From 270850e3527e858e829576793b45be3ef79e68a4 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Sat, 27 Jun 2026 14:11:25 -0600 Subject: [PATCH] feat(settings): MusicBrainz opt-out + gate MB-dependent sections MusicBrainz was hardcoded ON in the core client with no toggle, no persistence and no startup wiring, so it could never be turned off. Add a persisted opt-out (default ON: ui_prefs.musicbrainz_enabled + Settings>Integrations toggle) that seeds the core client at startup and flips it live via handle_bool. Gate the MB-dependent surfaces when off: the artist Network/Scene sidebar marks itself unavailable and opens on the MB-independent Magazine tab; the playlist "Suggest songs" CTA hides and activate() early-outs; and the musician page tolerates a disabled/failed MB resolve, falling through to the Qobuz fallback instead of rendering blank. cc --- crates/qbz-core/src/core.rs | 19 ++++++++++++++----- crates/qbz-ui/ui/playlist/PlaylistView.slint | 5 +++-- .../ui/settings/IntegrationsSettings.slint | 19 +++++++++++++++++++ crates/qbz-ui/ui/state.slint | 5 +++++ crates/qbz/src/artist.rs | 15 +++++++++++---- crates/qbz/src/discover_prefs.rs | 6 ++++++ crates/qbz/src/main.rs | 12 ++++++++++++ crates/qbz/src/playlist_suggestions.rs | 16 +++++++++++++++- crates/qbz/src/settings.rs | 11 +++++++++++ crates/qbz/src/ui_prefs.rs | 11 +++++++++++ 10 files changed, 107 insertions(+), 12 deletions(-) diff --git a/crates/qbz-core/src/core.rs b/crates/qbz-core/src/core.rs index 39aa64adb..31ff466de 100644 --- a/crates/qbz-core/src/core.rs +++ b/crates/qbz-core/src/core.rs @@ -2571,11 +2571,20 @@ impl QbzCore { name: &str, role: &str, ) -> Result { - let resolved_artist = self - .musicbrainz - .resolve_artist(name) - .await - .map_err(|e| CoreError::Internal(e.to_string()))?; + // MusicBrainz opt-out / unavailable: a disabled or failed resolve is NOT + // fatal here — fall through to the Qobuz exact-name / appears-on fallback + // below so the musician page still degrades cleanly when MB is off. (Was + // `?`, which propagated the disabled-client Err before the Qobuz fallback + // and left the musician page blank/stuck when MB is disabled.) + let resolved_artist = match self.musicbrainz.resolve_artist(name).await { + Ok(found) => found, + Err(e) => { + log::debug!( + "musicbrainz_resolve_musician: MB resolve unavailable for {name:?}: {e}" + ); + None + } + }; let normalized_target = name.trim().to_lowercase(); let artist_results = self.search_artists(name, 10, 0, None).await?; diff --git a/crates/qbz-ui/ui/playlist/PlaylistView.slint b/crates/qbz-ui/ui/playlist/PlaylistView.slint index ede9be989..fa7ce1717 100644 --- a/crates/qbz-ui/ui/playlist/PlaylistView.slint +++ b/crates/qbz-ui/ui/playlist/PlaylistView.slint @@ -6,7 +6,7 @@ import { Theme } from "../foundation/semantic-colors.slint"; import { Typography } from "../foundation/typography.slint"; import { Radius } from "../foundation/radius.slint"; -import { PlaylistState, PlaylistActions, DragState, NavState, OfflineState, BulkAction } from "../state.slint"; +import { PlaylistState, PlaylistActions, DragState, NavState, OfflineState, BulkAction, SettingsState } from "../state.slint"; import { PlaylistSuggestionsState, PlaylistSuggestionsActions, PlaylistSuggestionRow, TooltipState } from "../state.slint"; import { QbzIcon } from "../primitives/QbzIcon.slint"; import { CircleAction } from "../primitives/CircleAction.slint"; @@ -680,7 +680,8 @@ export component PlaylistView inherits Rectangle { // auto-computes — large playlists shouldn't pay for it). if PlaylistState.is-owner && !PlaylistState.is-local && PlaylistState.track-count > 0 - && PlaylistState.track-count < 2000: VerticalLayout { + && PlaylistState.track-count < 2000 + && SettingsState.musicbrainz-enabled: VerticalLayout { horizontal-stretch: 0; alignment: center; CircleAction { diff --git a/crates/qbz-ui/ui/settings/IntegrationsSettings.slint b/crates/qbz-ui/ui/settings/IntegrationsSettings.slint index 1159d1a19..bf57b96cd 100644 --- a/crates/qbz-ui/ui/settings/IntegrationsSettings.slint +++ b/crates/qbz-ui/ui/settings/IntegrationsSettings.slint @@ -86,6 +86,25 @@ export component IntegrationsSettings inherits VerticalLayout { } } + // =================================================================== + // METADATA — MusicBrainz opt-out (default on). Enriches artist pages + // (relationships, origin/scene) and playlist song suggestions. No telemetry. + // =================================================================== + Rectangle { height: 12px; } + GroupHeader { text: @tr("METADATA"); } + Rectangle { height: 4px; } + SettingRow { + label: @tr("MusicBrainz"); + description: @tr("Enable artist relationships and enhanced metadata from MusicBrainz. No telemetry — it only matches releases to enrich artist pages and playlist song suggestions. Turn off to disable those sections."); + QbzToggle { + checked: SettingsState.musicbrainz-enabled; + toggled(v) => { + SettingsState.musicbrainz-enabled = v; + root.settings-bool("musicbrainz", v); + } + } + } + // =================================================================== // SCROBBLERS — master header: title + master toggle + collapse chevron. // Body renders only when `enabled && !ui-collapsed`. diff --git a/crates/qbz-ui/ui/state.slint b/crates/qbz-ui/ui/state.slint index ee8aa12a4..42b1bd7fd 100644 --- a/crates/qbz-ui/ui/state.slint +++ b/crates/qbz-ui/ui/state.slint @@ -2723,6 +2723,11 @@ export global SettingsState { // Discover — opt-out: show the external "Recommendations" tab. Default on. // Seeded from persisted discover prefs at session start (crate::discover_prefs). in-out property show-recommendations: true; + // MusicBrainz metadata — opt-out (default on). Drives the core client's + // enabled flag, the artist Network/Scene sidebar (mb-available), and the + // playlist Suggested-Songs CTA. Seeded from ui_prefs at session start + // (crate::discover_prefs::seed); persisted via the "musicbrainz" key. + in-out property musicbrainz-enabled: true; in-out property streaming-only: false; // Volume normalization (loudness leveling). Applied in the shared player // and bypassed automatically when bit-perfect is active. Surfaced in the diff --git a/crates/qbz/src/artist.rs b/crates/qbz/src/artist.rs index 9262e367a..fbdbbb73b 100644 --- a/crates/qbz/src/artist.rs +++ b/crates/qbz/src/artist.rs @@ -20,7 +20,7 @@ use crate::home::CardData; use crate::{ AlbumCardItem, TrackItem, AppWindow, ArtistReleaseSection, ArtistState, DiscoveryArtist, JumpNavTab, LabelEntry, MbOriginData, MbRelationship, MbRelationshipsData, - NetworkSidebarState, ShellState, SimilarEntry, StoryItem, + NetworkSidebarState, SettingsState, ShellState, SimilarEntry, StoryItem, }; /// Plain, `Send` artist data produced on the worker thread. @@ -1195,11 +1195,18 @@ pub fn reset_network_sidebar(window: &AppWindow) { // (the same signal AlbumView + the ArtistPageView `net-cramped` // handlers use). Constrained => keep collapsed. let constrained = window.global::().get_content_constrained(); + // MusicBrainz opt-out: when MB is off the Network tab (relationships / + // discovery / origin) has nothing to show, so mark it unavailable and open + // on the MB-independent Magazine/Stories tab instead of an empty Network + // tab. The internal core guards (load_mb_metadata, musicbrainz_*) stay as + // belt-and-suspenders. + let mb_on = window.global::().get_musicbrainz_enabled(); let state = window.global::(); state.set_open(!constrained); - // Always (re)open a new artist on the Network tab. - state.set_active_tab("network".into()); - state.set_mb_available(true); + // (Re)open a new artist on the Network tab when MB is on, else Magazine. + let default_tab = if mb_on { "network" } else { "magazine" }; + state.set_active_tab(default_tab.into()); + state.set_mb_available(mb_on); state.set_mb_mbid("".into()); state.set_origin_loading(false); state.set_origin(MbOriginData::default()); diff --git a/crates/qbz/src/discover_prefs.rs b/crates/qbz/src/discover_prefs.rs index 2722ae23c..c0934ff4f 100644 --- a/crates/qbz/src/discover_prefs.rs +++ b/crates/qbz/src/discover_prefs.rs @@ -235,6 +235,12 @@ pub fn seed(window: &AppWindow) { window .global::() .set_show_recommendations(prefs.show_recommendations); + // MusicBrainz opt-out lives in ui_prefs (not the discover prefs store). + // Seed it here so both SettingsState seed sites (main.rs:320/554) populate + // the toggle that gates the artist sidebar + playlist suggestions. + window + .global::() + .set_musicbrainz_enabled(crate::ui_prefs::load().musicbrainz_enabled); push_descriptors(window, &prefs); } diff --git a/crates/qbz/src/main.rs b/crates/qbz/src/main.rs index 222c7e2d4..0a72035c2 100644 --- a/crates/qbz/src/main.rs +++ b/crates/qbz/src/main.rs @@ -5439,6 +5439,18 @@ fn main() -> Result<(), Box> { } } + // MusicBrainz opt-out seed — drive the core client's enabled flag from the + // persisted UI pref (default ON). Without this the client stays hardcoded ON + // and the Settings toggle can't turn it off. main() is sync, so spawn on the + // runtime; this runs before the first artist / playlist-suggestions load. + { + let runtime = app_runtime.clone(); + tokio_rt.spawn(async move { + let mb_on = crate::ui_prefs::load().musicbrainz_enabled; + runtime.core().musicbrainz_set_enabled(mb_on).await; + }); + } + // Shared QBZ image cache for album artwork; trim it on startup. let image_cache = artwork::open_cache(); artwork::spawn_evict(image_cache.clone()); diff --git a/crates/qbz/src/playlist_suggestions.rs b/crates/qbz/src/playlist_suggestions.rs index c9604b36c..1fc07a962 100644 --- a/crates/qbz/src/playlist_suggestions.rs +++ b/crates/qbz/src/playlist_suggestions.rs @@ -27,7 +27,7 @@ use slint::{ComponentHandle, Model, ModelRc, VecModel}; use crate::adapter::SlintAdapter; use crate::artwork::{ArtworkJob, ArtworkTarget}; -use crate::{AppWindow, PlaylistSuggestionRow, PlaylistSuggestionsState, PlaylistState}; +use crate::{AppWindow, PlaylistSuggestionRow, PlaylistSuggestionsState, PlaylistState, SettingsState}; type Runtime = std::sync::Arc>; type Handle = tokio::runtime::Handle; @@ -431,6 +431,20 @@ fn maybe_auto_expand(runtime: Runtime, weak: Weak, handle: Handle) { /// Launch suggestions for the open playlist: gather the seed artists + excludes /// off the loaded Qobuz tracks, then fetch the first pool page. UI thread. pub fn activate(window: &AppWindow, runtime: Runtime, handle: Handle) { + // MusicBrainz opt-out: the suggestion engine resolves each seed artist via + // MusicBrainz, so with MB off it can only ever return an empty pool. Skip the + // fetch entirely and present the closed/empty state. The wand CTA is also + // hidden in PlaylistView.slint when MB is off, so this is belt-and-suspenders. + if !window.global::().get_musicbrainz_enabled() { + let state = window.global::(); + state.set_activated(false); + state.set_loading(false); + state.set_loading_more(false); + state.set_is_empty(true); + state.set_rows(ModelRc::new(VecModel::from(Vec::::new()))); + return; + } + let playlist_id = window .global::() .get_id() diff --git a/crates/qbz/src/settings.rs b/crates/qbz/src/settings.rs index 93073a9d2..370ac6d8c 100644 --- a/crates/qbz/src/settings.rs +++ b/crates/qbz/src/settings.rs @@ -871,6 +871,17 @@ pub async fn handle_bool( crate::discover_prefs::set_show_recommendations(value); Ok(Apply::None) } + "musicbrainz" => { + // Opt-out toggle (default ON). Persist to ui_prefs (Option B, + // mirrors system_notifications) and drive the core client's + // in-memory enabled flag so the artist Network/Scene sidebar and + // playlist Suggested-Songs gate immediately. + let mut prefs = crate::ui_prefs::load(); + prefs.musicbrainz_enabled = value; + crate::ui_prefs::save(&prefs); + runtime.core().musicbrainz_set_enabled(value).await; + Ok(Apply::None) + } "persist-session" => { let r = with_playback(&ctx.playback, |s| s.set_persist_session(value)) .map(|_| Apply::None); diff --git a/crates/qbz/src/ui_prefs.rs b/crates/qbz/src/ui_prefs.rs index 0c5eab388..2cda8670c 100644 --- a/crates/qbz/src/ui_prefs.rs +++ b/crates/qbz/src/ui_prefs.rs @@ -119,6 +119,10 @@ fn default_system_notifications() -> bool { true } +fn default_musicbrainz_enabled() -> bool { + true +} + fn default_nav_in_sidebar() -> bool { true } @@ -240,6 +244,12 @@ pub struct UiPrefs { /// Default ON (the notify backend ships default-on; this is the user gate). #[serde(default = "default_system_notifications")] pub system_notifications: bool, + /// Whether MusicBrainz metadata enrichment is enabled (opt-out, default ON). + /// Drives the core client's enabled flag at startup and gates the artist + /// Network/Scene sidebar + playlist Suggested-Songs. Serde-default means an + /// older prefs file without the field deserializes to ON (zero migration). + #[serde(default = "default_musicbrainz_enabled")] + pub musicbrainz_enabled: bool, /// Discord Rich Presence "now listening" opt-in. Default OFF — external /// integrations are opt-in. (Tauri scoped this per Qobuz user; here it is a /// per-machine app preference — your Discord client is per-machine.) @@ -441,6 +451,7 @@ impl Default for UiPrefs { album_header_gradient: default_album_header_gradient(), intelligent_search: default_intelligent_search(), system_notifications: default_system_notifications(), + musicbrainz_enabled: default_musicbrainz_enabled(), discord_rpc_enabled: false, show_purchases: false, nav_tb_purchases: false,