From 8949460bd7f18b44f60bcb435b5487b50e9d8811 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Mon, 24 Jun 2024 12:55:30 -0600 Subject: [PATCH] fix cli welcome screen (#13474) Release Notes: - Fixed first launch via cli --------- Co-authored-by: Mikayla --- Cargo.lock | 1 + crates/cli/Cargo.toml | 1 + crates/cli/src/main.rs | 47 ++++++++++++++++++----------- crates/zed/src/zed/open_listener.rs | 3 +- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 58843a2bfa..04871af114 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2223,6 +2223,7 @@ dependencies = [ "fork", "ipc-channel", "once_cell", + "parking_lot", "paths", "plist", "release_channel", diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index ae58f7c641..aa64e8de8f 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -21,6 +21,7 @@ anyhow.workspace = true clap.workspace = true ipc-channel = "0.18" once_cell.workspace = true +parking_lot.workspace = true paths.workspace = true release_channel.workspace = true serde.workspace = true diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 8c8da80a5c..482f590dfc 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -3,10 +3,12 @@ use anyhow::{Context, Result}; use clap::Parser; use cli::{ipc::IpcOneShotServer, CliRequest, CliResponse, IpcHandshake}; +use parking_lot::Mutex; use std::{ env, fs, io, path::{Path, PathBuf}, process::ExitStatus, + sync::Arc, thread::{self, JoinHandle}, }; use util::paths::PathLikeWithPosition; @@ -123,26 +125,34 @@ fn main() -> Result<()> { None }; - let sender: JoinHandle> = thread::spawn(move || { - let (_, handshake) = server.accept().context("Handshake after Zed spawn")?; - let (tx, rx) = (handshake.requests, handshake.responses); - tx.send(CliRequest::Open { - paths, - wait: args.wait, - open_new_workspace, - dev_server_token: args.dev_server_token, - })?; + let exit_status = Arc::new(Mutex::new(None)); - while let Ok(response) = rx.recv() { - match response { - CliResponse::Ping => {} - CliResponse::Stdout { message } => println!("{message}"), - CliResponse::Stderr { message } => eprintln!("{message}"), - CliResponse::Exit { status } => std::process::exit(status), + let sender: JoinHandle> = thread::spawn({ + let exit_status = exit_status.clone(); + move || { + let (_, handshake) = server.accept().context("Handshake after Zed spawn")?; + let (tx, rx) = (handshake.requests, handshake.responses); + tx.send(CliRequest::Open { + paths, + wait: args.wait, + open_new_workspace, + dev_server_token: args.dev_server_token, + })?; + + while let Ok(response) = rx.recv() { + match response { + CliResponse::Ping => {} + CliResponse::Stdout { message } => println!("{message}"), + CliResponse::Stderr { message } => eprintln!("{message}"), + CliResponse::Exit { status } => { + exit_status.lock().replace(status); + return Ok(()); + } + } } - } - Ok(()) + Ok(()) + } }); if args.foreground { @@ -152,6 +162,9 @@ fn main() -> Result<()> { sender.join().unwrap()?; } + if let Some(exit_status) = exit_status.lock().take() { + std::process::exit(exit_status); + } Ok(()) } diff --git a/crates/zed/src/zed/open_listener.rs b/crates/zed/src/zed/open_listener.rs index d9b46675d1..6a1ac96095 100644 --- a/crates/zed/src/zed/open_listener.rs +++ b/crates/zed/src/zed/open_listener.rs @@ -398,7 +398,8 @@ pub async fn handle_cli_connection( } } } else if matches!(KEY_VALUE_STORE.read_kvp(FIRST_OPEN), Ok(None)) { - cx.update(|cx| show_welcome_view(app_state, cx)).log_err(); + cx.update(|cx| show_welcome_view(app_state, cx).detach()) + .log_err(); } else { cx.update(|cx| { workspace::open_new(app_state, cx, |workspace, cx| {