From 2c9104e1e375c79590faecf86df1394c46bb1d62 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Mon, 22 Jun 2026 23:57:08 -0600 Subject: [PATCH] feat(slint): persist sidebar state, volume and nav placement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Restore across restarts: the three-state sidebar (open/mini/closed) and the section-nav placement (sidebar vs header) seed from ui_prefs before the shell renders and persist via new ShellState callbacks; the player volume persists on slider release only (a new QbzSlider `released` callback + NowPlayingState.persist-volume — no ui_prefs write per drag tick) and is reapplied to the player on session entry. cc --- crates/qbz-slint/src/main.rs | 34 +++++++++++++++++++ crates/qbz-slint/src/ui_prefs.rs | 20 +++++++++++ .../qbz-slint/ui/primitives/QbzSlider.slint | 6 ++++ .../ui/settings/AppearanceSettings.slint | 1 + crates/qbz-slint/ui/shell/PlayerBar.slint | 7 ++++ crates/qbz-slint/ui/state.slint | 7 +++- 6 files changed, 74 insertions(+), 1 deletion(-) diff --git a/crates/qbz-slint/src/main.rs b/crates/qbz-slint/src/main.rs index c15445e79..6c5d4095c 100644 --- a/crates/qbz-slint/src/main.rs +++ b/crates/qbz-slint/src/main.rs @@ -181,6 +181,15 @@ fn init_shell_for_user( // when the user hasn't opted in. discord_rpc::init(runtime, &tokio::runtime::Handle::current()); + // Restore the persisted player volume so audio starts at the saved level + // (the poll loop then mirrors it onto NowPlayingState for the slider). + playback::set_volume( + runtime.clone(), + weak.clone(), + tokio::runtime::Handle::current(), + crate::ui_prefs::load().volume, + ); + // Bind "My QBZ" nav branding (custom label + icon) to this user // (per-user myqbz_branding.json). Seeded into MyQbzBrandingState by the // caller so the sidebar row + Settings row reflect the persisted values. @@ -4614,6 +4623,10 @@ fn main() -> Result<(), Box> { { let shell = window.global::(); shell.set_npb_mode(restored_npb); + // Restore the persisted sidebar state (0 open / 1 mini / 2 closed) + + // section-nav placement before the shell renders. + shell.set_sidebar_state(restored_prefs.sidebar_state); + shell.set_nav_in_sidebar(restored_prefs.nav_in_sidebar); // Large dock toggles — restore the persisted visualizer state + spectrum // choice (default ON / Bars) before the shell renders. shell.set_large_visualizer_on(restored_prefs.large_visualizer); @@ -8746,6 +8759,27 @@ fn main() -> Result<(), Box> { }); }); } + // Persist sidebar state / section-nav placement / volume (drag-end only) + // to ui_prefs. These callbacks just touch the prefs file — no runtime. + { + let shell = window.global::(); + shell.on_persist_sidebar_state(|state| { + let mut prefs = crate::ui_prefs::load(); + prefs.sidebar_state = state; + crate::ui_prefs::save(&prefs); + }); + shell.on_persist_nav(|enabled| { + let mut prefs = crate::ui_prefs::load(); + prefs.nav_in_sidebar = enabled; + crate::ui_prefs::save(&prefs); + }); + window.global::().on_persist_volume(|fraction| { + let mut prefs = crate::ui_prefs::load(); + prefs.volume = fraction.clamp(0.0, 1.0); + crate::ui_prefs::save(&prefs); + }); + } + { let runtime = app_runtime.clone(); let weak = window.as_weak(); diff --git a/crates/qbz-slint/src/ui_prefs.rs b/crates/qbz-slint/src/ui_prefs.rs index da6096a57..5ddb12d8f 100644 --- a/crates/qbz-slint/src/ui_prefs.rs +++ b/crates/qbz-slint/src/ui_prefs.rs @@ -86,6 +86,14 @@ fn default_system_notifications() -> bool { true } +fn default_nav_in_sidebar() -> bool { + true +} + +fn default_volume() -> f32 { + 1.0 +} + /// Miniplayer default-view select index -> persisted key (mirrors the /// miniplayer's own reader in `miniplayer.rs`). 0 = "remember". pub fn mini_default_view_for_index(index: i32) -> &'static str { @@ -173,6 +181,15 @@ pub struct UiPrefs { /// per-machine app preference — your Discord client is per-machine.) #[serde(default)] pub discord_rpc_enabled: bool, + /// Three-state sidebar: 0 open / 1 mini / 2 closed. Restored at startup. + #[serde(default)] + pub sidebar_state: i32, + /// Section navigation lives in the sidebar (vs the header). Default true. + #[serde(default = "default_nav_in_sidebar")] + pub nav_in_sidebar: bool, + /// Player volume, 0.0..=1.0. Restored at startup. Default full. + #[serde(default = "default_volume")] + pub volume: f32, /// Immersive in-view search action: `"disabled"` | `"replace"` | `"next"` | /// `"queue"`. Doubles as the enable switch (`"disabled"` keeps the field /// inert). See [`DEFAULT_IMMERSIVE_SEARCH_ACTION`]. @@ -281,6 +298,9 @@ impl Default for UiPrefs { intelligent_search: default_intelligent_search(), system_notifications: default_system_notifications(), discord_rpc_enabled: false, + sidebar_state: 0, + nav_in_sidebar: default_nav_in_sidebar(), + volume: default_volume(), immersive_search_action: default_immersive_search_action(), immersive_default_view: default_immersive_default_view(), immersive_last_view_mode: 0, diff --git a/crates/qbz-slint/ui/primitives/QbzSlider.slint b/crates/qbz-slint/ui/primitives/QbzSlider.slint index 58cdcba0c..bf03ed613 100644 --- a/crates/qbz-slint/ui/primitives/QbzSlider.slint +++ b/crates/qbz-slint/ui/primitives/QbzSlider.slint @@ -11,6 +11,9 @@ export component QbzSlider inherits Rectangle { in property maximum: 10; in property value: 0; callback changed(int); + // Fired once on pointer release (drag end) — for callers that want to + // commit/persist only the final value, not every intermediate `changed`. + callback released(int); width: 200px; height: 22px; @@ -72,6 +75,9 @@ export component QbzSlider inherits Rectangle { && root.value-from-x(self.mouse-x) != root.value) { root.changed(root.value-from-x(self.mouse-x)); } + if (e.kind == PointerEventKind.up) { + root.released(root.value); + } } // Continuous drag while held. moved => { diff --git a/crates/qbz-slint/ui/settings/AppearanceSettings.slint b/crates/qbz-slint/ui/settings/AppearanceSettings.slint index 6708dffaa..a5ded67fb 100644 --- a/crates/qbz-slint/ui/settings/AppearanceSettings.slint +++ b/crates/qbz-slint/ui/settings/AppearanceSettings.slint @@ -322,6 +322,7 @@ export component AppearanceSettings inherits VerticalLayout { checked: ShellState.nav-in-sidebar; toggled(v) => { ShellState.nav-in-sidebar = v; + ShellState.persist-nav(v); } } } diff --git a/crates/qbz-slint/ui/shell/PlayerBar.slint b/crates/qbz-slint/ui/shell/PlayerBar.slint index e3506c21c..7d233f7d7 100644 --- a/crates/qbz-slint/ui/shell/PlayerBar.slint +++ b/crates/qbz-slint/ui/shell/PlayerBar.slint @@ -847,6 +847,13 @@ export component PlayerBar inherits Rectangle { NowPlayingState.set-volume(v / 100.0); } } + // Persist only the final value on drag-end (avoids a + // ui_prefs write per drag tick). + released(v) => { + if (!root.vol-locked) { + NowPlayingState.persist-volume(v / 100.0); + } + } } } if AppearanceState.show-volume-steppers: VerticalLayout { diff --git a/crates/qbz-slint/ui/state.slint b/crates/qbz-slint/ui/state.slint index 670b2a6fb..04b059aa6 100644 --- a/crates/qbz-slint/ui/state.slint +++ b/crates/qbz-slint/ui/state.slint @@ -3403,11 +3403,15 @@ export global ShellState { // reverts LIVE to New (0). The persisted ui_prefs key stays "large", so a // later relaunch (sidebar defaults open) restores Large — the revert is a // compatibility fallback, not a preference change. + // Persist the sidebar state / nav placement (wired to ui_prefs in Rust). + callback persist-sidebar-state(int); + callback persist-nav(bool); public function cycle-sidebar() { root.sidebar-state = Math.mod(root.sidebar-state + 1, 3); if (root.sidebar-state != 0 && root.npb-mode == 3) { root.npb-mode = 0; } + root.persist-sidebar-state(root.sidebar-state); } // Right-side panels — independent now: Queue and Lyrics can BOTH be open // at once, stacked vertically in a shared right column (Feishin-style). Each @@ -3708,7 +3712,8 @@ export global NowPlayingState { callback next(); callback previous(); callback seek(float); // 0..1 - callback set-volume(float); // 0..1 + callback set-volume(float); // 0..1 — live (fires on every drag tick) + callback persist-volume(float); // 0..1 — drag-end only, persists to ui_prefs callback toggle-mute(); callback toggle-shuffle(); callback cycle-repeat();