Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions apps/desktop-gpui/src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")))]
{
Expand All @@ -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::<Vec<u16>>()
};
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")]
Expand Down
Loading