From 0a7a759c4b07200e865f7f90e9eb9c182627dbc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 21 Aug 2026 05:42:23 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(ui):=20the=20Proxies=20defau?= =?UTF-8?q?lt=20gets=20a=20home=20and=20a=20refusal=20finds=20its=20voice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit D1: the Proxies row hint promised a ~/.config/edith default no code ever wrote -- toggling it with nothing open vanished on relaunch. Gives Proxies its own save_proxies_pref/load_proxies_pref, the same sibling file auto-proxies already keeps, wired into toggle_proxies and read at startup. Strengthens the settings guard to scan every row's own hint text for a ~/.config/edith claim and demand the matching pref pair exist, not just the section headers. D2: pressing ctrl+, during an export was a silent no-op -- the oracle's own "an export is running" refusal for ActionId::Settings never reached notify_user because the darkroom's key guard swallowed every key whenever modal() was true, and modal() folds exporting() in. Splits Player::card_open() (an actual card/menu owns the keyboard) out of modal() (that, or an export is running) and points the stance's key guard at card_open() alone, so a bare export with no card open now falls through to enable()/act() and the refusal gets spoken like any other. Every other action refused only by an export was equally mute; this fixes the guard, not the one action. --- crates/app/src/main.rs | 5 ++- crates/app/src/player/cards.rs | 13 +++++++- crates/app/src/player/library.rs | 37 ++++++++++++++++++++++ crates/app/src/tests/cards.rs | 54 ++++++++++++++++++++++++++++++-- crates/app/src/tests/layout.rs | 33 +++++++++++++++++++ crates/app/src/ui/stance.rs | 22 +++++++++++-- 6 files changed, 157 insertions(+), 7 deletions(-) diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 2d0dfa3..ec327b1 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -803,6 +803,9 @@ fn main() { // any project's own line ([`engine::edith::Document::auto_proxy`]) // overrides it the moment one opens. let auto_proxies_on = player::library::load_auto_proxies_pref(); + // The Proxies default the last session left the switch at, same + // before-any-project-line precedence as the auto-proxies default above. + let proxies_on = player::library::load_proxies_pref(); // Nothing named on the command line is read here. The first file makes the // timeline -- a `.edith` restores a whole one, anything else *is* one -- // and the rest are imports like any other: rows in the library, dragged @@ -876,7 +879,7 @@ fn main() { volume_dragging: false, // What a session comes up at, so the first one opened is // pushed the values it already holds. - proxies_on: false, + proxies_on, auto_proxies_on, // Only ever used with a timeline; 30 keeps the empty // timecode reading in frames rather than in NaN. diff --git a/crates/app/src/player/cards.rs b/crates/app/src/player/cards.rs index f317622..7429808 100644 --- a/crates/app/src/player/cards.rs +++ b/crates/app/src/player/cards.rs @@ -1257,6 +1257,18 @@ impl Player { } pub(crate) fn modal(&self) -> bool { + self.card_open() || self.exporting().is_some() + } + + /// Whether an actual card owns the screen -- [`Player::modal`] minus the + /// exporting flag, which is a *state* an action can still be refused + /// over (spoken by the oracle) rather than a surface sitting on top of + /// the keyboard the way every card here does. The darkroom's key guard + /// ([`ui::stance`]'s `on_key_down`) reads this one instead of `modal()` + /// so a bare export in progress, with no card actually open, still lets + /// a keystroke reach `enable()`/`act()` and be answered -- Yes, or a + /// spoken `No` -- instead of being swallowed before either is asked. + pub(crate) fn card_open(&self) -> bool { self.keys_open || self.settings_open || self.export_open @@ -1267,7 +1279,6 @@ impl Player { || self.silence_open.is_some() || self.mix_open || self.subtitle_style_open - || self.exporting().is_some() } /// The pointer's way out of whatever card is up: what every scrim's press diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index 3286626..b7ce130 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -43,6 +43,35 @@ pub(crate) fn save_auto_proxies_pref(on: bool) -> std::io::Result<()> { std::fs::write(path, if on { "on\n" } else { "off\n" }) } +/// Where the Proxies *default* survives -- Proxies' own sibling of +/// [`auto_proxies_pref_path`], same corner-cut persistence. +/// +/// This is the window's own answer, not the project's: a project saved with +/// the switch set carries its own line and always wins once one is open +/// ([`Player::install_project`]) -- this file is only ever read before that. +pub(crate) fn proxies_pref_path() -> PathBuf { + crate::keymap::Keymap::config_path().with_file_name("proxies") +} + +/// `Off` unless the file says `on`; missing, unreadable or garbled all read as +/// `Off`, the same default the field has always started at -- a preference +/// file is not the user's work, so a bad one is worth no message at startup. +pub(crate) fn load_proxies_pref() -> bool { + match std::fs::read_to_string(proxies_pref_path()) { + Ok(text) => text.trim() == "on", + Err(_) => false, + } +} + +/// Writes the pick whole, the way [`save_auto_proxies_pref`] does. +pub(crate) fn save_proxies_pref(on: bool) -> std::io::Result<()> { + let path = proxies_pref_path(); + if let Some(dir) = path.parent() { + std::fs::create_dir_all(dir)?; + } + std::fs::write(path, if on { "on\n" } else { "off\n" }) +} + impl Player { /// The one way a library row reaches the timeline: the Add button and a row /// dragged onto a lane both come here, so there is a single answer to what @@ -772,6 +801,14 @@ impl Player { (true, n, m) => format!("PROXIES ON — cutting on {n}, {m} still being made"), }; eprintln!("{text}"); + // Kept for the next launch, not only the next project -- the same + // reason auto-proxies keeps one ([`save_auto_proxies_pref`]). + if let Err(e) = save_proxies_pref(on) { + let path = proxies_pref_path(); + self.notify_user( + format!("PROXIES DEFAULT COULD NOT BE KEPT — {} — {e}", path.display()).into(), + ); + } self.notify_user(text.into()); // The switch reseeks the session, and the wait for that picture is what // this clears -- with nothing open there is no open to wait for, and a diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index a7f6083..cd36b4c 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -25,7 +25,7 @@ fn no_overlaid_state_in_the_stance_goes_modal_without_painting_something() { ); } let guard_at = stance - .find("if this.rebinding.is_some() || this.overlaid() {") + .find("if this.rebinding.is_some()\n || this.card_open()") .expect("the stance's modal guard"); let guard = &stance[guard_at..guard_at + 1600]; for field in ["this.context_menu = None", "this.library_menu = None", "this.picker = None"] { @@ -43,8 +43,15 @@ fn every_modal_field_has_a_mounted_surface_somewhere_in_the_darkroom() { // rather than hand-copied -- a hand-copied list is exactly the shape // that let three cards go modal with nothing mounted (GAP 2): the field // was in `modal()` and nowhere in this test. - let modal_body = fn_body("modal"); - let mut fields = Vec::new(); + // `modal()` itself is now just `card_open() || exporting().is_some()` + // ([`Player::card_open`], split out so the darkroom's key guard can read + // "a card is open" without also reading "an export is running" -- see + // `ui::stance`'s guard and `an_export_alone_does_not_lock_the_stances_keyboard` + // below) -- so the card fields this test pins live in `card_open()` now, + // with `exporting` added by hand since `modal()`'s own body names it + // directly rather than through a field this splitter would find. + let modal_body = fn_body("card_open"); + let mut fields = vec!["exporting".to_string()]; for chunk in modal_body.split("self.").skip(1) { let name: String = chunk .chars() @@ -96,6 +103,47 @@ fn every_modal_field_has_a_mounted_surface_somewhere_in_the_darkroom() { } } +/// D2's class: an action refused while a modal is up used to be sworn to +/// silence, because the stance's own key guard ate the keystroke before +/// `enable()`/`act()` ever saw it -- driven live with `ctrl+,` mid-export +/// (no card open, only `exporting()` true): no notice plate, ledger reading +/// `—`. `ActionId::Settings`'s own refusal string (`oracle.rs`) was sound and +/// simply never reachable. +/// +/// The fix lives in the guard, not in Settings alone (the charter this test +/// pins is explicit that a per-action patch would leave every *other* action +/// refused during a bare export equally mute): [`Player::card_open`] is +/// `modal()` with `exporting()` split out, and the stance's guard now reads +/// `card_open()` -- never `overlaid()`/`modal()` directly, both of which +/// still fold `exporting()` back in for the surfaces that are meant to keep +/// blocking imports and edits during an export ([`Player::modal`]'s own +/// doc comment). This is a source scan, the same kind the guard above it +/// already is: this binary has no `TestAppContext` to actually press `ctrl+,` +/// mid-export and read the notice plate back. +#[test] +fn the_stances_key_guard_does_not_swallow_a_bare_export_before_the_oracle_is_asked() { + let stance = src_text("ui/stance.rs"); + let guard_at = stance + .find("if this.rebinding.is_some()\n || this.card_open()") + .expect("the stance's modal guard moved -- update this test's search string"); + let guard_line = &stance[guard_at..guard_at + 200]; + assert!( + !guard_line.contains("overlaid()") && !guard_line.contains("this.modal()"), + "the stance's key guard reads overlaid()/modal() again, which folds `exporting()` \ + back in and re-mutes every refusal an export-only moment should be able to speak (D2)" + ); + // The split itself: card_open() must never grow an exporting read of its + // own, or the guard above -- which trusts card_open() to mean "an actual + // card/menu/rebind owns the keyboard" -- silently regains the same mute. + let card_open_body = fn_body("card_open"); + assert!( + !card_open_body.contains("exporting"), + "Player::card_open() now reads `exporting` -- that reintroduces the swallow \ + `the_stances_key_guard_does_not_swallow_a_bare_export_before_the_oracle_is_asked` \ + exists to keep out; `modal()` is where `exporting()` belongs" + ); +} + #[test] fn a_bare_escape_leaves_player_fullscreen_before_anything_under_it() { // Fires while the picture-only layout is up, on the same bare escape diff --git a/crates/app/src/tests/layout.rs b/crates/app/src/tests/layout.rs index c5d8a48..e18ac8e 100644 --- a/crates/app/src/tests/layout.rs +++ b/crates/app/src/tests/layout.rs @@ -1968,6 +1968,39 @@ fn settings_project_and_editor_sections_open_disjoint_doors() { } } +/// D1's own class, pinned per row rather than per section: a row's hint can +/// claim a `~/.config/edith` default (the section header claims nothing on +/// its own since [`settings_project_and_editor_sections_open_disjoint_doors`]'s +/// commit, so a lying section head no longer slips past a reviewer -- but a +/// lying *row* hint did, on Proxies, because nothing scanned row text at all). +/// For every row whose own hint text names that file, this requires the +/// matching `save_*_pref`/`load_*_pref` pair to actually exist in +/// `player/library.rs` -- the exact gap Proxies shipped with: a hint promising +/// a default the row's own door never wrote. +#[test] +fn settings_row_hints_naming_config_edith_have_a_matching_pref_pair() { + let source = src_text("ui/settings_stance.rs"); + let library = src_text("player/library.rs"); + // (row id, the stem its pref functions are named after) + for (row_id, stem) in [("settings-proxies", "proxies"), ("settings-auto-proxies", "auto_proxies")] { + let row_start = source.find(&format!("\"{row_id}\"")).unwrap_or_else(|| panic!("{row_id} row moved or renamed -- update this guard")); + let row_end = source[row_start..].find(",\n ))").map_or(source.len(), |i| row_start + i); + let row_text = &source[row_start..row_end]; + if !row_text.contains("~/.config/edith") { + continue; + } + for prefix in ["save_", "load_"] { + let fn_name = format!("{prefix}{stem}_pref"); + assert!( + library.contains(&format!("fn {fn_name}(")), + "{row_id}'s hint claims a ~/.config/edith default but \ + player/library.rs has no `{fn_name}` -- the hint promises \ + storage the row does not have" + ); + } + } +} + /// With no project open, a PROJECT row must not fall back to a bare noun /// ("Size"/"Rate"/"HDR") standing in the value slot -- it reads as a value /// while carrying none. This binary has no `TestAppContext` to actually diff --git a/crates/app/src/ui/stance.rs b/crates/app/src/ui/stance.rs index effbb97..1df8ce9 100644 --- a/crates/app/src/ui/stance.rs +++ b/crates/app/src/ui/stance.rs @@ -679,14 +679,32 @@ pub(crate) fn render( return; } // Same modal guard the legacy handler's rebinding/keys_open/ - // export_open/exporting/colour/transform/speed/EQ/silence/mix/ + // export_open/colour/transform/speed/EQ/silence/mix/ // subtitle-style/menu chain (`render.rs`) amounts to, read as // one bool instead of re-copied field by field: while a card, a // rebind capture, or a menu owns the keyboard, the darkroom // stance yields to it exactly as the legacy tree does. This is // the fix for the stance's `Home`-inside-the-Colour-card // misfire. - if this.rebinding.is_some() || this.overlaid() { + // + // `exporting()` alone is deliberately left out of this list + // (`Player::card_open` is `modal()` minus it): a running export + // draws no card of its own to own the keyboard for, and a key + // caught here never reaches `enable()`/`act()` below, so a + // refusal the oracle would have spoken (`ActionId::Settings` + // among them) never got said -- the room went silent instead. + // Letting an export-only moment fall through costs nothing this + // guard exists for: every action the oracle would still refuse + // during an export says so through `act()`'s own `Enable::No` + // branch, and the six it leaves live (Theme, Fullscreen, + // SubtitleStyle, CancelExport, ...) are exactly the ones meant + // to keep working. + if this.rebinding.is_some() + || this.card_open() + || this.context_menu.is_some() + || this.library_menu.is_some() + || this.picker.is_some() + { // Escape is every card's own way out (`Player::close_card`, // the same list `overlaid`/`modal` read) -- blocking every // key while a card is open must not also lock the card open.