Switch to open based restarting

This commit is contained in:
Mikayla Maki 2023-02-16 16:35:34 -08:00
parent 4ea7a24b93
commit 6e33f33da1
8 changed files with 44 additions and 46 deletions

View file

@ -45,6 +45,7 @@ use std::{
ffi::{c_void, CStr, OsStr},
os::{raw::c_char, unix::ffi::OsStrExt},
path::{Path, PathBuf},
process::Command,
ptr,
rc::Rc,
slice, str,
@ -803,6 +804,33 @@ impl platform::Platform for MacPlatform {
})
}
}
fn restart(&self) {
#[cfg(debug_assertions)]
let path = std::env::current_exe();
#[cfg(not(debug_assertions))]
let path = unsafe {
let bundle: id = NSBundle::mainBundle();
if bundle.is_null() {
std::env::current_exe()
} else {
let path: id = msg_send![bundle, bundlePath];
let path: *mut c_char = msg_send![path, UTF8String];
Ok(PathBuf::from(OsStr::from_bytes(
CStr::from_ptr(path).to_bytes(),
)))
}
};
let command = path.and_then(|path| Command::new("/usr/bin/open").arg(path).spawn());
match command {
Err(err) => log::error!("Unable to restart application {}", err),
Ok(_) => self.quit(),
}
}
}
unsafe fn path_from_objc(path: id) -> PathBuf {