Merge pull request #2196 from zed-industries/open_urls

Fix open URLs, restarts, and make bundling easier to use
This commit is contained in:
Mikayla Maki 2023-02-21 15:36:50 -08:00 committed by GitHub
commit 14488619a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 41 deletions

View File

@ -829,17 +829,24 @@ impl platform::Platform for MacPlatform {
fn restart(&self) { fn restart(&self) {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
let path = std::env::current_exe(); let path = std::env::current_exe().unwrap();
#[cfg(not(debug_assertions))] #[cfg(not(debug_assertions))]
let path = self.app_path().or_else(|_| std::env::current_exe()); let path = self
.app_path()
.unwrap_or_else(|_| std::env::current_exe().unwrap());
let command = path.and_then(|path| Command::new("/usr/bin/open").arg(path).spawn()); let script = r#"lsof -p "$0" +r 1 &>/dev/null && open "$1""#;
match command { Command::new("/bin/bash")
Err(err) => log::error!("Unable to restart application {}", err), .arg("-c")
Ok(_child) => self.quit(), .arg(script)
} .arg(std::process::id().to_string())
.arg(path)
.spawn()
.ok();
self.quit();
} }
} }

View File

@ -78,7 +78,7 @@ fn main() {
}; };
let (cli_connections_tx, mut cli_connections_rx) = mpsc::unbounded(); let (cli_connections_tx, mut cli_connections_rx) = mpsc::unbounded();
let (open_paths_tx, open_paths_rx) = mpsc::unbounded(); let (open_paths_tx, mut open_paths_rx) = mpsc::unbounded();
app.on_open_urls(move |urls, _| { app.on_open_urls(move |urls, _| {
if let Some(server_name) = urls.first().and_then(|url| url.strip_prefix("zed-cli://")) { if let Some(server_name) = urls.first().and_then(|url| url.strip_prefix("zed-cli://")) {
if let Some(cli_connection) = connect_to_cli(server_name).log_err() { if let Some(cli_connection) = connect_to_cli(server_name).log_err() {
@ -189,9 +189,6 @@ fn main() {
cx.set_menus(menus::menus()); cx.set_menus(menus::menus());
cx.spawn(|cx| handle_open_paths(open_paths_rx, app_state.clone(), cx))
.detach();
if stdout_is_a_pty() { if stdout_is_a_pty() {
cx.platform().activate(true); cx.platform().activate(true);
let paths = collect_path_args(); let paths = collect_path_args();
@ -205,13 +202,32 @@ fn main() {
if let Ok(Some(connection)) = cli_connections_rx.try_next() { if let Ok(Some(connection)) = cli_connections_rx.try_next() {
cx.spawn(|cx| handle_cli_connection(connection, app_state.clone(), cx)) cx.spawn(|cx| handle_cli_connection(connection, app_state.clone(), cx))
.detach(); .detach();
} else if let Ok(Some(paths)) = open_paths_rx.try_next() {
cx.update(|cx| workspace::open_paths(&paths, &app_state, cx))
.detach();
} else { } else {
cx.spawn(|cx| async move { restore_or_create_workspace(cx).await }) cx.spawn(|cx| async move { restore_or_create_workspace(cx).await })
.detach() .detach()
} }
cx.spawn(|cx| async move {
while let Some(connection) = cli_connections_rx.next().await { cx.spawn(|cx| {
handle_cli_connection(connection, app_state.clone(), cx.clone()).await; let app_state = app_state.clone();
async move {
while let Some(connection) = cli_connections_rx.next().await {
handle_cli_connection(connection, app_state.clone(), cx.clone()).await;
}
}
})
.detach();
cx.spawn(|mut cx| {
let app_state = app_state.clone();
async move {
while let Some(paths) = open_paths_rx.next().await {
log::error!("OPEN PATHS FROM HANDLE");
cx.update(|cx| workspace::open_paths(&paths, &app_state, cx))
.detach();
}
} }
}) })
.detach(); .detach();
@ -521,17 +537,6 @@ fn load_config_files(
rx rx
} }
async fn handle_open_paths(
mut rx: mpsc::UnboundedReceiver<Vec<PathBuf>>,
app_state: Arc<AppState>,
mut cx: AsyncAppContext,
) {
while let Some(paths) = rx.next().await {
cx.update(|cx| workspace::open_paths(&paths, &app_state, cx))
.detach();
}
}
fn connect_to_cli( fn connect_to_cli(
server_name: &str, server_name: &str,
) -> Result<(mpsc::Receiver<CliRequest>, IpcSender<CliResponse>)> { ) -> Result<(mpsc::Receiver<CliRequest>, IpcSender<CliResponse>)> {

View File

@ -2,6 +2,24 @@
set -e set -e
build_flag="--release"
target_dir="release"
open_result=false
# If -o option is specified, the folder of the resulting dmg will be opened in finder
# If -d is specified, Zed will be compiled in debug mode and the application's path printed
# If -od or -do is specified Zed will be bundled in debug and the application will be run.
while getopts 'od' flag
do
case "${flag}" in
o) open_result=true;;
d)
build_flag="";
target_dir="debug"
;;
esac
done
export ZED_BUNDLE=true export ZED_BUNDLE=true
export MACOSX_DEPLOYMENT_TARGET=10.15.7 export MACOSX_DEPLOYMENT_TARGET=10.15.7
@ -12,13 +30,13 @@ rustup target add wasm32-wasi
export CXXFLAGS="-stdlib=libc++" export CXXFLAGS="-stdlib=libc++"
echo "Compiling zed binary for aarch64-apple-darwin" echo "Compiling zed binary for aarch64-apple-darwin"
cargo build --release --package zed --target aarch64-apple-darwin cargo build ${build_flag} --package zed --target aarch64-apple-darwin
echo "Compiling zed binary for x86_64-apple-darwin" echo "Compiling zed binary for x86_64-apple-darwin"
cargo build --release --package zed --target x86_64-apple-darwin cargo build ${build_flag} --package zed --target x86_64-apple-darwin
echo "Compiling cli binary for aarch64-apple-darwin" echo "Compiling cli binary for aarch64-apple-darwin"
cargo build --release --package cli --target aarch64-apple-darwin cargo build ${build_flag} --package cli --target aarch64-apple-darwin
echo "Compiling cli binary for x86_64-apple-darwin" echo "Compiling cli binary for x86_64-apple-darwin"
cargo build --release --package cli --target x86_64-apple-darwin cargo build ${build_flag} --package cli --target x86_64-apple-darwin
echo "Creating application bundle" echo "Creating application bundle"
pushd crates/zed pushd crates/zed
@ -28,7 +46,10 @@ sed \
-i .backup \ -i .backup \
"s/package.metadata.bundle-${channel}/package.metadata.bundle/" \ "s/package.metadata.bundle-${channel}/package.metadata.bundle/" \
Cargo.toml Cargo.toml
app_path=$(cargo bundle --release --target x86_64-apple-darwin | xargs) app_path=$(cargo bundle ${build_flag} --target x86_64-apple-darwin | xargs)
echo app_path
mv Cargo.toml.backup Cargo.toml mv Cargo.toml.backup Cargo.toml
popd popd
echo "Bundled ${app_path}" echo "Bundled ${app_path}"
@ -36,18 +57,18 @@ echo "Bundled ${app_path}"
echo "Creating fat binaries" echo "Creating fat binaries"
lipo \ lipo \
-create \ -create \
target/{x86_64-apple-darwin,aarch64-apple-darwin}/release/Zed \ target/{x86_64-apple-darwin,aarch64-apple-darwin}/${target_dir}/Zed \
-output \ -output \
"${app_path}/Contents/MacOS/zed" "${app_path}/Contents/MacOS/zed"
lipo \ lipo \
-create \ -create \
target/{x86_64-apple-darwin,aarch64-apple-darwin}/release/cli \ target/{x86_64-apple-darwin,aarch64-apple-darwin}/${target_dir}/cli \
-output \ -output \
"${app_path}/Contents/MacOS/cli" "${app_path}/Contents/MacOS/cli"
echo "Copying WebRTC.framework into the frameworks folder" echo "Copying WebRTC.framework into the frameworks folder"
mkdir "${app_path}/Contents/Frameworks" mkdir "${app_path}/Contents/Frameworks"
cp -R target/x86_64-apple-darwin/release/WebRTC.framework "${app_path}/Contents/Frameworks/" cp -R target/x86_64-apple-darwin/${target_dir}/WebRTC.framework "${app_path}/Contents/Frameworks/"
mv "${app_path}/Contents/Info.plist" "${app_path}/Contents/WithoutDocumentTypes.plist" mv "${app_path}/Contents/Info.plist" "${app_path}/Contents/WithoutDocumentTypes.plist"
awk \ awk \
@ -73,7 +94,17 @@ else
codesign --force --deep --sign - "${app_path}" -v codesign --force --deep --sign - "${app_path}" -v
fi fi
dmg_target_directory="target/release" if [ "$target_dir" = "debug" ]; then
if [ "$open_result" = true ]; then
open "$app_path"
else
echo "Created application bundle:"
echo "$app_path"
fi
exit 0
fi
dmg_target_directory="target/${target_dir}"
dmg_source_directory="${dmg_target_directory}/dmg" dmg_source_directory="${dmg_target_directory}/dmg"
dmg_file_path="${dmg_target_directory}/Zed.dmg" dmg_file_path="${dmg_target_directory}/Zed.dmg"
@ -94,10 +125,6 @@ if [[ -n $MACOS_CERTIFICATE && -n $MACOS_CERTIFICATE_PASSWORD && -n $APPLE_NOTAR
npx notarize-cli --file ${dmg_file_path} --bundle-id dev.zed.Zed --username "$APPLE_NOTARIZATION_USERNAME" --password "$APPLE_NOTARIZATION_PASSWORD" npx notarize-cli --file ${dmg_file_path} --bundle-id dev.zed.Zed --username "$APPLE_NOTARIZATION_USERNAME" --password "$APPLE_NOTARIZATION_PASSWORD"
fi fi
# If -o option is specified, open the $dmg_target_directory directory in Finder to reveal the DMG if [ "$open_result" = true ]; then
while getopts o flag open $dmg_target_directory
do fi
case "${flag}" in
o) open $dmg_target_directory;;
esac
done