diff --git a/app/Cargo.lock b/app/Cargo.lock index 06fd954..22bd19b 100644 --- a/app/Cargo.lock +++ b/app/Cargo.lock @@ -758,6 +758,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e0e367e4e7da84520dedcac1901e4da967309406d1e51017ae1abfb97adbd38" dependencies = [ "bitflags 2.13.2", + "block2 0.6.2", + "libc", "objc2 0.6.5", ] @@ -1894,6 +1896,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d49e936b501e5c5bf01fda3a9452ff86dc3ea98ad5f283e1455153142d97518c" dependencies = [ "bitflags 2.13.2", + "block2 0.6.2", "objc2 0.6.5", "objc2-core-foundation", "objc2-core-graphics", @@ -2730,6 +2733,29 @@ dependencies = [ "usvg", ] +[[package]] +name = "rfd" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20dafead71c16a34e1ff357ddefc8afc11e7d51d6d2b9fbd07eaa48e3e540220" +dependencies = [ + "block2 0.6.2", + "dispatch2", + "js-sys", + "libc", + "log", + "objc2 0.6.5", + "objc2-app-kit 0.3.2", + "objc2-core-foundation", + "objc2-foundation 0.3.2", + "percent-encoding", + "raw-window-handle", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-sys 0.61.2", +] + [[package]] name = "rgb" version = "0.8.53" @@ -2801,6 +2827,7 @@ dependencies = [ "png 0.18.1", "pollster", "raw-window-handle", + "rfd", "rune-core", "rune-edit", "rune-gpu", diff --git a/app/Cargo.toml b/app/Cargo.toml index bbacd77..b6b274d 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -14,7 +14,7 @@ path = "src/main.rs" winresource = "0.1" [dependencies] -rune = { path = "vendor/rune/crates/rune" } +rune = { path = "vendor/rune/crates/rune", features = ["native-file-dialog"] } rune-kit = { path = "vendor/rune/crates/rune-kit" } rune-notify = { path = "vendor/rune/crates/rune-notify" } diff --git a/app/README.md b/app/README.md index 84f126d..279b0da 100644 --- a/app/README.md +++ b/app/README.md @@ -86,7 +86,11 @@ reading (`history::tests`), highlight clipping (`highlight::tests`) and formatti are tested against the daemon's serde names. 3. Settings: done. General, recording, audio and daemon tabs; device and encoder lists come from `getAudioDevices` and `getEncoders`; changes go out through `updateSettings`, and each - application volume slider sends `updateAudioSource` as it moves. + application volume slider sends `updateAudioSource` as it moves. The recordings folder is + shown, not typed: `Select folder` asks the system for one, through the `native-file-dialog` + feature `Cargo.toml` turns on, and headless runs answer it from a script. Every path the + settings show is cut in the middle against the row it sits in, so a narrow window elides + and a wide one shows the whole thing. 4. Match history: done. Cards read `GameHistory.vue`'s fields (result, champion portrait, queue, KDA, CS/m, gold/m, LP change) from the raw API responses in each timeline, with the queue filters. Portraits come from Data Dragon and are cached on disk (`src/portraits.rs`). diff --git a/app/src/screens/settings.rs b/app/src/screens/settings.rs index 9bcf173..0c92a18 100644 --- a/app/src/screens/settings.rs +++ b/app/src/screens/settings.rs @@ -15,7 +15,6 @@ pub struct Form { pub dirty: bool, pub saving: bool, pub open_select: Option<&'static str>, - pub path: TextEdit, pub naming: TextEdit, pub poll_interval: TextEdit, pub bitrate: TextEdit, @@ -28,7 +27,6 @@ impl Form { pub fn empty() -> Self { let draft = Settings::default(); Self { - path: TextEdit::new(&draft.output.path), naming: TextEdit::new(&draft.output.naming_pattern), poll_interval: TextEdit::new(draft.daemon.poll_interval_ms.to_string()), bitrate: TextEdit::new(draft.audio.bitrate.to_string()), @@ -49,7 +47,6 @@ impl Form { return; } self.draft = settings.clone(); - self.path.replace_text(&settings.output.path); self.naming.replace_text(&settings.output.naming_pattern); self.poll_interval .replace_text(settings.daemon.poll_interval_ms.to_string()); @@ -63,7 +60,6 @@ impl Form { /// Pull the text fields into the draft and hand it to `updateSettings`. pub fn settings(&mut self) -> Settings { let mut out = self.draft.clone(); - out.output.path = self.path.text.trim().to_string(); out.output.naming_pattern = self.naming.text.trim().to_string(); out.daemon.poll_interval_ms = self .poll_interval @@ -134,6 +130,57 @@ fn text_row( ui::setting_row_with(p, key, label, hint, ui::text_field(p, key, label, edit, to)) } +/// The folder recordings land in, as the settings hold it, and the button that replaces it with +/// one the system's dialog picks. The path is read back, not typed: a folder is a thing you find. +fn path_row(p: Paint, app: &App, key: &'static str, label: &'static str, hint: &'static str) -> El { + // The whole path, not the last folders. It gets what the labels and the button leave, and a + // middle "…" when that is not enough, so the window's width picks the cut and no character + // count does. The margin holds it off the labels once the row is tight. + let shown = text(&app.form.draft.output.path) + .key("path") + .font(body(12.0)) + .color(p.muted()) + .ml(space::S2) + .truncate_middle(); + let pick = ui::button_tx( + p, + "pick-folder", + "Select folder", + false, + move |app: &mut App, tx: &mut rune::Tx| { + let options = rune::FileDialogOptions { + title: hint.to_string(), + directory: Some(app.output_dir()), + ..Default::default() + }; + tx.open_folder(options, |app: &mut App, result, _| match result { + Ok(Some(path)) => { + app.form.draft.output.path = path.display().to_string(); + app.form.dirty = true; + } + Ok(None) => {} + Err(e) => app.notify_error(format!("No folder dialog: {e}")), + }); + }, + ); + ui::setting_row_with( + p, + key, + label, + hint, + // Growing the control and letting itself be small give the text a bounded width to elide + // inside; content-sized, the row would run off the card. + row() + .gap(space::S2) + .center_y() + .grow(1.0) + .min_w(0.0) + .justify_end() + .child(shown) + .child(pick), + ) +} + #[allow(clippy::too_many_arguments)] // the columns of a settings row fn select_row( p: Paint, @@ -395,26 +442,17 @@ fn quick(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec, content: p, "recordings-folder", "Recordings folder", - text(short_path(&app.form.draft.output.path)) + // Cut in the middle against the row's width, so a narrow window elides. + text(&app.form.draft.output.path) .key("path") .font(body(12.0)) - .color(p.muted()), + .color(p.muted()) + .ml(space::S2) + .truncate_middle(), )], )) } -/// A path as it fits on a row: the last two segments, with the rest elided. -fn short_path(path: &str) -> String { - let sep = std::path::MAIN_SEPARATOR; - let normalized = path.replace(sep, "/"); - let parts: Vec<&str> = normalized.split('/').filter(|p| !p.is_empty()).collect(); - match parts.len() { - 0 => path.to_string(), - 1 | 2 => parts.join(&sep.to_string()), - n => format!("…{sep}{}{sep}{}", parts[n - 2], parts[n - 1]), - } -} - fn recording(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec, content: El) -> El { let v = &app.form.draft.video; let o = &app.form.draft.output; @@ -473,13 +511,12 @@ fn recording(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec, cont }, )), vec![ - text_row( + path_row( p, + app, "output-path", "Folder", "Where finished recordings are written", - &app.form.path, - |app| &mut app.form.path, ), text_row( p, @@ -913,7 +950,10 @@ fn advanced(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec, conte text(value) .key("value") .font(type_::MONO_CAPTION) - .color(p.muted()), + .color(p.muted()) + .ml(space::S2) + // A long value, the log path most of all, is cut to the row's width. + .truncate_middle(), ) }; let recording = if app.status.is_recording { "yes" } else { "no" }; @@ -951,11 +991,7 @@ fn advanced(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec, conte .map(|id| id.to_string()) .unwrap_or_else(|| "none".into()), ), - status_row( - "daemon-log", - "Log file", - short_path(&crate::daemon::log_path()), - ), + status_row("daemon-log", "Log file", crate::daemon::log_path()), ], )) .child(ui::card( diff --git a/app/src/ui.rs b/app/src/ui.rs index 9cd1700..9e64e42 100644 --- a/app/src/ui.rs +++ b/app/src/ui.rs @@ -412,6 +412,18 @@ pub fn button( label: &str, primary: bool, on_press: impl Fn(&mut App) + Send + Sync + 'static, +) -> El { + button_tx(p, key, label, primary, move |app, _| on_press(app)) +} + +/// [`button`] whose press gets the frame's [`Tx`], for a control that asks the window for +/// something: a native folder dialog, an open URL, a clipboard read. +pub fn button_tx( + p: Paint, + key: &str, + label: &str, + primary: bool, + on_press: impl Fn(&mut App, &mut rune::Tx) + Send + Sync + 'static, ) -> El { el().key(key) .role("button") @@ -424,7 +436,7 @@ pub fn button( .fill(if primary { p.accent } else { p.t.control_off }) .hover(p.t.hover) .press(p.t.press) - .on_press(on_press) + .on_press_tx(on_press) .child( text(label) .key("label")