forge
Explore
Log in

Don't you dare go Hollow

The page stops claiming storage it never uses

Browse files at this commit

f4ba6132c936ab415223e3e3119a0666c90d544dAhmet Kaan GümüşParent: a2e172e
  • fix
    • the page stops claiming storage it never uses
Show full message
🐛 fix(settings): the page stops claiming storage it never uses

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.rsmodified+5 -1
@@ -799,6 +799,10 @@ fn main() {
799 // The subtitle style the last session picked, same silence on a missing799 // The subtitle style the last session picked, same silence on a missing
800 // or unreadable file.800 // or unreadable file.
801 let (sub_family, sub_text) = load_subtitle_style();801 let (sub_family, sub_text) = load_subtitle_style();
802+ // The auto-proxies default the last session left the switch at, before
803+ // any project's own line ([`engine::edith::Document::auto_proxy`])
804+ // overrides it the moment one opens.
805+ let auto_proxies_on = player::library::load_auto_proxies_pref();
802 // Nothing named on the command line is read here. The first file makes the806 // Nothing named on the command line is read here. The first file makes the
803 // timeline -- a `.edith` restores a whole one, anything else *is* one --807 // timeline -- a `.edith` restores a whole one, anything else *is* one --
804 // and the rest are imports like any other: rows in the library, dragged808 // and the rest are imports like any other: rows in the library, dragged
@@ -873,7 +877,7 @@ fn main() {
873 // What a session comes up at, so the first one opened is877 // What a session comes up at, so the first one opened is
874 // pushed the values it already holds.878 // pushed the values it already holds.
875 proxies_on: false,879 proxies_on: false,
876- auto_proxies_on: true,880+ auto_proxies_on,
877 // Only ever used with a timeline; 30 keeps the empty881 // Only ever used with a timeline; 30 keeps the empty
878 // timecode reading in frames rather than in NaN.882 // timecode reading in frames rather than in NaN.
879 fps: 30.,883 fps: 30.,
crates/app/src/oracle.rsmodified+12 -5
@@ -102,13 +102,20 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable {
102 // touching no timeline, live through an export the same way.102 // touching no timeline, live through an export the same way.
103 // ...and the cue plate's own font and size: a reading preference like the103 // ...and the cue plate's own font and size: a reading preference like the
104 // theme, never burned into an export, live the same way.104 // theme, never burned into an export, live the same way.
105- if action == ActionId::Theme105+ //
106- || action == ActionId::Fullscreen106+ // Settings is not in this list, on purpose: it opens the same modal slot
107- || action == ActionId::SubtitleStyle107+ // the exporting card owns (`Player::open_settings`, one card at a time),
108- || action == ActionId::Settings108+ // so a permission this oracle granted here would be a permission nobody
109- {109+ // could ever observe. It is refused below, with every other card.
110+ if action == ActionId::Theme || action == ActionId::Fullscreen || action == ActionId::SubtitleStyle {
110 return Enable::Yes;111 return Enable::Yes;
111 }112 }
113+ if action == ActionId::Settings {
114+ return match ctx.exporting {
115+ true => Enable::No("an export is running"),
116+ false => Enable::Yes,
117+ };
118+ }
112 if action == ActionId::ShowActions {119 if action == ActionId::ShowActions {
113 return match ctx.exporting {120 return match ctx.exporting {
114 true => Enable::No("an export is running"),121 true => Enable::No("an export is running"),
crates/app/src/player/cards.rsmodified+4 -3
@@ -855,9 +855,10 @@ impl Player {
855 /// card it opens with no timeline required and nothing to refuse.855 /// card it opens with no timeline required and nothing to refuse.
856 /// Opens the settings page (PROJECT rows beside EDITOR rows,856 /// Opens the settings page (PROJECT rows beside EDITOR rows,
857 /// `ui::settings_stance`): the one door for "edit project and editor857 /// `ui::settings_stance`): the one door for "edit project and editor
858- /// settings" -- always answerable, since the oracle treats it like858+ /// settings" -- refused while an export is running, same as every other
859- /// `Theme` (`oracle.rs`), and refused only while an export is running,859+ /// card here, since the exporting card owns this same modal slot
860- /// same as every other card here.860+ /// (`oracle.rs` agrees: `ActionId::Settings` is `No` there too, for the
861+ /// same reason).
861 pub(crate) fn open_settings(&mut self, cx: &mut Context<Self>) {862 pub(crate) fn open_settings(&mut self, cx: &mut Context<Self>) {
862 if self.exporting().is_some() {863 if self.exporting().is_some() {
863 return;864 return;
crates/app/src/player/library.rsmodified+43 -0
@@ -9,6 +9,40 @@ const AUTOSAVE_DEBOUNCE: Duration = Duration::from_secs(5);
9 /// periodic half of "debounced + periodic".9 /// periodic half of "debounced + periodic".
10 const AUTOSAVE_PERIOD: Duration = Duration::from_secs(60);10 const AUTOSAVE_PERIOD: Duration = Duration::from_secs(60);
11 11
12+/// Where the auto-proxies *default* survives, beside the keybindings and the
13+/// theme, same corner-cut persistence as [`crate::subs::subtitle_style_path`]:
14+/// a torn write costs this one preference and nothing else.
15+///
16+/// This is the window's own answer, not the project's: a project that was
17+/// saved with the switch set already carries its own line
18+/// ([`engine::edith::Document::auto_proxy`]) and always wins once one is
19+/// open ([`Player::install_project`]) -- this file is only ever read before
20+/// that, which is what makes it the difference between "the switch reverts to
21+/// On on every relaunch" and "the switch stayed how it was left".
22+pub(crate) fn auto_proxies_pref_path() -> PathBuf {
23+ crate::keymap::Keymap::config_path().with_file_name("auto-proxies")
24+}
25+
26+/// `On` unless the file says `off`; missing, unreadable or garbled all read as
27+/// `On`, the same default the field has always started at -- a preference
28+/// file is not the user's work, so a bad one is worth no message at startup.
29+pub(crate) fn load_auto_proxies_pref() -> bool {
30+ match std::fs::read_to_string(auto_proxies_pref_path()) {
31+ Ok(text) => text.trim() != "off",
32+ Err(_) => true,
33+ }
34+}
35+
36+/// Writes the pick whole, the way [`crate::ui::theme::save`] writes the
37+/// palette.
38+pub(crate) fn save_auto_proxies_pref(on: bool) -> std::io::Result<()> {
39+ let path = auto_proxies_pref_path();
40+ if let Some(dir) = path.parent() {
41+ std::fs::create_dir_all(dir)?;
42+ }
43+ std::fs::write(path, if on { "on\n" } else { "off\n" })
44+}
45+
12 impl Player {46 impl Player {
13 /// The one way a library row reaches the timeline: the Add button and a row47 /// The one way a library row reaches the timeline: the Add button and a row
14 /// dragged onto a lane both come here, so there is a single answer to what48 /// dragged onto a lane both come here, so there is a single answer to what
@@ -770,6 +804,15 @@ impl Player {
770 false => "AUTO PROXIES OFF — no import makes one; Proxies on is what asks for them",804 false => "AUTO PROXIES OFF — no import makes one; Proxies on is what asks for them",
771 };805 };
772 eprintln!("{text}");806 eprintln!("{text}");
807+ // Kept for the next launch, not only the next project -- a flip made
808+ // with nothing open, or a project never saved after it, used to
809+ // vanish the moment the window closed ([`load_auto_proxies_pref`]).
810+ if let Err(e) = save_auto_proxies_pref(on) {
811+ let path = auto_proxies_pref_path();
812+ self.notify_user(
813+ format!("AUTO PROXIES DEFAULT COULD NOT BE KEPT — {} — {e}", path.display()).into(),
814+ );
815+ }
773 self.notify_user(text.into());816 self.notify_user(text.into());
774 cx.notify();817 cx.notify();
775 }818 }
crates/app/src/tests/editing.rsmodified+6 -3
@@ -899,12 +899,15 @@ fn the_clip_menu_dims_what_the_playhead_is_not_on_and_stays_in_the_window() {
899 // word to the user's own config file, which is why it is one of the899 // word to the user's own config file, which is why it is one of the
900 // actions besides the cancel that stay live here. Fullscreen is the900 // actions besides the cancel that stay live here. Fullscreen is the
901 // same kind of thing: the platform's own window toggle, touching no901 // same kind of thing: the platform's own window toggle, touching no
902- // edit list either.902+ // edit list either. Settings is NOT among them, on purpose: it opens
903+ // the same modal slot the exporting card is already standing in
904+ // (`Player::open_settings`), so a permission granted here would be
905+ // one nobody could ever act on -- driven and confirmed: both the `,`
906+ // chord and the spine glyph leave the exporting card on screen.
903 let allowed = action == ActionId::CancelExport907 let allowed = action == ActionId::CancelExport
904 || action == ActionId::Theme908 || action == ActionId::Theme
905 || action == ActionId::Fullscreen909 || action == ActionId::Fullscreen
906- || action == ActionId::SubtitleStyle910+ || action == ActionId::SubtitleStyle;
907- || action == ActionId::Settings;
908 assert_eq!(911 assert_eq!(
909 whole(action, busy).yes(),912 whole(action, busy).yes(),
910 allowed,913 allowed,
crates/app/src/tests/media.rsmodified+41 -0
@@ -5,6 +5,7 @@ use super::*;
5 use crate::subs::{5 use crate::subs::{
6 load_subtitle_style, save_subtitle_style, sub_line_h_for, subtitle_style_path, SUB_SIZE_RANGE,6 load_subtitle_style, save_subtitle_style, sub_line_h_for, subtitle_style_path, SUB_SIZE_RANGE,
7 };7 };
8+use crate::player::library::{auto_proxies_pref_path, load_auto_proxies_pref, save_auto_proxies_pref};
8 use crate::ui::preview::{bgra_to_rgba, screenshot_path};9 use crate::ui::preview::{bgra_to_rgba, screenshot_path};
9 10
10 /// The import line's own state machine, driven the way a repaint drives11 /// 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() {
951 std::fs::remove_dir_all(&dir).ok();952 std::fs::remove_dir_all(&dir).ok();
952 }953 }
953 954
955+/// The auto-proxies default, round-tripped through a scratch config
956+/// directory the same way the subtitle style is above -- the door D1 wired
957+/// it through, so this is what the settings page header can now honestly
958+/// call the same claim it makes about Proxies: a project's own line always
959+/// beats this one once one is open ([`engine::edith::Document::auto_proxy`]),
960+/// but with nothing open (or nothing saved since the flip) this is what a
961+/// relaunch reads instead of the field's hardcoded `true`.
962+#[test]
963+fn the_auto_proxies_default_round_trips_through_its_own_config_file_or_falls_back_to_on() {
964+ let dir = std::env::temp_dir().join(format!(
965+ "edith-auto-proxies-pref-test-{}-{}",
966+ std::process::id(),
967+ std::time::SystemTime::now()
968+ .duration_since(std::time::UNIX_EPOCH)
969+ .unwrap()
970+ .as_nanos()
971+ ));
972+ std::fs::create_dir_all(&dir).unwrap();
973+ // Scoped to this test alone, the same guarantee the subtitle-style test
974+ // above makes for the same env var.
975+ unsafe { std::env::set_var("XDG_CONFIG_HOME", &dir) };
976+
977+ // Nothing written yet: On, the field's own long-standing default.
978+ assert!(load_auto_proxies_pref(), "a missing file must read as On");
979+
980+ save_auto_proxies_pref(false).unwrap();
981+ assert!(!load_auto_proxies_pref(), "off must round-trip");
982+
983+ save_auto_proxies_pref(true).unwrap();
984+ assert!(load_auto_proxies_pref(), "on must round-trip too, not just off");
985+
986+ // Garbled bytes -- a stray edit, or a future dialect -- read as On rather
987+ // than failing a startup on someone else's edit of the file.
988+ std::fs::write(auto_proxies_pref_path(), "not on or off\n").unwrap();
989+ assert!(load_auto_proxies_pref(), "unreadable content must fall back to On");
990+
991+ unsafe { std::env::remove_var("XDG_CONFIG_HOME") };
992+ std::fs::remove_dir_all(&dir).ok();
993+}
994+
954 /// The cue's line height scales with its size, on the same ratio the defaults995 /// The cue's line height scales with its size, on the same ratio the defaults
955 /// draw at -- a bigger plate wants more room per line, not letters growing996 /// draw at -- a bigger plate wants more room per line, not letters growing
956 /// inside an unchanged one.997 /// inside an unchanged one.
crates/app/src/ui/settings_stance.rsmodified+4 -4
@@ -180,7 +180,7 @@ fn editor_section(player: &Player, cx: &mut Context<Player>) -> impl IntoElement
180 .flex()180 .flex()
181 .flex_col()181 .flex_col()
182 .gap(px(2.))182 .gap(px(2.))
183- .child(section_head("EDITOR · kept in ~/.config/edith"))183+ .child(section_head("EDITOR · this machine, this window"))
184 .child(row(184 .child(row(
185 "settings-proxies",185 "settings-proxies",
186 "Proxies",186 "Proxies",
@@ -188,7 +188,7 @@ fn editor_section(player: &Player, cx: &mut Context<Player>) -> impl IntoElement
188 true => format!("On{}", player.proxy_tail()),188 true => format!("On{}", player.proxy_tail()),
189 false => "Off".to_string(),189 false => "Off".to_string(),
190 },190 },
191- "cuts on small stand-ins of the big films; the sound and every export stay the film's own",191+ "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",
192 player,192 player,
193 cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_proxies(cx)),193 cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_proxies(cx)),
194 ))194 ))
@@ -196,7 +196,7 @@ fn editor_section(player: &Player, cx: &mut Context<Player>) -> impl IntoElement
196 "settings-auto-proxies",196 "settings-auto-proxies",
197 "Auto proxies",197 "Auto proxies",
198 if player.auto_proxies_on { "On" } else { "Off" },198 if player.auto_proxies_on { "On" } else { "Off" },
199- "makes a stand-in for every big film as it is imported",199+ "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",
200 player,200 player,
201 cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_auto_proxies(cx)),201 cx.listener(|this, _: &ClickEvent, _, cx| this.toggle_auto_proxies(cx)),
202 ))202 ))
@@ -204,7 +204,7 @@ fn editor_section(player: &Player, cx: &mut Context<Player>) -> impl IntoElement
204 "settings-subtitle-style",204 "settings-subtitle-style",
205 "Subtitle font",205 "Subtitle font",
206 "Font…",206 "Font…",
207- "the cue plate's own font and size",207+ "the cue plate's own font and size -- kept in ~/.config/edith, never in a project",
208 player,208 player,
209 cx.listener(|this, _: &ClickEvent, _, cx| this.open_subtitle_style(cx)),209 cx.listener(|this, _: &ClickEvent, _, cx| this.open_subtitle_style(cx)),
210 ))210 ))
crates/engine/src/playback.rsmodified+1 -0
@@ -4514,3 +4514,4 @@ mod tests {
4514 assert_eq!(next.index, first.index, "paused: same timeline position before and after");4514 assert_eq!(next.index, first.index, "paused: same timeline position before and after");
4515 }4515 }
4516 }4516 }
4517+