forge
Explore
Log in

Don't you dare go Hollow

The done notice opens the file's location

Browse files at this commit

cbb8a50098f9d9478698185ff76e445625dda152Ahmet Kaan GümüşParent: 99fb07c
  • feat
    • the done notice opens the file's location
Show full message
✨ feat(export): the done notice opens the file's location

A finished export names a file that is now on disk, so the bar it announces
itself in became the way to it: clicking the DONE line asks the desktop's
FileManager1 to show that file selected, falling back to opening its folder
with xdg-open, and retires the notice as any click always did. The path is
kept beside the notice and read only while that line is the one showing, so a
later message turns the bar back into a plain dismissal.
crates/app/src/main.rsmodified+111 -4
@@ -400,6 +400,10 @@ struct Player {
400400 /// until it is answered -- any key retires it, so does a click on it -- so a
401401 /// failure is read in full instead of blinking past.
402402 notice: Option<SharedString>,
403+ /// What the last finished export wrote, so the notice can be the way to it.
404+ /// Only the [`EXPORT_DONE`] line reads it -- any later notice has replaced
405+ /// that text -- so a click never opens a file the bar is not naming.
406+ exported: Option<PathBuf>,
403407 /// What the compositor was last told this window is called. Setting a title
404408 /// is a protocol round trip and a repaint is sixty a second, so the title is
405409 /// pushed only when it is not this any more.
@@ -1533,7 +1537,12 @@ impl Player {
15331537 return;
15341538 }
15351539 let text = match result {
1536- Ok(()) => format!("EXPORT DONE → {}", file_name(&self.export_path)),
1540+ Ok(()) => {
1541+ // Written and still where it was written: the bar carries it
1542+ // until some other notice takes the bar.
1543+ self.exported = Some(self.export_path.clone());
1544+ format!("{EXPORT_DONE}{}", file_name(&self.export_path))
1545+ }
15371546 Err(e) => format!("EXPORT FAILED: {e}"),
15381547 };
15391548 eprintln!("{text}");
@@ -2388,11 +2397,31 @@ impl Player {
23882397 /// retires it (the key handler) and so does a click on it. Its own surface
23892398 /// because the message is the point -- a failure cut to the timecode's slot
23902399 /// is a failure nobody read.
2400+ ///
2401+ /// The export's own line is more than a message: it names a file that is
2402+ /// now on disk, so the same click that retires it shows that file in the
2403+ /// desktop's file manager.
23912404 fn notice_bar(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> {
23922405 let notice = self.notice.clone()?;
2406+ // The path travels with the text it was written for: a later notice
2407+ // holds the bar and the click is a plain dismissal again.
2408+ let exported = self
2409+ .exported
2410+ .clone()
2411+ .filter(|_| notice.starts_with(EXPORT_DONE));
2412+ let hint = match exported {
2413+ Some(_) => "click — open file location",
2414+ None => "click or press any key to dismiss",
2415+ };
23932416 Some(
23942417 div()
23952418 .id("notice")
2419+ .when(exported.is_some(), |d| {
2420+ d.tooltip(|_, cx| {
2421+ cx.new(|_| Tip("Open file location — shows the export in the file manager".into()))
2422+ .into()
2423+ })
2424+ })
23962425 .flex_none()
23972426 .flex()
23982427 .items_start()
@@ -2402,7 +2431,14 @@ impl Player {
24022431 .bg(rgb(SURFACE))
24032432 .cursor_pointer()
24042433 .hover(|s| s.bg(rgb(HOVER)))
2405- .on_click(cx.listener(|this, _: &ClickEvent, _, cx| {
2434+ .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
2435+ // Another process starting: off the UI thread, and it
2436+ // outlives the notice it was asked from.
2437+ if let Some(path) = exported.clone() {
2438+ cx.background_executor()
2439+ .spawn(async move { show_in_file_manager(&path) })
2440+ .detach();
2441+ }
24062442 this.notice = None;
24072443 cx.notify();
24082444 }))
@@ -2412,7 +2448,7 @@ impl Player {
24122448 .flex_none()
24132449 .text_size(px(11.))
24142450 .text_color(rgb(INK_DIM))
2415- .child("click or press any key to dismiss"),
2451+ .child(hint),
24162452 ),
24172453 )
24182454 }
@@ -3477,6 +3513,61 @@ fn scrub_due(target: u32, last_target: u32, since: Duration) -> bool {
34773513 target != last_target && since >= SCRUB_GAP
34783514 }
34793515
3516+/// How a finished export announces itself. Written by `poll_export` and read
3517+/// by the notice bar, which is what makes that one line clickable.
3518+const EXPORT_DONE: &str = "EXPORT DONE → ";
3519+
3520+/// The path as a URI the bus will take: percent-encoded, because an export
3521+/// lands wherever its source lives and those directories have spaces in them.
3522+/// Bytes, not chars -- a path is not required to be UTF-8.
3523+fn file_uri(path: &std::path::Path) -> String {
3524+ use std::os::unix::ffi::OsStrExt;
3525+ let mut uri = String::from("file://");
3526+ for &b in path.as_os_str().as_bytes() {
3527+ match b {
3528+ b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' | b'/' => {
3529+ uri.push(b as char)
3530+ }
3531+ _ => uri.push_str(&format!("%{b:02X}")),
3532+ }
3533+ }
3534+ uri
3535+}
3536+
3537+/// Shows a file in the desktop's file manager, selected: the freedesktop
3538+/// interface every major one answers, asked for over the session bus. With no
3539+/// file manager on the bus the folder itself is the next best thing, and with
3540+/// neither there is nothing to say -- the notice the click retired was the
3541+/// answer, and a machine without a desktop opener is not one a second notice
3542+/// would help. Blocks on two child processes, so it is never called on the UI
3543+/// thread.
3544+fn show_in_file_manager(path: &std::path::Path) {
3545+ // The URI must be absolute; an export path is only as absolute as the
3546+ // source it was built from.
3547+ let path = std::fs::canonicalize(path).unwrap_or_else(|_| path.to_path_buf());
3548+ let shown = std::process::Command::new("busctl")
3549+ .args([
3550+ "--user",
3551+ "call",
3552+ "org.freedesktop.FileManager1",
3553+ "/org/freedesktop/FileManager1",
3554+ "org.freedesktop.FileManager1",
3555+ "ShowItems",
3556+ "ass",
3557+ "1",
3558+ &file_uri(&path),
3559+ "",
3560+ ])
3561+ .status()
3562+ .is_ok_and(|s| s.success());
3563+ if shown {
3564+ return;
3565+ }
3566+ if let Some(dir) = path.parent() {
3567+ let _ = std::process::Command::new("xdg-open").arg(dir).status();
3568+ }
3569+}
3570+
34803571 /// Runs the first chooser that is installed. `Some(None)` is a cancelled
34813572 /// dialog; `None` is a machine with no chooser at all, and what still works
34823573 /// without one differs per dialog, so the caller words that refusal.
@@ -4511,7 +4602,22 @@ mod tests {
45114602 show_label, source_frames, source_tint, start_frac, timecode, unseen_paths, unseen_sources,
45124603 whole_take, width_frac, window_title,
45134604 };
4514- use super::{file_name, library_rows};
4605+ use super::{file_name, file_uri, library_rows};
4606+
4607+ /// What the file manager is handed: the parts a path keeps as they are, and
4608+ /// the ones the bus would otherwise read as something else.
4609+ #[test]
4610+ fn file_uri_encodes_what_a_path_carries() {
4611+ assert_eq!(file_uri(std::path::Path::new("/a/b.mp4")), "file:///a/b.mp4");
4612+ assert_eq!(
4613+ file_uri(std::path::Path::new("/home/x/out dir/my export.mp4")),
4614+ "file:///home/x/out%20dir/my%20export.mp4"
4615+ );
4616+ assert_eq!(
4617+ file_uri(std::path::Path::new("/tmp/ünlü#1?.mp4")),
4618+ "file:///tmp/%C3%BCnl%C3%BC%231%3F.mp4"
4619+ );
4620+ }
45154621 use engine::PlaybackSession;
45164622 use engine::scale::FitPolicy;
45174623 use gpui::{Bounds, Pixels, point, px, size};
@@ -5860,6 +5966,7 @@ fn main() {
58605966 format: Format::default(),
58615967 rebinding: None,
58625968 notice: notice.clone().map(SharedString::from),
5969+ exported: None,
58635970 // Nothing pushed yet, and never a real title: the first
58645971 // render is what names the window.
58655972 titled: String::new(),