feat(purchases): add Settings toggles + nav placement truth table (default OFF)

Slice 12/13. Two persisted UI prefs (show_purchases, nav_tb_purchases, both
default false) in UiPrefs; Show-Purchases toggle drives the show-purchases flag
the S11 nav gates on; 'Purchases in title bar' toggle (nav_tb_purchases, disabled
without a custom titlebar). Implements the source-of-truth section 5.8 placement
truth table: sidebar entry shown iff S && !(T && TB), header entry iff S && T && TB
(closing the S11 per-feature-gating gap) so flipping the toggle moves the Purchases
entry between sidebar and header 1:1 with Tauri. on_appearance_bool persistence +
startup reseed. cargo check -p qbz-slint reached exit-0. Per-machine prefs
(consistent with other Slint appearance prefs).

cc
This commit is contained in:
vicrodh committed 2026-06-24 17:41:43 -06:00
1 parent 965c898b10
commit 45be8763d7
5 files changed
+81 -4

No files matched your search

+26
View File
@@ -5154,6 +5154,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
window
.global::<AppearanceState>()
.set_intelligent_search(crate::ui_prefs::load().intelligent_search);
// Purchases opt-in nav visibility + title-bar placement (both default OFF).
// Seeded here from the persisted prefs so the sidebar / header entries
// reflect the user's choice on startup (the Slint equivalent of Tauri's
// rehydrate-after-login: ui_prefs is read once the session/window is up).
{
let prefs = crate::ui_prefs::load();
let appearance = window.global::<AppearanceState>();
appearance.set_show_purchases(prefs.show_purchases);
appearance.set_nav_tb_purchases(prefs.nav_tb_purchases);
}
window.global::<AppearanceState>().set_immersive_search_action_index(
crate::ui_prefs::immersive_search_action_index(
&crate::ui_prefs::load().immersive_search_action,
@@ -7218,6 +7228,22 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"tray-minimize-to-tray" => tray_settings::set_minimize_to_tray(value),
"tray-close-to-tray" => tray_settings::set_close_to_tray(value),
"tray-mac-hide-dock" => tray_settings::set_mac_hide_dock(value),
"show-purchases" => {
// Opt-in Purchases nav visibility (default OFF). The bound
// `AppearanceState.show-purchases` property was already flipped
// by the toggle, so the sidebar / header entries update live;
// here we only persist the choice so it survives restart.
let mut prefs = crate::ui_prefs::load();
prefs.show_purchases = value;
crate::ui_prefs::save(&prefs);
}
"nav-tb-purchases" => {
// Purchases title-bar placement (default OFF). Persist only —
// the live flag is already on `AppearanceState.nav-tb-purchases`.
let mut prefs = crate::ui_prefs::load();
prefs.nav_tb_purchases = value;
crate::ui_prefs::save(&prefs);
}
other => log::debug!("[qbz-slint] unhandled appearance-bool '{other}'"),
});
let theme_weak = window.as_weak();
+14
View File
@@ -244,6 +244,18 @@ pub struct UiPrefs {
/// per-machine app preference — your Discord client is per-machine.)
#[serde(default)]
pub discord_rpc_enabled: bool,
/// Show the opt-in "Purchases" navigation entry (sidebar / header). Default
/// OFF — the whole DRM-free Purchases feature is hidden until the user
/// enables it (mirrors Tauri `showPurchases`, default `false`). Re-seeded
/// into `AppearanceState.show-purchases` at startup; persisted on toggle.
#[serde(default)]
pub show_purchases: bool,
/// Place the Purchases nav entry in the custom title bar instead of the
/// sidebar. Default OFF (mirrors Tauri `purchasesInTitlebar`, default
/// `false`). Only meaningful when the custom title bar is shown; the toggle
/// is disabled in Settings when the title bar is hidden / system-native.
#[serde(default)]
pub nav_tb_purchases: bool,
/// Three-state sidebar: 0 open / 1 mini / 2 closed. Restored at startup.
#[serde(default)]
pub sidebar_state: i32,
@@ -395,6 +407,8 @@ impl Default for UiPrefs {
intelligent_search: default_intelligent_search(),
system_notifications: default_system_notifications(),
discord_rpc_enabled: false,
show_purchases: false,
nav_tb_purchases: false,
sidebar_state: 0,
nav_in_sidebar: default_nav_in_sidebar(),
volume: default_volume(),
@@ -607,7 +607,6 @@ export component AppearanceSettings inherits VerticalLayout {
}
}
SettingRow {
unsupported: true;
label: @tr("Show Purchases");
description: @tr("Show the Purchases section in the sidebar for browsing and downloading your purchased music");
QbzToggle {
@@ -618,6 +617,23 @@ export component AppearanceSettings inherits VerticalLayout {
}
}
}
// Purchases title-bar placement — moves the Purchases nav entry into the
// custom title bar instead of the sidebar (mirrors Tauri `purchasesInTitlebar`,
// default OFF). Disabled when the custom title bar is hidden or the system
// title bar is in use (no custom title bar to place it in).
SettingRow {
label: @tr("Purchases in title bar");
description: @tr("Place the Purchases entry in the custom title bar instead of the sidebar");
enabled: !root.tb-locked;
QbzToggle {
checked: AppearanceState.nav-tb-purchases;
enabled: !root.tb-locked;
toggled(v) => {
AppearanceState.nav-tb-purchases = v;
AppearanceState.appearance-bool("nav-tb-purchases", v);
}
}
}
Rectangle { height: 12px; }
Divider { }
+14 -2
View File
@@ -828,7 +828,14 @@ export component HeaderBar inherits Rectangle {
}
// Purchases — opt-in (default OFF). DIRECT tab (no dropdown), active
// for both the list + per-album detail views. HIDDEN while offline.
if AppearanceState.show-purchases && !OfflineState.offline: VerticalLayout {
// Titlebar-placement (§5.8 truth table): the title bar hosts the
// entry iff `S && T && TB` — only when the user enabled "Purchases
// in title bar" (`nav-tb-purchases`) AND the custom title bar is
// actually shown. Otherwise it stays in the sidebar (Sidebar.slint).
if AppearanceState.show-purchases && !OfflineState.offline
&& AppearanceState.nav-tb-purchases
&& !AppearanceState.hide-title-bar
&& !AppearanceState.use-system-title-bar: VerticalLayout {
alignment: center;
NavTab {
icon: @image-url("../assets/icons/shopping-bag.svg");
@@ -908,7 +915,12 @@ export component HeaderBar inherits Rectangle {
}
}
// Purchases — opt-in (default OFF). DIRECT button. HIDDEN offline.
if AppearanceState.show-purchases && !OfflineState.offline: VerticalLayout {
// Titlebar-placement (§5.8 truth table): shown in the header iff
// `S && T && TB` — same gate as the full-nav tab above.
if AppearanceState.show-purchases && !OfflineState.offline
&& AppearanceState.nav-tb-purchases
&& !AppearanceState.hide-title-bar
&& !AppearanceState.use-system-title-bar: VerticalLayout {
alignment: center;
CompactDirectBtn {
icon: @image-url("../assets/icons/shopping-bag.svg");
+10 -1
View File
@@ -757,7 +757,16 @@ export component Sidebar inherits Rectangle {
// destination (no tab dropdown). HIDDEN entirely while offline (the
// surface needs the Qobuz session). Active for both the list view
// and the per-album detail view (§5.3 / §8.6 gating).
if AppearanceState.show-purchases && !OfflineState.offline: SidebarDirectRow {
// Titlebar-placement (§5.8 truth table): the sidebar hosts the entry
// iff `S && !(T && TB)` — when the user enables "Purchases in title
// bar" (`nav-tb-purchases`) AND the custom title bar is actually
// shown, the entry MOVES to the header (HeaderBar.slint) and is
// hidden here. `TB = showTitleBar` = custom titlebar present
// (mirrors AppearanceSettings `tb-locked`, inverted).
if AppearanceState.show-purchases && !OfflineState.offline
&& !(AppearanceState.nav-tb-purchases
&& !AppearanceState.hide-title-bar
&& !AppearanceState.use-system-title-bar): SidebarDirectRow {
icon: @image-url("../assets/icons/shopping-bag.svg");
label: @tr("Purchases");
active: NavState.view == ContentView.purchases