From f4ba6132c936ab415223e3e3119a0666c90d544d 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 02:09:37 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(settings):=20the=20page=20st?= =?UTF-8?q?ops=20claiming=20storage=20it=20never=20uses?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Driving found the EDITOR header saying 'kept in ~/.config/edith' while those rows wrote nothing there, and Auto proxies persisting nowhere at all — it reverted to On every relaunch. The engine round-trip was already right; the gap was the window-level default, which now has its own config file beside subtitle-style. Each row's hint names its real door instead of one blanket claim. Settings also could not open during an export — the exporting card owns the modal slot — while the oracle and its test asserted it could. The oracle now agrees with what the user can observe. --- crates/app/src/main.rs | 6 +++- crates/app/src/oracle.rs | 17 +++++++---- crates/app/src/player/cards.rs | 7 +++-- crates/app/src/player/library.rs | 43 ++++++++++++++++++++++++++++ crates/app/src/tests/editing.rs | 9 ++++-- crates/app/src/tests/media.rs | 41 ++++++++++++++++++++++++++ crates/app/src/ui/settings_stance.rs | 8 +++--- crates/engine/src/playback.rs | 1 + 8 files changed, 116 insertions(+), 16 deletions(-) diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 6c818b4..2d0dfa3 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -799,6 +799,10 @@ fn main() { // The subtitle style the last session picked, same silence on a missing // or unreadable file. let (sub_family, sub_text) = load_subtitle_style(); + // The auto-proxies default the last session left the switch at, before + // 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(); // 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 @@ -873,7 +877,7 @@ fn main() { // What a session comes up at, so the first one opened is // pushed the values it already holds. proxies_on: false, - auto_proxies_on: true, + auto_proxies_on, // Only ever used with a timeline; 30 keeps the empty // timecode reading in frames rather than in NaN. fps: 30., diff --git a/crates/app/src/oracle.rs b/crates/app/src/oracle.rs index 4003610..47bc295 100644 --- a/crates/app/src/oracle.rs +++ b/crates/app/src/oracle.rs @@ -102,13 +102,20 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { // touching no timeline, live through an export the same way. // ...and the cue plate's own font and size: a reading preference like the // theme, never burned into an export, live the same way. - if action == ActionId::Theme - || action == ActionId::Fullscreen - || action == ActionId::SubtitleStyle - || action == ActionId::Settings - { + // + // Settings is not in this list, on purpose: it opens the same modal slot + // the exporting card owns (`Player::open_settings`, one card at a time), + // so a permission this oracle granted here would be a permission nobody + // could ever observe. It is refused below, with every other card. + if action == ActionId::Theme || action == ActionId::Fullscreen || action == ActionId::SubtitleStyle { return Enable::Yes; } + if action == ActionId::Settings { + return match ctx.exporting { + true => Enable::No("an export is running"), + false => Enable::Yes, + }; + } if action == ActionId::ShowActions { return match ctx.exporting { true => Enable::No("an export is running"), diff --git a/crates/app/src/player/cards.rs b/crates/app/src/player/cards.rs index 917ab11..f317622 100644 --- a/crates/app/src/player/cards.rs +++ b/crates/app/src/player/cards.rs @@ -855,9 +855,10 @@ impl Player { /// card it opens with no timeline required and nothing to refuse. /// Opens the settings page (PROJECT rows beside EDITOR rows, /// `ui::settings_stance`): the one door for "edit project and editor - /// settings" -- always answerable, since the oracle treats it like - /// `Theme` (`oracle.rs`), and refused only while an export is running, - /// same as every other card here. + /// settings" -- refused while an export is running, same as every other + /// card here, since the exporting card owns this same modal slot + /// (`oracle.rs` agrees: `ActionId::Settings` is `No` there too, for the + /// same reason). pub(crate) fn open_settings(&mut self, cx: &mut Context) { if self.exporting().is_some() { return; diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index eca5388..3286626 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -9,6 +9,40 @@ const AUTOSAVE_DEBOUNCE: Duration = Duration::from_secs(5); /// periodic half of "debounced + periodic". const AUTOSAVE_PERIOD: Duration = Duration::from_secs(60); +/// Where the auto-proxies *default* survives, beside the keybindings and the +/// theme, same corner-cut persistence as [`crate::subs::subtitle_style_path`]: +/// a torn write costs this one preference and nothing else. +/// +/// This is the window's own answer, not the project's: a project that was +/// saved with the switch set already carries its own line +/// ([`engine::edith::Document::auto_proxy`]) and always wins once one is +/// open ([`Player::install_project`]) -- this file is only ever read before +/// that, which is what makes it the difference between "the switch reverts to +/// On on every relaunch" and "the switch stayed how it was left". +pub(crate) fn auto_proxies_pref_path() -> PathBuf { + crate::keymap::Keymap::config_path().with_file_name("auto-proxies") +} + +/// `On` unless the file says `off`; missing, unreadable or garbled all read as +/// `On`, 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_auto_proxies_pref() -> bool { + match std::fs::read_to_string(auto_proxies_pref_path()) { + Ok(text) => text.trim() != "off", + Err(_) => true, + } +} + +/// Writes the pick whole, the way [`crate::ui::theme::save`] writes the +/// palette. +pub(crate) fn save_auto_proxies_pref(on: bool) -> std::io::Result<()> { + let path = auto_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 @@ -770,6 +804,15 @@ impl Player { false => "AUTO PROXIES OFF — no import makes one; Proxies on is what asks for them", }; eprintln!("{text}"); + // Kept for the next launch, not only the next project -- a flip made + // with nothing open, or a project never saved after it, used to + // vanish the moment the window closed ([`load_auto_proxies_pref`]). + if let Err(e) = save_auto_proxies_pref(on) { + let path = auto_proxies_pref_path(); + self.notify_user( + format!("AUTO PROXIES DEFAULT COULD NOT BE KEPT — {} — {e}", path.display()).into(), + ); + } self.notify_user(text.into()); cx.notify(); } diff --git a/crates/app/src/tests/editing.rs b/crates/app/src/tests/editing.rs index a5bb76e..e11801c 100644 --- a/crates/app/src/tests/editing.rs +++ b/crates/app/src/tests/editing.rs @@ -899,12 +899,15 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() { // word to the user's own config file, which is why it is one of the // actions besides the cancel that stay live here. Fullscreen is the // same kind of thing: the platform's own window toggle, touching no - // edit list either. + // edit list either. Settings is NOT among them, on purpose: it opens + // the same modal slot the exporting card is already standing in + // (`Player::open_settings`), so a permission granted here would be + // one nobody could ever act on -- driven and confirmed: both the `,` + // chord and the spine glyph leave the exporting card on screen. let allowed = action == ActionId::CancelExport || action == ActionId::Theme || action == ActionId::Fullscreen - || action == ActionId::SubtitleStyle - || action == ActionId::Settings; + || action == ActionId::SubtitleStyle; assert_eq!( whole(action, busy).yes(), allowed, diff --git a/crates/app/src/tests/media.rs b/crates/app/src/tests/media.rs index 8680495..0f79725 100644 --- a/crates/app/src/tests/media.rs +++ b/crates/app/src/tests/media.rs @@ -5,6 +5,7 @@ use super::*; use crate::subs::{ load_subtitle_style, save_subtitle_style, sub_line_h_for, subtitle_style_path, SUB_SIZE_RANGE, }; +use crate::player::library::{auto_proxies_pref_path, load_auto_proxies_pref, save_auto_proxies_pref}; use crate::ui::preview::{bgra_to_rgba, screenshot_path}; /// The import line's own state machine, driven the way a repaint drives @@ -951,6 +952,46 @@ fn the_subtitle_style_file_round_trips_or_falls_back_to_defaults() { std::fs::remove_dir_all(&dir).ok(); } +/// The auto-proxies default, round-tripped through a scratch config +/// directory the same way the subtitle style is above -- the door D1 wired +/// it through, so this is what the settings page header can now honestly +/// call the same claim it makes about Proxies: a project's own line always +/// beats this one once one is open ([`engine::edith::Document::auto_proxy`]), +/// but with nothing open (or nothing saved since the flip) this is what a +/// relaunch reads instead of the field's hardcoded `true`. +#[test] +fn the_auto_proxies_default_round_trips_through_its_own_config_file_or_falls_back_to_on() { + let dir = std::env::temp_dir().join(format!( + "edith-auto-proxies-pref-test-{}-{}", + std::process::id(), + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_nanos() + )); + std::fs::create_dir_all(&dir).unwrap(); + // Scoped to this test alone, the same guarantee the subtitle-style test + // above makes for the same env var. + unsafe { std::env::set_var("XDG_CONFIG_HOME", &dir) }; + + // Nothing written yet: On, the field's own long-standing default. + assert!(load_auto_proxies_pref(), "a missing file must read as On"); + + save_auto_proxies_pref(false).unwrap(); + assert!(!load_auto_proxies_pref(), "off must round-trip"); + + save_auto_proxies_pref(true).unwrap(); + assert!(load_auto_proxies_pref(), "on must round-trip too, not just off"); + + // Garbled bytes -- a stray edit, or a future dialect -- read as On rather + // than failing a startup on someone else's edit of the file. + std::fs::write(auto_proxies_pref_path(), "not on or off\n").unwrap(); + assert!(load_auto_proxies_pref(), "unreadable content must fall back to On"); + + unsafe { std::env::remove_var("XDG_CONFIG_HOME") }; + std::fs::remove_dir_all(&dir).ok(); +} + /// The cue's line height scales with its size, on the same ratio the defaults /// draw at -- a bigger plate wants more room per line, not letters growing /// inside an unchanged one. diff --git a/crates/app/src/ui/settings_stance.rs b/crates/app/src/ui/settings_stance.rs index 35c6531..f745279 100644 --- a/crates/app/src/ui/settings_stance.rs +++ b/crates/app/src/ui/settings_stance.rs @@ -180,7 +180,7 @@ fn editor_section(player: &Player, cx: &mut Context) -> impl IntoElement .flex() .flex_col() .gap(px(2.)) - .child(section_head("EDITOR · kept in ~/.config/edith")) + .child(section_head("EDITOR · this machine, this window")) .child(row( "settings-proxies", "Proxies", @@ -188,7 +188,7 @@ fn editor_section(player: &Player, cx: &mut Context) -> impl IntoElement true => format!("On{}", player.proxy_tail()), false => "Off".to_string(), }, - "cuts on small stand-ins of the big films; the sound and every export stay the film's own", + "cuts on small stand-ins of the big films; the sound and every export stay the film's own -- default kept in ~/.config/edith, the pick for an open project in its own .edith", player, cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_proxies(cx)), )) @@ -196,7 +196,7 @@ fn editor_section(player: &Player, cx: &mut Context) -> impl IntoElement "settings-auto-proxies", "Auto proxies", if player.auto_proxies_on { "On" } else { "Off" }, - "makes a stand-in for every big film as it is imported", + "makes a stand-in for every big film as it is imported -- default kept in ~/.config/edith, the pick for an open project in its own .edith", player, cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_auto_proxies(cx)), )) @@ -204,7 +204,7 @@ fn editor_section(player: &Player, cx: &mut Context) -> impl IntoElement "settings-subtitle-style", "Subtitle font", "Font…", - "the cue plate's own font and size", + "the cue plate's own font and size -- kept in ~/.config/edith, never in a project", player, cx.listener(|this, _: &ClickEvent, _, cx| this.open_subtitle_style(cx)), )) diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index 269ff7e..cf55f8d 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -4514,3 +4514,4 @@ mod tests { assert_eq!(next.index, first.index, "paused: same timeline position before and after"); } } +