The Proxies default gets a home and a refusal finds its voice
Browse files at this commit0a7a759c4b07200e865f7f90e9eb9c182627dbc9Parent: ba3306f- fix
- the Proxies default gets a home and a refusal finds its voice
6 changed files +157 -7
- crates/app/src/main.rs +4 -1
- crates/app/src/player/cards.rs +12 -1
- crates/app/src/player/library.rs +37 -0
- crates/app/src/tests/cards.rs +51 -3
- crates/app/src/tests/layout.rs +33 -0
- crates/app/src/ui/stance.rs +20 -2
crates/app/src/main.rsmodified+4 -1
| @@ -803,6 +803,9 @@ fn main() { | |||
| 803 | // any project's own line ([`engine::edith::Document::auto_proxy`]) | 803 | // any project's own line ([`engine::edith::Document::auto_proxy`]) |
| 804 | // overrides it the moment one opens. | 804 | // overrides it the moment one opens. |
| 805 | let auto_proxies_on = player::library::load_auto_proxies_pref(); | 805 | let auto_proxies_on = player::library::load_auto_proxies_pref(); |
| 806 | + // The Proxies default the last session left the switch at, same | ||
| 807 | + // before-any-project-line precedence as the auto-proxies default above. | ||
| 808 | + let proxies_on = player::library::load_proxies_pref(); | ||
| 806 | // Nothing named on the command line is read here. The first file makes the | 809 | // Nothing named on the command line is read here. The first file makes the |
| 807 | // timeline -- a `.edith` restores a whole one, anything else *is* one -- | 810 | // timeline -- a `.edith` restores a whole one, anything else *is* one -- |
| 808 | // and the rest are imports like any other: rows in the library, dragged | 811 | // and the rest are imports like any other: rows in the library, dragged |
| @@ -876,7 +879,7 @@ fn main() { | |||
| 876 | volume_dragging: false, | 879 | volume_dragging: false, |
| 877 | // What a session comes up at, so the first one opened is | 880 | // What a session comes up at, so the first one opened is |
| 878 | // pushed the values it already holds. | 881 | // pushed the values it already holds. |
| 879 | - proxies_on: false, | 882 | + proxies_on, |
| 880 | auto_proxies_on, | 883 | auto_proxies_on, |
| 881 | // Only ever used with a timeline; 30 keeps the empty | 884 | // Only ever used with a timeline; 30 keeps the empty |
| 882 | // timecode reading in frames rather than in NaN. | 885 | // timecode reading in frames rather than in NaN. |
crates/app/src/player/cards.rsmodified+12 -1
| @@ -1257,6 +1257,18 @@ impl Player { | |||
| 1257 | } | 1257 | } |
| 1258 | 1258 | ||
| 1259 | pub(crate) fn modal(&self) -> bool { | 1259 | pub(crate) fn modal(&self) -> bool { |
| 1260 | + self.card_open() || self.exporting().is_some() | ||
| 1261 | + } | ||
| 1262 | + | ||
| 1263 | + /// Whether an actual card owns the screen -- [`Player::modal`] minus the | ||
| 1264 | + /// exporting flag, which is a *state* an action can still be refused | ||
| 1265 | + /// over (spoken by the oracle) rather than a surface sitting on top of | ||
| 1266 | + /// the keyboard the way every card here does. The darkroom's key guard | ||
| 1267 | + /// ([`ui::stance`]'s `on_key_down`) reads this one instead of `modal()` | ||
| 1268 | + /// so a bare export in progress, with no card actually open, still lets | ||
| 1269 | + /// a keystroke reach `enable()`/`act()` and be answered -- Yes, or a | ||
| 1270 | + /// spoken `No` -- instead of being swallowed before either is asked. | ||
| 1271 | + pub(crate) fn card_open(&self) -> bool { | ||
| 1260 | self.keys_open | 1272 | self.keys_open |
| 1261 | || self.settings_open | 1273 | || self.settings_open |
| 1262 | || self.export_open | 1274 | || self.export_open |
| @@ -1267,7 +1279,6 @@ impl Player { | |||
| 1267 | || self.silence_open.is_some() | 1279 | || self.silence_open.is_some() |
| 1268 | || self.mix_open | 1280 | || self.mix_open |
| 1269 | || self.subtitle_style_open | 1281 | || self.subtitle_style_open |
| 1270 | - || self.exporting().is_some() | ||
| 1271 | } | 1282 | } |
| 1272 | 1283 | ||
| 1273 | /// The pointer's way out of whatever card is up: what every scrim's press | 1284 | /// The pointer's way out of whatever card is up: what every scrim's press |
crates/app/src/player/library.rsmodified+37 -0
| @@ -43,6 +43,35 @@ pub(crate) fn save_auto_proxies_pref(on: bool) -> std::io::Result<()> { | |||
| 43 | std::fs::write(path, if on { "on\n" } else { "off\n" }) | 43 | std::fs::write(path, if on { "on\n" } else { "off\n" }) |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | +/// Where the Proxies *default* survives -- Proxies' own sibling of | ||
| 47 | +/// [`auto_proxies_pref_path`], same corner-cut persistence. | ||
| 48 | +/// | ||
| 49 | +/// This is the window's own answer, not the project's: a project saved with | ||
| 50 | +/// the switch set carries its own line and always wins once one is open | ||
| 51 | +/// ([`Player::install_project`]) -- this file is only ever read before that. | ||
| 52 | +pub(crate) fn proxies_pref_path() -> PathBuf { | ||
| 53 | + crate::keymap::Keymap::config_path().with_file_name("proxies") | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +/// `Off` unless the file says `on`; missing, unreadable or garbled all read as | ||
| 57 | +/// `Off`, the same default the field has always started at -- a preference | ||
| 58 | +/// file is not the user's work, so a bad one is worth no message at startup. | ||
| 59 | +pub(crate) fn load_proxies_pref() -> bool { | ||
| 60 | + match std::fs::read_to_string(proxies_pref_path()) { | ||
| 61 | + Ok(text) => text.trim() == "on", | ||
| 62 | + Err(_) => false, | ||
| 63 | + } | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +/// Writes the pick whole, the way [`save_auto_proxies_pref`] does. | ||
| 67 | +pub(crate) fn save_proxies_pref(on: bool) -> std::io::Result<()> { | ||
| 68 | + let path = proxies_pref_path(); | ||
| 69 | + if let Some(dir) = path.parent() { | ||
| 70 | + std::fs::create_dir_all(dir)?; | ||
| 71 | + } | ||
| 72 | + std::fs::write(path, if on { "on\n" } else { "off\n" }) | ||
| 73 | +} | ||
| 74 | + | ||
| 46 | impl Player { | 75 | impl Player { |
| 47 | /// The one way a library row reaches the timeline: the Add button and a row | 76 | /// The one way a library row reaches the timeline: the Add button and a row |
| 48 | /// dragged onto a lane both come here, so there is a single answer to what | 77 | /// dragged onto a lane both come here, so there is a single answer to what |
| @@ -772,6 +801,14 @@ impl Player { | |||
| 772 | (true, n, m) => format!("PROXIES ON — cutting on {n}, {m} still being made"), | 801 | (true, n, m) => format!("PROXIES ON — cutting on {n}, {m} still being made"), |
| 773 | }; | 802 | }; |
| 774 | eprintln!("{text}"); | 803 | eprintln!("{text}"); |
| 804 | + // Kept for the next launch, not only the next project -- the same | ||
| 805 | + // reason auto-proxies keeps one ([`save_auto_proxies_pref`]). | ||
| 806 | + if let Err(e) = save_proxies_pref(on) { | ||
| 807 | + let path = proxies_pref_path(); | ||
| 808 | + self.notify_user( | ||
| 809 | + format!("PROXIES DEFAULT COULD NOT BE KEPT — {} — {e}", path.display()).into(), | ||
| 810 | + ); | ||
| 811 | + } | ||
| 775 | self.notify_user(text.into()); | 812 | self.notify_user(text.into()); |
| 776 | // The switch reseeks the session, and the wait for that picture is what | 813 | // The switch reseeks the session, and the wait for that picture is what |
| 777 | // this clears -- with nothing open there is no open to wait for, and a | 814 | // this clears -- with nothing open there is no open to wait for, and a |
crates/app/src/tests/cards.rsmodified+51 -3
| @@ -25,7 +25,7 @@ fn no_overlaid_state_in_the_stance_goes_modal_without_painting_something() { | |||
| 25 | ); | 25 | ); |
| 26 | } | 26 | } |
| 27 | let guard_at = stance | 27 | let guard_at = stance |
| 28 | - .find("if this.rebinding.is_some() || this.overlaid() {") | 28 | + .find("if this.rebinding.is_some()\n || this.card_open()") |
| 29 | .expect("the stance's modal guard"); | 29 | .expect("the stance's modal guard"); |
| 30 | let guard = &stance[guard_at..guard_at + 1600]; | 30 | let guard = &stance[guard_at..guard_at + 1600]; |
| 31 | for field in ["this.context_menu = None", "this.library_menu = None", "this.picker = None"] { | 31 | 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() { | |||
| 43 | // rather than hand-copied -- a hand-copied list is exactly the shape | 43 | // rather than hand-copied -- a hand-copied list is exactly the shape |
| 44 | // that let three cards go modal with nothing mounted (GAP 2): the field | 44 | // that let three cards go modal with nothing mounted (GAP 2): the field |
| 45 | // was in `modal()` and nowhere in this test. | 45 | // was in `modal()` and nowhere in this test. |
| 46 | - let modal_body = fn_body("modal"); | 46 | + // `modal()` itself is now just `card_open() || exporting().is_some()` |
| 47 | - let mut fields = Vec::new(); | 47 | + // ([`Player::card_open`], split out so the darkroom's key guard can read |
| 48 | + // "a card is open" without also reading "an export is running" -- see | ||
| 49 | + // `ui::stance`'s guard and `an_export_alone_does_not_lock_the_stances_keyboard` | ||
| 50 | + // below) -- so the card fields this test pins live in `card_open()` now, | ||
| 51 | + // with `exporting` added by hand since `modal()`'s own body names it | ||
| 52 | + // directly rather than through a field this splitter would find. | ||
| 53 | + let modal_body = fn_body("card_open"); | ||
| 54 | + let mut fields = vec!["exporting".to_string()]; | ||
| 48 | for chunk in modal_body.split("self.").skip(1) { | 55 | for chunk in modal_body.split("self.").skip(1) { |
| 49 | let name: String = chunk | 56 | let name: String = chunk |
| 50 | .chars() | 57 | .chars() |
| @@ -96,6 +103,47 @@ fn every_modal_field_has_a_mounted_surface_somewhere_in_the_darkroom() { | |||
| 96 | } | 103 | } |
| 97 | } | 104 | } |
| 98 | 105 | ||
| 106 | +/// D2's class: an action refused while a modal is up used to be sworn to | ||
| 107 | +/// silence, because the stance's own key guard ate the keystroke before | ||
| 108 | +/// `enable()`/`act()` ever saw it -- driven live with `ctrl+,` mid-export | ||
| 109 | +/// (no card open, only `exporting()` true): no notice plate, ledger reading | ||
| 110 | +/// `—`. `ActionId::Settings`'s own refusal string (`oracle.rs`) was sound and | ||
| 111 | +/// simply never reachable. | ||
| 112 | +/// | ||
| 113 | +/// The fix lives in the guard, not in Settings alone (the charter this test | ||
| 114 | +/// pins is explicit that a per-action patch would leave every *other* action | ||
| 115 | +/// refused during a bare export equally mute): [`Player::card_open`] is | ||
| 116 | +/// `modal()` with `exporting()` split out, and the stance's guard now reads | ||
| 117 | +/// `card_open()` -- never `overlaid()`/`modal()` directly, both of which | ||
| 118 | +/// still fold `exporting()` back in for the surfaces that are meant to keep | ||
| 119 | +/// blocking imports and edits during an export ([`Player::modal`]'s own | ||
| 120 | +/// doc comment). This is a source scan, the same kind the guard above it | ||
| 121 | +/// already is: this binary has no `TestAppContext` to actually press `ctrl+,` | ||
| 122 | +/// mid-export and read the notice plate back. | ||
| 123 | +#[test] | ||
| 124 | +fn the_stances_key_guard_does_not_swallow_a_bare_export_before_the_oracle_is_asked() { | ||
| 125 | + let stance = src_text("ui/stance.rs"); | ||
| 126 | + let guard_at = stance | ||
| 127 | + .find("if this.rebinding.is_some()\n || this.card_open()") | ||
| 128 | + .expect("the stance's modal guard moved -- update this test's search string"); | ||
| 129 | + let guard_line = &stance[guard_at..guard_at + 200]; | ||
| 130 | + assert!( | ||
| 131 | + !guard_line.contains("overlaid()") && !guard_line.contains("this.modal()"), | ||
| 132 | + "the stance's key guard reads overlaid()/modal() again, which folds `exporting()` \ | ||
| 133 | + back in and re-mutes every refusal an export-only moment should be able to speak (D2)" | ||
| 134 | + ); | ||
| 135 | + // The split itself: card_open() must never grow an exporting read of its | ||
| 136 | + // own, or the guard above -- which trusts card_open() to mean "an actual | ||
| 137 | + // card/menu/rebind owns the keyboard" -- silently regains the same mute. | ||
| 138 | + let card_open_body = fn_body("card_open"); | ||
| 139 | + assert!( | ||
| 140 | + !card_open_body.contains("exporting"), | ||
| 141 | + "Player::card_open() now reads `exporting` -- that reintroduces the swallow \ | ||
| 142 | + `the_stances_key_guard_does_not_swallow_a_bare_export_before_the_oracle_is_asked` \ | ||
| 143 | + exists to keep out; `modal()` is where `exporting()` belongs" | ||
| 144 | + ); | ||
| 145 | +} | ||
| 146 | + | ||
| 99 | #[test] | 147 | #[test] |
| 100 | fn a_bare_escape_leaves_player_fullscreen_before_anything_under_it() { | 148 | fn a_bare_escape_leaves_player_fullscreen_before_anything_under_it() { |
| 101 | // Fires while the picture-only layout is up, on the same bare escape | 149 | // Fires while the picture-only layout is up, on the same bare escape |
crates/app/src/tests/layout.rsmodified+33 -0
| @@ -1968,6 +1968,39 @@ fn settings_project_and_editor_sections_open_disjoint_doors() { | |||
| 1968 | } | 1968 | } |
| 1969 | } | 1969 | } |
| 1970 | 1970 | ||
| 1971 | +/// D1's own class, pinned per row rather than per section: a row's hint can | ||
| 1972 | +/// claim a `~/.config/edith` default (the section header claims nothing on | ||
| 1973 | +/// its own since [`settings_project_and_editor_sections_open_disjoint_doors`]'s | ||
| 1974 | +/// commit, so a lying section head no longer slips past a reviewer -- but a | ||
| 1975 | +/// lying *row* hint did, on Proxies, because nothing scanned row text at all). | ||
| 1976 | +/// For every row whose own hint text names that file, this requires the | ||
| 1977 | +/// matching `save_*_pref`/`load_*_pref` pair to actually exist in | ||
| 1978 | +/// `player/library.rs` -- the exact gap Proxies shipped with: a hint promising | ||
| 1979 | +/// a default the row's own door never wrote. | ||
| 1980 | +#[test] | ||
| 1981 | +fn settings_row_hints_naming_config_edith_have_a_matching_pref_pair() { | ||
| 1982 | + let source = src_text("ui/settings_stance.rs"); | ||
| 1983 | + let library = src_text("player/library.rs"); | ||
| 1984 | + // (row id, the stem its pref functions are named after) | ||
| 1985 | + for (row_id, stem) in [("settings-proxies", "proxies"), ("settings-auto-proxies", "auto_proxies")] { | ||
| 1986 | + let row_start = source.find(&format!("\"{row_id}\"")).unwrap_or_else(|| panic!("{row_id} row moved or renamed -- update this guard")); | ||
| 1987 | + let row_end = source[row_start..].find(",\n ))").map_or(source.len(), |i| row_start + i); | ||
| 1988 | + let row_text = &source[row_start..row_end]; | ||
| 1989 | + if !row_text.contains("~/.config/edith") { | ||
| 1990 | + continue; | ||
| 1991 | + } | ||
| 1992 | + for prefix in ["save_", "load_"] { | ||
| 1993 | + let fn_name = format!("{prefix}{stem}_pref"); | ||
| 1994 | + assert!( | ||
| 1995 | + library.contains(&format!("fn {fn_name}(")), | ||
| 1996 | + "{row_id}'s hint claims a ~/.config/edith default but \ | ||
| 1997 | + player/library.rs has no `{fn_name}` -- the hint promises \ | ||
| 1998 | + storage the row does not have" | ||
| 1999 | + ); | ||
| 2000 | + } | ||
| 2001 | + } | ||
| 2002 | +} | ||
| 2003 | + | ||
| 1971 | /// With no project open, a PROJECT row must not fall back to a bare noun | 2004 | /// With no project open, a PROJECT row must not fall back to a bare noun |
| 1972 | /// ("Size"/"Rate"/"HDR") standing in the value slot -- it reads as a value | 2005 | /// ("Size"/"Rate"/"HDR") standing in the value slot -- it reads as a value |
| 1973 | /// while carrying none. This binary has no `TestAppContext` to actually | 2006 | /// while carrying none. This binary has no `TestAppContext` to actually |
crates/app/src/ui/stance.rsmodified+20 -2
| @@ -679,14 +679,32 @@ pub(crate) fn render( | |||
| 679 | return; | 679 | return; |
| 680 | } | 680 | } |
| 681 | // Same modal guard the legacy handler's rebinding/keys_open/ | 681 | // Same modal guard the legacy handler's rebinding/keys_open/ |
| 682 | - // export_open/exporting/colour/transform/speed/EQ/silence/mix/ | 682 | + // export_open/colour/transform/speed/EQ/silence/mix/ |
| 683 | // subtitle-style/menu chain (`render.rs`) amounts to, read as | 683 | // subtitle-style/menu chain (`render.rs`) amounts to, read as |
| 684 | // one bool instead of re-copied field by field: while a card, a | 684 | // one bool instead of re-copied field by field: while a card, a |
| 685 | // rebind capture, or a menu owns the keyboard, the darkroom | 685 | // rebind capture, or a menu owns the keyboard, the darkroom |
| 686 | // stance yields to it exactly as the legacy tree does. This is | 686 | // stance yields to it exactly as the legacy tree does. This is |
| 687 | // the fix for the stance's `Home`-inside-the-Colour-card | 687 | // the fix for the stance's `Home`-inside-the-Colour-card |
| 688 | // misfire. | 688 | // misfire. |
| 689 | - if this.rebinding.is_some() || this.overlaid() { | 689 | + // |
| 690 | + // `exporting()` alone is deliberately left out of this list | ||
| 691 | + // (`Player::card_open` is `modal()` minus it): a running export | ||
| 692 | + // draws no card of its own to own the keyboard for, and a key | ||
| 693 | + // caught here never reaches `enable()`/`act()` below, so a | ||
| 694 | + // refusal the oracle would have spoken (`ActionId::Settings` | ||
| 695 | + // among them) never got said -- the room went silent instead. | ||
| 696 | + // Letting an export-only moment fall through costs nothing this | ||
| 697 | + // guard exists for: every action the oracle would still refuse | ||
| 698 | + // during an export says so through `act()`'s own `Enable::No` | ||
| 699 | + // branch, and the six it leaves live (Theme, Fullscreen, | ||
| 700 | + // SubtitleStyle, CancelExport, ...) are exactly the ones meant | ||
| 701 | + // to keep working. | ||
| 702 | + if this.rebinding.is_some() | ||
| 703 | + || this.card_open() | ||
| 704 | + || this.context_menu.is_some() | ||
| 705 | + || this.library_menu.is_some() | ||
| 706 | + || this.picker.is_some() | ||
| 707 | + { | ||
| 690 | // Escape is every card's own way out (`Player::close_card`, | 708 | // Escape is every card's own way out (`Player::close_card`, |
| 691 | // the same list `overlaid`/`modal` read) -- blocking every | 709 | // the same list `overlaid`/`modal` read) -- blocking every |
| 692 | // key while a card is open must not also lock the card open. | 710 | // key while a card is open must not also lock the card open. |