Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(desktop-gpui): reveal and open paths through GPUI (#3235)
Richie McIlroyc55248a6cee2
diff --git a/apps/desktop-gpui/Cargo.lock b/apps/desktop-gpui/Cargo.lockindex 6f37149b4..5a1a20f08 100644--- a/apps/desktop-gpui/Cargo.lock+++ b/apps/desktop-gpui/Cargo.lock@@ -1569,6 +1569,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.tomlindex 8de8fcd39..2f4409569 100644--- a/apps/desktop-gpui/Cargo.toml+++ b/apps/desktop-gpui/Cargo.toml@@ -162,6 +162,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.rsindex 206f60ba7..8a1523477 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.rsindex 53252dccb..dc66a8375 100644--- a/apps/desktop-gpui/src/editor_export.rs+++ b/apps/desktop-gpui/src/editor_export.rs@@ -2649,9 +2649,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.rsindex 95d5ce1e2..2344d3f2b 100644--- a/apps/desktop-gpui/src/editor_window.rs+++ b/apps/desktop-gpui/src/editor_window.rs@@ -7117,10 +7117,7 @@ impl EditorWindow {fn open_recording_bundle(&mut self, cx: &mut Context<Self>) {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<Self>) {diff --git a/apps/desktop-gpui/src/library.rs b/apps/desktop-gpui/src/library.rsindex 194287426..f0278f56d 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 <dir>` 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.rsindex 73243af39..7c01b3167 100644--- a/apps/desktop-gpui/src/main_window.rs+++ b/apps/desktop-gpui/src/main_window.rs@@ -4786,7 +4786,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,@@ -4863,7 +4863,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),@@ -4945,7 +4945,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.rsindex 0eddf7d36..c764e814d 100644--- a/apps/desktop-gpui/src/screenshot_editor.rs+++ b/apps/desktop-gpui/src/screenshot_editor.rs@@ -2466,7 +2466,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.rsindex 530a8df63..536f5a2c8 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.rsindex decabd793..19b3740a4 100644--- a/apps/desktop-gpui/src/settings_window.rs+++ b/apps/desktop-gpui/src/settings_window.rs@@ -2649,7 +2649,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),@@ -3138,7 +3138,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.rsindex aa2e3220c..4a2ba5e40 100644--- a/apps/desktop-gpui/src/tray.rs+++ b/apps/desktop-gpui/src/tray.rs@@ -495,35 +495,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 <thing>` -- 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) {