feat(slint): persist sidebar state, volume and nav placement
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
This commit is contained in:
6 files changed
+74
-1
No files matched your search
@@ -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<dyn std::error::Error>> {
|
||||
{
|
||||
let shell = window.global::<ShellState>();
|
||||
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<dyn std::error::Error>> {
|
||||
});
|
||||
});
|
||||
}
|
||||
// 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::<ShellState>();
|
||||
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::<NowPlayingState>().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();
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -11,6 +11,9 @@ export component QbzSlider inherits Rectangle {
|
||||
in property <int> maximum: 10;
|
||||
in property <int> 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 => {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user