diff --git a/bos-settings/src/ui/sidebar.rs b/bos-settings/src/ui/sidebar.rs index 70d3e09..bbc4fb1 100644 --- a/bos-settings/src/ui/sidebar.rs +++ b/bos-settings/src/ui/sidebar.rs @@ -55,7 +55,12 @@ pub const MAINTENANCE_ITEMS: &[SidebarItem] = &[ pub const ABOUT_ITEMS: &[SidebarItem] = &[item("about", "About", "help-about-symbolic")]; -pub fn build() -> (GBox, ListBox) { +/// `default_id` must match whatever page `window.rs` sets as the `Stack`'s +/// initial visible child — previously these were two independent hardcoded +/// "about" literals in different files with no link between them, so +/// changing one without the other silently desynced the sidebar highlight +/// from the actually-displayed page. +pub fn build(default_id: &str) -> (GBox, ListBox) { let vbox = GBox::new(Orientation::Vertical, 0); vbox.add_css_class("sidebar"); vbox.set_width_request(210); @@ -69,12 +74,11 @@ pub fn build() -> (GBox, ListBox) { append_section(&list, "Maintenance", MAINTENANCE_ITEMS); append_section(&list, None, ABOUT_ITEMS); - // Select About so it matches the default stack page. let mut i = 0; loop { match list.row_at_index(i) { None => break, - Some(row) if row.widget_name() == "about" => { + Some(row) if row.widget_name() == default_id => { list.select_row(Some(&row)); break; } diff --git a/bos-settings/src/ui/window.rs b/bos-settings/src/ui/window.rs index c74063e..67d62e0 100644 --- a/bos-settings/src/ui/window.rs +++ b/bos-settings/src/ui/window.rs @@ -4,6 +4,12 @@ use gtk4::{Application, ApplicationWindow, Orientation, Paned, Stack}; use super::sidebar; use super::views; +// About is a settings app's most GNOME-Settings-like landing page — +// identifies the machine, no config editor thrown at you first. Defined +// once here and threaded through to both the `Stack` and the sidebar's +// initial selection, so the two can't independently drift out of sync. +const DEFAULT_PAGE: &str = "about"; + pub fn build_ui(app: &Application) { let window = ApplicationWindow::builder() .application(app) @@ -19,7 +25,7 @@ pub fn build_ui(app: &Application) { hpaned.set_shrink_start_child(false); hpaned.set_resize_start_child(false); - let (sidebar_box, list) = sidebar::build(); + let (sidebar_box, list) = sidebar::build(DEFAULT_PAGE); let stack = Stack::new(); stack.set_hexpand(true); @@ -41,9 +47,7 @@ pub fn build_ui(app: &Application) { stack.add_named(&views::breadsearch::build(), Some("breadsearch")); stack.add_named(&views::hyprland::build(), Some("hyprland")); - // Default to About — a settings app's most GNOME-Settings-like landing - // page: identifies the machine, no config editor thrown at you first. - stack.set_visible_child_name("about"); + stack.set_visible_child_name(DEFAULT_PAGE); { let stack = stack.clone();