From f489db4f08a49404f46af572e1537c73df19be6b Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Mon, 31 Aug 2026 17:28:44 +0800 Subject: [PATCH] fix(windows): reveal items in explorer for paths with spaces Command::arg wraps the `/select,` argument in MSVC quotes as a whole once the path contains a space; Explorer cannot parse that form and silently falls back to the default shell folder (Documents). Delegate to tauri-plugin-opener, which selects the item through SHOpenFolderAndSelectItems instead of the Explorer command line. --- src-tauri/src/commands/fs_open.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src-tauri/src/commands/fs_open.rs b/src-tauri/src/commands/fs_open.rs index 7f7bf5dcd4..3fcba55f45 100644 --- a/src-tauri/src/commands/fs_open.rs +++ b/src-tauri/src/commands/fs_open.rs @@ -6,7 +6,8 @@ use dbx_core::path_utils::expand_tilde; /// Reveal a file in the platform's file manager. /// /// - macOS: `open -R ` highlights the file in Finder. -/// - Windows: `explorer.exe /select,` opens Explorer with the file selected. +/// - Windows: selects the file in Explorer via the opener plugin (COM +/// `SHOpenFolderAndSelectItems`, the same approach Electron uses). /// - Linux: opens the parent directory with `xdg-open`. (DBus /// `org.freedesktop.FileManager1.ShowItems` would be a higher-fidelity /// alternative; deferred to a follow-up to avoid a new dependency.) @@ -26,15 +27,13 @@ pub fn reveal_in_file_manager(path: &Path) -> Result<(), String> { #[cfg(target_os = "windows")] { - // `/select,` must be passed as a single argument with no space - // after the comma. `Command::arg` does not invoke a shell, so the path - // is forwarded as-is — spaces and non-ASCII characters survive. - let arg = format!("/select,{}", path.display()); - dbx_core::process::new_std_command("explorer") - .arg(arg) - .spawn() - .map(|_| ()) - .map_err(|e| format!("failed to launch Explorer: {e}")) + // Explorer does not parse its command line with the usual MSVC rules: + // passing `explorer /select,` through `Command::arg` wraps the + // whole argument in quotes as soon as the path contains a space, and + // Explorer then silently falls back to opening the default shell + // folder (Documents). The opener plugin selects the item via COM + // instead, which has no command-line parsing involved. + tauri_plugin_opener::reveal_item_in_dir(path).map_err(|e| format!("failed to reveal in Explorer: {e}")) } #[cfg(all(not(target_os = "macos"), not(target_os = "windows")))]