Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): restart cannot handle binary name change on macOS #10991

Merged
merged 4 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/fix-restart-macos.md
Original file line number Diff line number Diff line change
@@ -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.
47 changes: 43 additions & 4 deletions core/tauri/src/api/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we read Contents/Info.plist to determine new binary name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohhhhhh we can.. let's do that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amr the no-Apple dev that knows more about Apple than any other dev

#[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::<Vec<_>>()
})
.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);
Expand Down
14 changes: 7 additions & 7 deletions examples/api/src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading