diff --git a/Cargo.lock b/Cargo.lock index 53b4674771a..e2add4db807 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15043,7 +15043,6 @@ dependencies = [ "util", "uuid", "watch", - "windows 0.62.2", "workspace", "worktree", "zlog", diff --git a/crates/remote_server/Cargo.toml b/crates/remote_server/Cargo.toml index 30ca632b3f0..c18909bf23e 100644 --- a/crates/remote_server/Cargo.toml +++ b/crates/remote_server/Cargo.toml @@ -79,7 +79,6 @@ uuid = { workspace = true, features = ["v4"] } libc.workspace = true [target.'cfg(windows)'.dependencies] -windows.workspace = true gpui = { workspace = true, features = ["windows-manifest"] } [dev-dependencies] diff --git a/crates/remote_server/src/server.rs b/crates/remote_server/src/server.rs index bcd3a2a1ead..48004fddd54 100644 --- a/crates/remote_server/src/server.rs +++ b/crates/remote_server/src/server.rs @@ -3,9 +3,6 @@ mod headless_project; #[cfg(test)] mod remote_editing_tests; -#[cfg(windows)] -pub mod windows; - pub use headless_project::{HeadlessAppState, HeadlessProject}; use anyhow::{Context as _, Result, anyhow}; @@ -1191,24 +1188,28 @@ async fn spawn_server(paths: &ServerPaths) -> Result<(), SpawnServerError> { #[cfg(windows)] fn spawn_server_windows(binary_name: &Path, paths: &ServerPaths) -> Result<(), SpawnServerError> { - let binary_path = binary_name.to_string_lossy().to_string(); - let parameters = format!( - "run --log-file \"{}\" --pid-file \"{}\" --stdin-socket \"{}\" --stdout-socket \"{}\" --stderr-socket \"{}\"", - paths.log_file.to_string_lossy(), - paths.pid_file.to_string_lossy(), - paths.stdin_socket.to_string_lossy(), - paths.stdout_socket.to_string_lossy(), - paths.stderr_socket.to_string_lossy() - ); - - let directory = binary_name - .parent() - .map(|p| p.to_string_lossy().to_string()) - .unwrap_or_default(); - - crate::windows::shell_execute_from_explorer(&binary_path, ¶meters, &directory) - .map_err(|e| SpawnServerError::ProcessStatus(std::io::Error::other(e)))?; - + use smol::process::windows::CommandExt; + // Detach from the console and break away from sshd's job so closing the SSH session doesn't kill the daemon. + const DETACHED_PROCESS: u32 = 0x0000_0008; + const CREATE_BREAKAWAY_FROM_JOB: u32 = 0x0100_0000; + smol::process::Command::new(binary_name) + .stdin(util::command::Stdio::null()) + .stdout(util::command::Stdio::null()) + .stderr(util::command::Stdio::null()) + .arg("run") + .arg("--log-file") + .arg(&paths.log_file) + .arg("--pid-file") + .arg(&paths.pid_file) + .arg("--stdin-socket") + .arg(&paths.stdin_socket) + .arg("--stdout-socket") + .arg(&paths.stdout_socket) + .arg("--stderr-socket") + .arg(&paths.stderr_socket) + .creation_flags(DETACHED_PROCESS | CREATE_BREAKAWAY_FROM_JOB) + .spawn() + .map_err(SpawnServerError::ProcessStatus)?; Ok(()) } diff --git a/crates/remote_server/src/windows.rs b/crates/remote_server/src/windows.rs deleted file mode 100644 index c1ef6c0c63c..00000000000 --- a/crates/remote_server/src/windows.rs +++ /dev/null @@ -1,48 +0,0 @@ -use windows::Win32::System::Com::{ - CLSCTX_LOCAL_SERVER, COINIT_APARTMENTTHREADED, CoCreateInstance, CoInitializeEx, IDispatch, - IServiceProvider, -}; -use windows::Win32::System::Variant::VARIANT; -use windows::Win32::UI::Shell::{ - CSIDL_DESKTOP, IShellBrowser, IShellDispatch2, IShellFolderViewDual, IShellWindows, - SID_STopLevelBrowser, SVGIO_BACKGROUND, SWC_DESKTOP, SWFO_NEEDDISPATCH, ShellWindows, -}; -use windows::core::{BSTR, Interface}; - -pub fn shell_execute_from_explorer( - file: &str, - parameters: &str, - directory: &str, -) -> anyhow::Result<()> { - unsafe { - CoInitializeEx(None, COINIT_APARTMENTTHREADED).unwrap(); - - let mut _hwnd = Default::default(); - let shell_dispatch: IShellDispatch2 = - CoCreateInstance::<_, IShellWindows>(&ShellWindows, None, CLSCTX_LOCAL_SERVER)? - .FindWindowSW( - &VARIANT::from(CSIDL_DESKTOP as i32), - &VARIANT::default(), - SWC_DESKTOP, - &mut _hwnd, - SWFO_NEEDDISPATCH, - )? - .cast::()? - .QueryService::(&SID_STopLevelBrowser)? - .QueryActiveShellView()? - .GetItemObject::(SVGIO_BACKGROUND)? - .cast::()? - .Application()? - .cast()?; - - shell_dispatch.ShellExecute( - &BSTR::from(file), - &VARIANT::from(parameters), - &VARIANT::from(directory), - &VARIANT::from(""), - &VARIANT::from(0i32), - )?; - - Ok(()) - } -}