The done notice opens the file's location
Browse files at this commitcbb8a50098f9d9478698185ff76e445625dda152Parent: 99fb07c- feat
- the done notice opens the file's location
1 changed file +111 -4
- crates/app/src/main.rs +111 -4
crates/app/src/main.rsmodified+111 -4
| @@ -400,6 +400,10 @@ struct Player { | ||
| 400 | 400 | /// until it is answered -- any key retires it, so does a click on it -- so a |
| 401 | 401 | /// failure is read in full instead of blinking past. |
| 402 | 402 | 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>, | |
| 403 | 407 | /// What the compositor was last told this window is called. Setting a title |
| 404 | 408 | /// is a protocol round trip and a repaint is sixty a second, so the title is |
| 405 | 409 | /// pushed only when it is not this any more. |
| @@ -1533,7 +1537,12 @@ impl Player { | ||
| 1533 | 1537 | return; |
| 1534 | 1538 | } |
| 1535 | 1539 | 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 | + } | |
| 1537 | 1546 | Err(e) => format!("EXPORT FAILED: {e}"), |
| 1538 | 1547 | }; |
| 1539 | 1548 | eprintln!("{text}"); |
| @@ -2388,11 +2397,31 @@ impl Player { | ||
| 2388 | 2397 | /// retires it (the key handler) and so does a click on it. Its own surface |
| 2389 | 2398 | /// because the message is the point -- a failure cut to the timecode's slot |
| 2390 | 2399 | /// 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. | |
| 2391 | 2404 | fn notice_bar(&self, cx: &mut Context<Self>) -> Option<impl IntoElement> { |
| 2392 | 2405 | 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 | + }; | |
| 2393 | 2416 | Some( |
| 2394 | 2417 | div() |
| 2395 | 2418 | .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 | + }) | |
| 2396 | 2425 | .flex_none() |
| 2397 | 2426 | .flex() |
| 2398 | 2427 | .items_start() |
| @@ -2402,7 +2431,14 @@ impl Player { | ||
| 2402 | 2431 | .bg(rgb(SURFACE)) |
| 2403 | 2432 | .cursor_pointer() |
| 2404 | 2433 | .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 | + } | |
| 2406 | 2442 | this.notice = None; |
| 2407 | 2443 | cx.notify(); |
| 2408 | 2444 | })) |
| @@ -2412,7 +2448,7 @@ impl Player { | ||
| 2412 | 2448 | .flex_none() |
| 2413 | 2449 | .text_size(px(11.)) |
| 2414 | 2450 | .text_color(rgb(INK_DIM)) |
| 2415 | - .child("click or press any key to dismiss"), | |
| 2451 | + .child(hint), | |
| 2416 | 2452 | ), |
| 2417 | 2453 | ) |
| 2418 | 2454 | } |
| @@ -3477,6 +3513,61 @@ fn scrub_due(target: u32, last_target: u32, since: Duration) -> bool { | ||
| 3477 | 3513 | target != last_target && since >= SCRUB_GAP |
| 3478 | 3514 | } |
| 3479 | 3515 | |
| 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 | + | |
| 3480 | 3571 | /// Runs the first chooser that is installed. `Some(None)` is a cancelled |
| 3481 | 3572 | /// dialog; `None` is a machine with no chooser at all, and what still works |
| 3482 | 3573 | /// without one differs per dialog, so the caller words that refusal. |
| @@ -4511,7 +4602,22 @@ mod tests { | ||
| 4511 | 4602 | show_label, source_frames, source_tint, start_frac, timecode, unseen_paths, unseen_sources, |
| 4512 | 4603 | whole_take, width_frac, window_title, |
| 4513 | 4604 | }; |
| 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 | + } | |
| 4515 | 4621 | use engine::PlaybackSession; |
| 4516 | 4622 | use engine::scale::FitPolicy; |
| 4517 | 4623 | use gpui::{Bounds, Pixels, point, px, size}; |
| @@ -5860,6 +5966,7 @@ fn main() { | ||
| 5860 | 5966 | format: Format::default(), |
| 5861 | 5967 | rebinding: None, |
| 5862 | 5968 | notice: notice.clone().map(SharedString::from), |
| 5969 | + exported: None, | |
| 5863 | 5970 | // Nothing pushed yet, and never a real title: the first |
| 5864 | 5971 | // render is what names the window. |
| 5865 | 5972 | titled: String::new(), |