Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions apps/desktop-gpui/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/desktop-gpui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-gpui/src/deeplink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop-gpui/src/editor_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}),
)
Expand Down
5 changes: 1 addition & 4 deletions apps/desktop-gpui/src/editor_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7084,10 +7084,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>) {
Expand Down
58 changes: 10 additions & 48 deletions apps/desktop-gpui/src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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> {
Expand Down
6 changes: 3 additions & 3 deletions apps/desktop-gpui/src/main_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-gpui/src/screenshot_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
_ => {}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-gpui/src/settings_pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop-gpui/src/settings_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
20 changes: 1 addition & 19 deletions apps/desktop-gpui/src/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading