From 67ec1a758141e19104f709165e0b925610e83281 Mon Sep 17 00:00:00 2001 From: Markgatcha <93056348+Markgatcha@users.noreply.github.com> Date: Sun, 25 Oct 2026 12:34:33 -0400 Subject: [PATCH] fix(desktop-gpui): open paths with ShellExecuteW instead of cmd `library::open_path` opened a recording by spawning `cmd /C start "" `. Two problems with that: - `cmd.exe` is a console program, so a GUI-subsystem parent gets a console window. That is the terminal flash on every "Open File" (#2309). - The path is a command-line token, not a single argument. Rust only quotes arguments that contain spaces or quotes, so a folder like `R&D` becomes `start "" C:\...\R` plus a second command `D\clip.mp4`. `ShellExecuteW` with the `open` verb needs no shell and takes the path as one file argument. The helper mirrors `installer.rs`: `windows_sys`, `w!("open")`, `SW_SHOWNORMAL`, and the documented `> 32` return check. Verified in a standalone Windows 11 harness against `windows-sys` 0.59 with the same three features the app enables: an existing directory and a file named `a & b.txt` both return success, and a missing path returns `SE_ERR_FNF` (2), so the error branch works. --- apps/desktop-gpui/src/library.rs | 44 +++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/apps/desktop-gpui/src/library.rs b/apps/desktop-gpui/src/library.rs index 19428742600..893b56bc75b 100644 --- a/apps/desktop-gpui/src/library.rs +++ b/apps/desktop-gpui/src/library.rs @@ -612,9 +612,7 @@ pub fn open_path(path: &Path) { } #[cfg(target_os = "windows")] { - std::process::Command::new("cmd") - .args(["/C", "start", "", &path.to_string_lossy()]) - .spawn() + shell_open(path) } #[cfg(all(not(target_os = "macos"), not(target_os = "windows")))] { @@ -626,6 +624,46 @@ pub fn open_path(path: &Path) { } } +/// `ShellExecuteW` rather than `cmd /C start`: `cmd` is a console program, so a +/// GUI-subsystem parent gets a console window, and the path would be parsed as +/// part of a command line instead of a single file argument. +#[cfg(target_os = "windows")] +fn shell_open(path: &Path) -> Result<(), String> { + use std::os::windows::ffi::OsStrExt as _; + use windows_sys::{ + Win32::UI::{Shell::ShellExecuteW, WindowsAndMessaging::SW_SHOWNORMAL}, + w, + }; + + let wide = |value: &std::ffi::OsStr| { + value + .encode_wide() + .chain(std::iter::once(0)) + .collect::>() + }; + let file = wide(path.as_os_str()); + // SAFETY: `file` is NUL-terminated and outlives the call; the remaining + // arguments are the documented nulls for the default verb. + let result = unsafe { + ShellExecuteW( + std::ptr::null_mut(), + w!("open"), + file.as_ptr(), + std::ptr::null(), + std::ptr::null(), + SW_SHOWNORMAL, + ) + }; + if result as isize > 32 { + Ok(()) + } else { + Err(format!( + "Windows could not open the path (code {})", + result as isize + )) + } +} + pub fn reveal_in_folder(path: &Path) { let result = { #[cfg(target_os = "macos")]