diff --git a/apps/desktop-gpui/Cargo.lock b/apps/desktop-gpui/Cargo.lock index 4556ee85d4e..d0e08e3bb40 100644 --- a/apps/desktop-gpui/Cargo.lock +++ b/apps/desktop-gpui/Cargo.lock @@ -1568,6 +1568,7 @@ dependencies = [ "cosmic-text 0.14.2", "cpal 0.15.3 (git+https://github.com/CapSoftware/cpal?rev=6013cb5f8bd3)", "dirs 6.0.0", + "dunce", "ffmpeg-next", "flume 0.11.1", "futures-util", diff --git a/apps/desktop-gpui/Cargo.toml b/apps/desktop-gpui/Cargo.toml index f14782fd81f..6e5df3900f3 100644 --- a/apps/desktop-gpui/Cargo.toml +++ b/apps/desktop-gpui/Cargo.toml @@ -159,6 +159,7 @@ reqwest = { version = "0.12", default-features = false, features = [ ] } futures-util = "0.3" dirs = "6" +dunce = "1.0.5" # Caption transcription (`src/transcription.rs`): the exact engine pin the # Tauri app carries (`apps/desktop/src-tauri/Cargo.toml:75`), so a model file # downloaded by either app loads identically in both. diff --git a/apps/desktop-gpui/src/deeplink.rs b/apps/desktop-gpui/src/deeplink.rs index 206f60ba7a0..8a1523477da 100644 --- a/apps/desktop-gpui/src/deeplink.rs +++ b/apps/desktop-gpui/src/deeplink.rs @@ -558,7 +558,7 @@ impl DeepLinkAction { RecordingMetaInner::Instant(_) => { let mp4_path = project_path.join("content/output.mp4"); if mp4_path.exists() && mp4_path.is_file() { - library::open_path(&mp4_path); + library::open_with_system(&mp4_path, cx); app_windows::hide_main_window(cx); } } diff --git a/apps/desktop-gpui/src/editor_export.rs b/apps/desktop-gpui/src/editor_export.rs index 7ffa4fc171d..68871c4704a 100644 --- a/apps/desktop-gpui/src/editor_export.rs +++ b/apps/desktop-gpui/src/editor_export.rs @@ -2629,9 +2629,9 @@ impl EditorWindow { ui::ButtonSize::Md, ) .label("Open File") - .on_click(move |_, _, _| { + .on_click(move |_, _, cx| { if let Some(path) = &path { - library::open_path(path); + library::open_with_system(path, cx); } }), ) diff --git a/apps/desktop-gpui/src/editor_window.rs b/apps/desktop-gpui/src/editor_window.rs index 80b69d557f8..507a9d1fa1c 100644 --- a/apps/desktop-gpui/src/editor_window.rs +++ b/apps/desktop-gpui/src/editor_window.rs @@ -7046,10 +7046,7 @@ impl EditorWindow { fn open_recording_bundle(&mut self, cx: &mut Context) { self.set_selection(None, cx); - crate::library::open_recording_folder( - &self.project_path, - crate::library::RecordingMode::Studio, - ); + crate::library::reveal_path(&self.project_path, cx); } fn delete_recording(&mut self, window: &mut Window, cx: &mut Context) { diff --git a/apps/desktop-gpui/src/library.rs b/apps/desktop-gpui/src/library.rs index f45cef1cb7d..42a71b3ec10 100644 --- a/apps/desktop-gpui/src/library.rs +++ b/apps/desktop-gpui/src/library.rs @@ -28,7 +28,7 @@ use cap_project::{ StudioRecordingStatus, }; use cap_recording::{recovery::RecoveryManager, upload_resume::UploadLock}; -use gpui::RenderImage; +use gpui::{App, RenderImage}; /// `RECENT_MEDIA_LIMIT` in `new-main/index.tsx:129`. pub const RECENT_MEDIA_LIMIT: usize = 9; @@ -595,61 +595,23 @@ pub fn delete_recording_directory(path: &Path) -> Result<(), String> { /// An instant recording opens its `content` directory -- /// `commands.openFilePath` is `open ` on macOS -- and anything else, or a /// bundle with no `content` directory, is revealed in the file manager. -pub fn open_recording_folder(path: &Path, mode: RecordingMode) { +pub fn open_recording_folder(path: &Path, mode: RecordingMode, cx: &App) { let content = path.join("content"); if mode == RecordingMode::Instant && content.is_dir() { - open_path(&content); + open_with_system(&content, cx); } else { - reveal_in_folder(path); + reveal_path(path, cx); } } -pub fn open_path(path: &Path) { - let result = { - #[cfg(target_os = "macos")] - { - std::process::Command::new("open").arg(path).spawn() - } - #[cfg(target_os = "windows")] - { - std::process::Command::new("cmd") - .args(["/C", "start", "", &path.to_string_lossy()]) - .spawn() - } - #[cfg(all(not(target_os = "macos"), not(target_os = "windows")))] - { - std::process::Command::new("xdg-open").arg(path).spawn() - } - }; - if let Err(error) = result { - tracing::warn!(path = %path.display(), "opening a path failed: {error}"); - } +// `std::fs::canonicalize` yields `\\?\` verbatim paths on Windows, which the +// shell APIs behind GPUI's reveal and open reject with E_INVALIDARG. +pub fn reveal_path(path: &Path, cx: &App) { + cx.reveal_path(dunce::simplified(path)); } -pub fn reveal_in_folder(path: &Path) { - let result = { - #[cfg(target_os = "macos")] - { - std::process::Command::new("open") - .arg("-R") - .arg(path) - .spawn() - } - #[cfg(target_os = "windows")] - { - std::process::Command::new("explorer") - .arg(format!("/select,{}", path.display())) - .spawn() - } - #[cfg(all(not(target_os = "macos"), not(target_os = "windows")))] - { - let parent = path.parent().unwrap_or(path); - std::process::Command::new("xdg-open").arg(parent).spawn() - } - }; - if let Err(error) = result { - tracing::warn!(path = %path.display(), "revealing a path failed: {error}"); - } +pub fn open_with_system(path: &Path, cx: &App) { + cx.open_with_system(dunce::simplified(path)); } pub fn copy_file_to_path(src: &Path, dest: &Path) -> Result<(), String> { diff --git a/apps/desktop-gpui/src/main_window.rs b/apps/desktop-gpui/src/main_window.rs index 36774a8806f..700ea047cd6 100644 --- a/apps/desktop-gpui/src/main_window.rs +++ b/apps/desktop-gpui/src/main_window.rs @@ -4650,7 +4650,7 @@ impl MainWindow { } else if !studio && let Some(url) = &sharing { cx.open_url(url); } else if !studio { - library::open_recording_folder(&path, mode); + library::open_recording_folder(&path, mode, cx); } }), actions, @@ -4727,7 +4727,7 @@ impl MainWindow { row = row.child(self.library_action( ("lib-rec-folder", index), "icons/folder.svg", - move |_, _, _| library::open_recording_folder(&folder, mode), + move |_, _, cx| library::open_recording_folder(&folder, mode, cx), )); row.child(self.library_action( ("lib-rec-delete", index), @@ -4806,7 +4806,7 @@ impl MainWindow { .child( self.library_action(("lib-ss-open", index), "icons/folder.svg", { let bundle = bundle.clone(); - move |_, _, _| library::reveal_in_folder(&bundle) + move |_, _, cx| library::reveal_path(&bundle, cx) }), ) .child(self.library_action( diff --git a/apps/desktop-gpui/src/screenshot_editor.rs b/apps/desktop-gpui/src/screenshot_editor.rs index 96489a861d4..20d6de08e8b 100644 --- a/apps/desktop-gpui/src/screenshot_editor.rs +++ b/apps/desktop-gpui/src/screenshot_editor.rs @@ -2465,7 +2465,7 @@ impl ScreenshotEditorWindow { MenuKind::More => { self.menu = None; match index { - 0 => crate::library::reveal_in_folder(&self.bundle.join("original.png")), + 0 => crate::library::reveal_path(&self.bundle.join("original.png"), cx), 1 => self.delete_screenshot(window, cx), _ => {} } diff --git a/apps/desktop-gpui/src/settings_pages.rs b/apps/desktop-gpui/src/settings_pages.rs index 530a8df630f..536f5a2c88e 100644 --- a/apps/desktop-gpui/src/settings_pages.rs +++ b/apps/desktop-gpui/src/settings_pages.rs @@ -3532,7 +3532,7 @@ impl SettingsWindow { ui::ButtonSize::Md, ) .label("Show File") - .on_click(move |_, _, _| crate::library::reveal_in_folder(&path)), + .on_click(move |_, _, cx| crate::library::reveal_path(&path, cx)), ); } buttons = buttons.child( diff --git a/apps/desktop-gpui/src/settings_window.rs b/apps/desktop-gpui/src/settings_window.rs index 7f76cf3032a..4e3f50041ee 100644 --- a/apps/desktop-gpui/src/settings_window.rs +++ b/apps/desktop-gpui/src/settings_window.rs @@ -2563,7 +2563,7 @@ impl SettingsWindow { "Open folder", false, cx, - move |_this, _window, _cx| library::reveal_in_folder(&bundle), + move |_this, _window, cx| library::reveal_path(&bundle, cx), )) .child(self.row_button( ("screenshot-delete", index), @@ -3052,7 +3052,7 @@ impl SettingsWindow { "Open recording bundle", false, cx, - move |_this, _window, _cx| library::open_recording_folder(&folder_path, mode), + move |_this, _window, cx| library::open_recording_folder(&folder_path, mode, cx), )); actions.child(self.row_button( ("recording-delete", index), diff --git a/apps/desktop-gpui/src/tray.rs b/apps/desktop-gpui/src/tray.rs index b30b919ef18..01b232a429e 100644 --- a/apps/desktop-gpui/src/tray.rs +++ b/apps/desktop-gpui/src/tray.rs @@ -473,35 +473,17 @@ fn open_previous_item(path: PathBuf, cx: &mut App) { } RecordingMetaInner::Instant(_) => { if let Some(sharing) = &meta.sharing { - #[cfg(target_os = "windows")] cx.open_url(&sharing.link); - #[cfg(not(target_os = "windows"))] - open_with_finder(&sharing.link); } else { let mp4 = path.join("content/output.mp4"); if mp4.exists() { - #[cfg(target_os = "windows")] - cx.open_with_system(&mp4); - #[cfg(not(target_os = "windows"))] - open_with_finder(&mp4.to_string_lossy()); + library::open_with_system(&mp4, cx); } } } } } -/// `tauri_plugin_opener`'s `open_url` / `open_path`, which on macOS are both -/// `open ` -- the same spawn `library::open_recording_folder` uses. -#[cfg(not(target_os = "windows"))] -fn open_with_finder(target: &str) { - #[cfg(target_os = "macos")] - if let Err(error) = std::process::Command::new("open").arg(target).spawn() { - tracing::warn!(target, "opening from the tray failed: {error}"); - } - #[cfg(not(target_os = "macos"))] - let _ = target; -} - /// The status item was clicked while a recording is running: stop it, exactly /// as `on_tray_icon_event` does. fn stop_recording(cx: &mut App) {