From 6285a15cf3ad1057d8fa0cb275890b79d2c6e69e Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Fri, 16 Oct 2026 19:15:02 -0400 Subject: [PATCH] Default to Classic menus while preserving explicit preferences --- crates/horizon-client/src/options_ui.rs | 3 ++ crates/horizon-client/src/ui_theme.rs | 42 ++++++++++++++++++++----- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/crates/horizon-client/src/options_ui.rs b/crates/horizon-client/src/options_ui.rs index 38be29576..91b312b8f 100644 --- a/crates/horizon-client/src/options_ui.rs +++ b/crates/horizon-client/src/options_ui.rs @@ -2942,6 +2942,8 @@ mod tests { #[test] fn classic_video_settings_lead_back_to_horizon_menus() { + let previous_style = style(); + set_style(MenuStyle::Horizon); let s = Settings::default(); let mut ui = OptionsUi::default(); ui.push(Page::Video); @@ -2963,5 +2965,6 @@ mod tests { crate::options_horizon::SECTIONS[ui.section].name, "Interface" ); + set_style(previous_style); } } diff --git a/crates/horizon-client/src/ui_theme.rs b/crates/horizon-client/src/ui_theme.rs index 1c41add9d..6cda67a96 100644 --- a/crates/horizon-client/src/ui_theme.rs +++ b/crates/horizon-client/src/ui_theme.rs @@ -38,7 +38,7 @@ pub enum MenuStyle { /// Vanilla's screens, exactly as the parity harnesses expect them. Classic, } -static STYLE: AtomicU8 = AtomicU8::new(0); +static STYLE: AtomicU8 = AtomicU8::new(1); pub fn style() -> MenuStyle { if STYLE.load(Ordering::Relaxed) == 1 { MenuStyle::Classic @@ -55,16 +55,18 @@ pub fn set_style(s: MenuStyle) { /// Horizon-only preferences live in `horizon.txt` beside `options.txt`, so /// vanilla's options file stays exactly as vanilla writes it. pub fn load_preferences(dir: &Path) { - let text = std::fs::read_to_string(dir.join("horizon.txt")).unwrap_or_default(); - let classic = text.lines().any(|l| l.trim() == "menuStyle:classic"); + let saved = preference(dir, "menuStyle"); // HORIZON_MENU_STYLE=classic forces vanilla's screens (tests, harnesses). let forced = std::env::var("HORIZON_MENU_STYLE").ok(); - set_style(match forced.as_deref() { + set_style(preferred_style(saved.as_deref(), forced.as_deref())); +} +fn preferred_style(saved: Option<&str>, forced: Option<&str>) -> MenuStyle { + match forced { Some("classic") => MenuStyle::Classic, Some("horizon") => MenuStyle::Horizon, - _ if classic => MenuStyle::Classic, - _ => MenuStyle::Horizon, - }); + _ if saved == Some("horizon") => MenuStyle::Horizon, + _ => MenuStyle::Classic, + } } pub fn save_preferences(dir: &Path) { let value = match style() { @@ -1366,3 +1368,29 @@ pub const fn id(name: &str, index: u64) -> u64 { } h ^ index.wrapping_mul(0x9e37_79b9_7f4a_7c15) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn classic_is_the_default_and_explicit_menu_preferences_are_preserved() { + for saved in [None, Some("classic"), Some("invalid")] { + assert_eq!(preferred_style(saved, None), MenuStyle::Classic); + } + assert_eq!(preferred_style(Some("horizon"), None), MenuStyle::Horizon); + assert_eq!(preferred_style(None, Some("horizon")), MenuStyle::Horizon); + assert_eq!( + preferred_style(Some("classic"), Some("horizon")), + MenuStyle::Horizon + ); + assert_eq!( + preferred_style(Some("horizon"), Some("classic")), + MenuStyle::Classic + ); + assert_eq!( + preferred_style(Some("horizon"), Some("invalid")), + MenuStyle::Horizon + ); + } +}