Fixes a race condition in the restart implementation
Fixes open_urls racing workspace initialization and causing a double-open (community#927) Adds a -d flag to the bundle script to compile in debug mode Co-Authored-by: Max <max@zed.dev>
This commit is contained in:
@@ -807,17 +807,24 @@ impl platform::Platform for MacPlatform {
|
||||
|
||||
fn restart(&self) {
|
||||
#[cfg(debug_assertions)]
|
||||
let path = std::env::current_exe();
|
||||
let path = std::env::current_exe().unwrap();
|
||||
|
||||
#[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 {
|
||||
Err(err) => log::error!("Unable to restart application {}", err),
|
||||
Ok(_child) => self.quit(),
|
||||
}
|
||||
Command::new("/bin/bash")
|
||||
.arg("-c")
|
||||
.arg(script)
|
||||
.arg(std::process::id().to_string())
|
||||
.arg(path)
|
||||
.spawn()
|
||||
.ok();
|
||||
|
||||
self.quit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-18
@@ -78,7 +78,7 @@ fn main() {
|
||||
};
|
||||
|
||||
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, _| {
|
||||
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() {
|
||||
@@ -189,9 +189,6 @@ fn main() {
|
||||
|
||||
cx.set_menus(menus::menus());
|
||||
|
||||
cx.spawn(|cx| handle_open_paths(open_paths_rx, app_state.clone(), cx))
|
||||
.detach();
|
||||
|
||||
if stdout_is_a_pty() {
|
||||
cx.platform().activate(true);
|
||||
let paths = collect_path_args();
|
||||
@@ -205,13 +202,32 @@ fn main() {
|
||||
if let Ok(Some(connection)) = cli_connections_rx.try_next() {
|
||||
cx.spawn(|cx| handle_cli_connection(connection, app_state.clone(), cx))
|
||||
.detach();
|
||||
} else if let Ok(Some(paths)) = open_paths_rx.try_next() {
|
||||
cx.update(|cx| workspace::open_paths(&paths, &app_state, cx))
|
||||
.detach();
|
||||
} else {
|
||||
cx.spawn(|cx| async move { restore_or_create_workspace(cx).await })
|
||||
.detach()
|
||||
}
|
||||
cx.spawn(|cx| async move {
|
||||
while let Some(connection) = cli_connections_rx.next().await {
|
||||
handle_cli_connection(connection, app_state.clone(), cx.clone()).await;
|
||||
|
||||
cx.spawn(|cx| {
|
||||
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();
|
||||
@@ -521,17 +537,6 @@ fn load_config_files(
|
||||
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(
|
||||
server_name: &str,
|
||||
) -> Result<(mpsc::Receiver<CliRequest>, IpcSender<CliResponse>)> {
|
||||
|
||||
Reference in New Issue
Block a user