Switch to open based restarting
This commit is contained in:
parent
4ea7a24b93
commit
6e33f33da1
8 changed files with 44 additions and 46 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1097,7 +1097,6 @@ dependencies = [
|
||||||
"ipc-channel",
|
"ipc-channel",
|
||||||
"plist",
|
"plist",
|
||||||
"serde",
|
"serde",
|
||||||
"sysinfo",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -18,7 +18,6 @@ clap = { version = "3.1", features = ["derive"] }
|
||||||
dirs = "3.0"
|
dirs = "3.0"
|
||||||
ipc-channel = "0.16"
|
ipc-channel = "0.16"
|
||||||
serde = { version = "1.0", features = ["derive", "rc"] }
|
serde = { version = "1.0", features = ["derive", "rc"] }
|
||||||
sysinfo = "0.27"
|
|
||||||
|
|
||||||
[target.'cfg(target_os = "macos")'.dependencies]
|
[target.'cfg(target_os = "macos")'.dependencies]
|
||||||
core-foundation = "0.9"
|
core-foundation = "0.9"
|
||||||
|
|
|
@ -14,10 +14,8 @@ use std::{
|
||||||
fs::{self, OpenOptions},
|
fs::{self, OpenOptions},
|
||||||
io,
|
io,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
ptr, thread,
|
ptr,
|
||||||
time::Duration,
|
|
||||||
};
|
};
|
||||||
use sysinfo::{Pid, System, SystemExt};
|
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[clap(name = "zed", global_setting(clap::AppSettings::NoAutoVersion))]
|
#[clap(name = "zed", global_setting(clap::AppSettings::NoAutoVersion))]
|
||||||
|
@ -34,8 +32,6 @@ struct Args {
|
||||||
/// Custom Zed.app path
|
/// Custom Zed.app path
|
||||||
#[clap(short, long)]
|
#[clap(short, long)]
|
||||||
bundle_path: Option<PathBuf>,
|
bundle_path: Option<PathBuf>,
|
||||||
#[clap(short, long)]
|
|
||||||
restart_from: Option<Pid>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
@ -64,13 +60,6 @@ fn main() -> Result<()> {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(parent_pid) = args.restart_from {
|
|
||||||
let mut system = System::new();
|
|
||||||
while system.refresh_process(parent_pid) {
|
|
||||||
thread::sleep(Duration::from_millis(100));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for path in args.paths.iter() {
|
for path in args.paths.iter() {
|
||||||
if !path.exists() {
|
if !path.exists() {
|
||||||
touch(path.as_path())?;
|
touch(path.as_path())?;
|
||||||
|
|
|
@ -81,6 +81,7 @@ pub trait Platform: Send + Sync {
|
||||||
fn app_version(&self) -> Result<AppVersion>;
|
fn app_version(&self) -> Result<AppVersion>;
|
||||||
fn os_name(&self) -> &'static str;
|
fn os_name(&self) -> &'static str;
|
||||||
fn os_version(&self) -> Result<AppVersion>;
|
fn os_version(&self) -> Result<AppVersion>;
|
||||||
|
fn restart(&self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) trait ForegroundPlatform {
|
pub(crate) trait ForegroundPlatform {
|
||||||
|
|
|
@ -45,6 +45,7 @@ use std::{
|
||||||
ffi::{c_void, CStr, OsStr},
|
ffi::{c_void, CStr, OsStr},
|
||||||
os::{raw::c_char, unix::ffi::OsStrExt},
|
os::{raw::c_char, unix::ffi::OsStrExt},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
process::Command,
|
||||||
ptr,
|
ptr,
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
slice, str,
|
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 {
|
unsafe fn path_from_objc(path: id) -> PathBuf {
|
||||||
|
|
|
@ -226,6 +226,8 @@ impl super::Platform for Platform {
|
||||||
patch: 0,
|
patch: 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn restart(&self) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -38,7 +38,9 @@ use terminal_view::{get_working_directory, TerminalView};
|
||||||
use fs::RealFs;
|
use fs::RealFs;
|
||||||
use settings::watched_json::{watch_keymap_file, watch_settings_file, WatchedJsonFile};
|
use settings::watched_json::{watch_keymap_file, watch_settings_file, WatchedJsonFile};
|
||||||
use theme::ThemeRegistry;
|
use theme::ThemeRegistry;
|
||||||
use util::{channel::RELEASE_CHANNEL, paths, ResultExt, StaffMode, TryFutureExt};
|
#[cfg(debug_assertions)]
|
||||||
|
use util::StaffMode;
|
||||||
|
use util::{channel::RELEASE_CHANNEL, paths, ResultExt, TryFutureExt};
|
||||||
use workspace::{
|
use workspace::{
|
||||||
self, item::ItemHandle, notifications::NotifyResultExt, AppState, NewFile, OpenPaths, Workspace,
|
self, item::ItemHandle, notifications::NotifyResultExt, AppState, NewFile, OpenPaths, Workspace,
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,8 +23,7 @@ use gpui::{
|
||||||
},
|
},
|
||||||
impl_actions,
|
impl_actions,
|
||||||
platform::{WindowBounds, WindowOptions},
|
platform::{WindowBounds, WindowOptions},
|
||||||
AssetSource, AsyncAppContext, Platform, PromptLevel, Task, TitlebarOptions, ViewContext,
|
AssetSource, AsyncAppContext, Platform, PromptLevel, TitlebarOptions, ViewContext, WindowKind,
|
||||||
WindowKind,
|
|
||||||
};
|
};
|
||||||
use language::Rope;
|
use language::Rope;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
@ -35,7 +34,7 @@ use search::{BufferSearchBar, ProjectSearchBar};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::to_string_pretty;
|
use serde_json::to_string_pretty;
|
||||||
use settings::{keymap_file_json_schema, settings_file_json_schema, Settings};
|
use settings::{keymap_file_json_schema, settings_file_json_schema, Settings};
|
||||||
use std::{borrow::Cow, env, path::Path, process::Command, str, sync::Arc};
|
use std::{borrow::Cow, env, path::Path, str, sync::Arc};
|
||||||
use util::{channel::ReleaseChannel, paths, ResultExt, StaffMode};
|
use util::{channel::ReleaseChannel, paths, ResultExt, StaffMode};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
pub use workspace;
|
pub use workspace;
|
||||||
|
@ -130,9 +129,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::MutableAppContext) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
cx.add_global_action(|_: &Quit, cx| {
|
cx.add_global_action(quit);
|
||||||
quit(cx).detach_and_log_err(cx);
|
|
||||||
});
|
|
||||||
cx.add_global_action(restart);
|
cx.add_global_action(restart);
|
||||||
cx.add_global_action(move |action: &OpenBrowser, cx| cx.platform().open_url(&action.url));
|
cx.add_global_action(move |action: &OpenBrowser, cx| cx.platform().open_url(&action.url));
|
||||||
cx.add_global_action(move |_: &IncreaseBufferFontSize, cx| {
|
cx.add_global_action(move |_: &IncreaseBufferFontSize, cx| {
|
||||||
|
@ -408,30 +405,10 @@ pub fn build_window_options(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn restart(_: &Restart, cx: &mut gpui::MutableAppContext) {
|
fn restart(_: &Restart, cx: &mut gpui::MutableAppContext) {
|
||||||
let cli_process = cx
|
cx.platform().restart();
|
||||||
.platform()
|
|
||||||
.path_for_auxiliary_executable("cli")
|
|
||||||
.log_err()
|
|
||||||
.and_then(|path| {
|
|
||||||
Command::new(path)
|
|
||||||
.args(["--restart-from", &format!("{}", std::process::id())])
|
|
||||||
.spawn()
|
|
||||||
.log_err()
|
|
||||||
});
|
|
||||||
|
|
||||||
cx.spawn(|mut cx| async move {
|
|
||||||
let did_quit = cx.update(quit).await?;
|
|
||||||
if !did_quit {
|
|
||||||
if let Some(mut cli_process) = cli_process {
|
|
||||||
cli_process.kill().log_err();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok::<(), anyhow::Error>(())
|
|
||||||
})
|
|
||||||
.detach_and_log_err(cx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn quit(cx: &mut gpui::MutableAppContext) -> Task<Result<bool>> {
|
fn quit(_: &Quit, cx: &mut gpui::MutableAppContext) {
|
||||||
let mut workspaces = cx
|
let mut workspaces = cx
|
||||||
.window_ids()
|
.window_ids()
|
||||||
.filter_map(|window_id| cx.root_view::<Workspace>(window_id))
|
.filter_map(|window_id| cx.root_view::<Workspace>(window_id))
|
||||||
|
@ -454,7 +431,7 @@ fn quit(cx: &mut gpui::MutableAppContext) -> Task<Result<bool>> {
|
||||||
.next()
|
.next()
|
||||||
.await;
|
.await;
|
||||||
if answer != Some(0) {
|
if answer != Some(0) {
|
||||||
return Ok(false);
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -466,12 +443,13 @@ fn quit(cx: &mut gpui::MutableAppContext) -> Task<Result<bool>> {
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
return Ok(false);
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cx.platform().quit();
|
cx.platform().quit();
|
||||||
anyhow::Ok(true)
|
anyhow::Ok(())
|
||||||
})
|
})
|
||||||
|
.detach_and_log_err(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn about(_: &mut Workspace, _: &About, cx: &mut gpui::ViewContext<Workspace>) {
|
fn about(_: &mut Workspace, _: &About, cx: &mut gpui::ViewContext<Workspace>) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue