diff --git a/.changes/fix-restart-macos.md b/.changes/fix-restart-macos.md new file mode 100644 index 000000000000..b7db3b536469 --- /dev/null +++ b/.changes/fix-restart-macos.md @@ -0,0 +1,6 @@ +--- +"tauri": patch:bug +--- + +Fixes the restart() function not being compatible with the v2 binary name change. +Additionally, do not panic if we somehow failed to restart, and only exit instead. diff --git a/core/tauri/src/api/process.rs b/core/tauri/src/api/process.rs index 1cb4c0e08853..03b8547883fa 100644 --- a/core/tauri/src/api/process.rs +++ b/core/tauri/src/api/process.rs @@ -82,10 +82,49 @@ pub fn restart(env: &Env) { use std::process::{exit, Command}; if let Ok(path) = current_binary(env) { - Command::new(path) - .args(&env.args) - .spawn() - .expect("application failed to start"); + // on macOS on updates the binary name might have changed + // so we'll read the Contents/MacOS folder instead to infer the actual binary path + #[cfg(target_os = "macos")] + if let Some(parent) = path.parent() { + if parent.components().last() + == Some(std::path::Component::Normal(std::ffi::OsStr::new("MacOS"))) + { + let macos_binaries = std::fs::read_dir(parent) + .map(|dir| { + dir + .into_iter() + .flatten() + .map(|entry| entry.path()) + .collect::>() + }) + .unwrap_or_default(); + match macos_binaries.len() { + 0 => { + // should never happen, but let's not panic here since it's a crucial feature for updates + exit(1); + } + 1 => { + // we have one binary (no sidecar) so we should use it to restart + if let Err(e) = Command::new(macos_binaries.first().unwrap()) + .args(&env.args) + .spawn() + { + eprintln!("failed to restart app: {e}"); + } + + exit(0); + } + _ => { + // in case of sidecars we don't have enough information here to decide what's the right binary name + // so let's hope the binary name didn't change by running the Command::spawn below + } + } + } + } + + if let Err(e) = Command::new(path).args(&env.args).spawn() { + eprintln!("failed to restart app: {e}"); + } } exit(0); diff --git a/examples/api/src-tauri/Cargo.lock b/examples/api/src-tauri/Cargo.lock index 65e4049085b6..af3f065ec5f1 100644 --- a/examples/api/src-tauri/Cargo.lock +++ b/examples/api/src-tauri/Cargo.lock @@ -4027,7 +4027,7 @@ checksum = "69758bda2e78f098e4ccb393021a0963bb3442eac05f135c30f61b7370bbafae" [[package]] name = "tauri" -version = "1.7.1" +version = "1.7.2" dependencies = [ "anyhow", "base64 0.22.1", @@ -4093,7 +4093,7 @@ dependencies = [ [[package]] name = "tauri-build" -version = "1.5.3" +version = "1.5.4" dependencies = [ "anyhow", "cargo_toml", @@ -4112,7 +4112,7 @@ dependencies = [ [[package]] name = "tauri-codegen" -version = "1.4.4" +version = "1.4.5" dependencies = [ "base64 0.21.7", "brotli", @@ -4136,7 +4136,7 @@ dependencies = [ [[package]] name = "tauri-macros" -version = "1.4.5" +version = "1.4.6" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -4148,7 +4148,7 @@ dependencies = [ [[package]] name = "tauri-runtime" -version = "0.14.4" +version = "0.14.5" dependencies = [ "gtk", "http", @@ -4167,7 +4167,7 @@ dependencies = [ [[package]] name = "tauri-runtime-wry" -version = "0.14.9" +version = "0.14.10" dependencies = [ "arboard", "cocoa 0.24.1", @@ -4186,7 +4186,7 @@ dependencies = [ [[package]] name = "tauri-utils" -version = "1.6.0" +version = "1.6.1" dependencies = [ "aes-gcm", "brotli",