diff --git a/crates/Cargo.lock b/crates/Cargo.lock index 4fe57ab69..70f260d7c 100644 --- a/crates/Cargo.lock +++ b/crates/Cargo.lock @@ -1691,6 +1691,21 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "discord-rich-presence" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90c55d69cab17c19677ce3a5f8face993a9e6eaf847fecac3547f3a3ff4a2494" +dependencies = [ + "log", + "serde", + "serde_derive", + "serde_json", + "serde_repr", + "thiserror 2.0.18", + "uuid 0.8.2", +] + [[package]] name = "dispatch" version = "0.2.0" @@ -5511,7 +5526,7 @@ dependencies = [ "serde", "serde_json", "tokio", - "uuid", + "uuid 1.22.0", ] [[package]] @@ -5635,6 +5650,7 @@ name = "qbz-integrations" version = "0.1.0" dependencies = [ "chrono", + "discord-rich-presence", "log", "reqwest", "rusqlite", @@ -5659,7 +5675,7 @@ dependencies = [ "serde_json", "tempfile", "thiserror 2.0.18", - "uuid", + "uuid 1.22.0", "walkdir", ] @@ -5714,7 +5730,7 @@ dependencies = [ "serde", "strsim", "tokio", - "uuid", + "uuid 1.22.0", ] [[package]] @@ -5847,7 +5863,7 @@ dependencies = [ "sha2 0.10.9", "tempfile", "thiserror 2.0.18", - "uuid", + "uuid 1.22.0", ] [[package]] @@ -5900,7 +5916,7 @@ dependencies = [ "swash", "tokio", "urlencoding", - "uuid", + "uuid 1.22.0", ] [[package]] @@ -5926,7 +5942,7 @@ dependencies = [ "serde_json", "thiserror 2.0.18", "tokio", - "uuid", + "uuid 1.22.0", ] [[package]] @@ -5948,7 +5964,7 @@ dependencies = [ "serde", "serde_json", "thiserror 2.0.18", - "uuid", + "uuid 1.22.0", ] [[package]] @@ -8364,6 +8380,15 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +dependencies = [ + "getrandom 0.2.17", +] + [[package]] name = "uuid" version = "1.22.0" @@ -9882,7 +9907,7 @@ dependencies = [ "tokio", "tracing", "uds_windows", - "uuid", + "uuid 1.22.0", "windows-sys 0.61.2", "winnow 1.0.3", "zbus_macros 5.15.0", diff --git a/crates/qbz-integrations/Cargo.toml b/crates/qbz-integrations/Cargo.toml index 14aa3b9f4..aeef7ea4f 100644 --- a/crates/qbz-integrations/Cargo.toml +++ b/crates/qbz-integrations/Cargo.toml @@ -25,6 +25,10 @@ thiserror = "1" # URL encoding for API queries urlencoding = "2" +# Discord Rich Presence (now-listening activity). Same crate + version the +# Tauri build used; frontend-agnostic (IPC-only, no Tauri dependency). +discord-rich-presence = "1.1.0" + # SQLite for caching (optional, enabled by default) rusqlite = { version = "0.31", features = ["bundled"], optional = true } diff --git a/crates/qbz-integrations/src/discord.rs b/crates/qbz-integrations/src/discord.rs new file mode 100644 index 000000000..b23fef632 --- /dev/null +++ b/crates/qbz-integrations/src/discord.rs @@ -0,0 +1,210 @@ +//! Discord Rich Presence integration (frontend-agnostic). +//! +//! Ported ~1:1 from the Tauri `discord_rpc.rs` backend, minus the +//! `#[tauri::command]` / `tauri::State` wrappers — the logic is plain Rust so +//! any frontend (Slint, TUI, CLI) drives it through [`DiscordRpc`]. +//! +//! Connection is lazy: the IPC client is created on the first [`DiscordRpc::update`] +//! call when the feature is enabled, and dropped if any operation fails. Failure +//! is silent — when Discord is not running, when the sandbox blocks the IPC +//! socket, or when the user has not opted in, the activity simply does not appear. +//! +//! The IPC calls are blocking; call [`DiscordRpc`] methods off the UI thread +//! (e.g. inside `tokio::task::spawn_blocking`). + +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::Mutex; +use std::time::{SystemTime, UNIX_EPOCH}; + +use discord_rich_presence::{activity, DiscordIpc, DiscordIpcClient}; + +/// Public Discord Application ID for QBZ. Public identifier, not a secret. +const DISCORD_APP_ID: &str = "1501835855587708988"; +const QBZ_HOMEPAGE: &str = "https://qbz.lol"; + +/// Bridge our Flatpak sandbox to the Discord-Flatpak IPC socket. +/// +/// The `discord-rich-presence` crate searches `$XDG_RUNTIME_DIR/discord-ipc-N` +/// for `N=0..9`. Native Discord (deb / rpm / AUR) writes its socket directly +/// to that path, so the search succeeds out of the box. Discord installed via +/// Flathub writes to `$XDG_RUNTIME_DIR/app/com.discordapp.Discord/discord-ipc-N` +/// because each Flatpak app gets its own runtime subdirectory; the crate's +/// default search misses it, and Rich Presence appears broken even though +/// Discord is running. +/// +/// Other Flathub apps work around this with a startup wrapper script that +/// unconditionally symlinks every iteration into `$XDG_RUNTIME_DIR` for every +/// user. That conflicts with QBZ's external-service-integration posture: all +/// optional integrations are opt-in (Last.fm, ListenBrainz, MusicBrainz, Plex, +/// Discord here). Running the wrapper for every Flatpak instance — including +/// users who never enabled Discord RPC — silently turns the integration into +/// opt-out at the sandbox layer. +/// +/// We make the symlinks here instead, lazily, the first time the user actually +/// connects to Discord. If the user never toggles Discord RPC on, these links +/// are never created and the sandbox stays untouched. The links live for the +/// lifetime of the Flatpak instance (`$XDG_RUNTIME_DIR` is scoped per-instance) +/// so there's no cross-session pollution either. +/// +/// Returns silently on every failure path — missing env var, non-Flatpak +/// process, ENOENT on the source dir, EEXIST on the link target, etc. +fn prepare_flatpak_discord_socket_links() { + if std::env::var_os("FLATPAK_ID").is_none() { + return; + } + let Some(runtime_dir) = std::env::var_os("XDG_RUNTIME_DIR") else { + return; + }; + let runtime_dir = std::path::PathBuf::from(runtime_dir); + + // discord-rich-presence iterates 0..=9; only bother creating a link when + // the slot in $XDG_RUNTIME_DIR is currently empty AND the corresponding + // path inside the Discord-Flatpak app dir exists. Either condition failing + // is normal (Discord not running, slot already taken by native Discord, + // etc.) and silently skipped. + for i in 0..=9 { + let link_target = runtime_dir.join(format!("discord-ipc-{}", i)); + if link_target.exists() || link_target.symlink_metadata().is_ok() { + continue; + } + let source = runtime_dir + .join("app") + .join("com.discordapp.Discord") + .join(format!("discord-ipc-{}", i)); + if !source.exists() { + continue; + } + #[cfg(unix)] + let _ = std::os::unix::fs::symlink(&source, &link_target); + } +} + +/// The "now listening" snapshot pushed to Discord. Mirrors the params the Tauri +/// `v2_discord_rpc_update` command took. +#[derive(Debug, Clone, Default)] +pub struct NowListening { + pub title: String, + pub artist: String, + pub album: String, + pub is_playing: bool, + /// Current playback position, seconds. + pub current_time: f64, + /// Track duration, seconds (0 = unknown; no end timestamp then). + pub duration: f64, + /// Large-image asset: a Discord asset key OR an http(s) cover URL. `None` + /// falls back to the "cover" asset key. + pub cover_url: Option, +} + +/// Discord Rich Presence client holder. Owns the lazy IPC connection + the +/// opt-in flag. Cheap to keep as a process-global (the Slint service does). +#[derive(Default)] +pub struct DiscordRpc { + client: Mutex>, + enabled: AtomicBool, +} + +impl DiscordRpc { + pub const fn new() -> Self { + Self { + client: Mutex::new(None), + enabled: AtomicBool::new(false), + } + } + + /// Whether the integration is currently opted in. + pub fn is_enabled(&self) -> bool { + self.enabled.load(Ordering::SeqCst) + } + + /// Flip the opt-in flag. Disabling tears down the live activity + IPC + /// connection so the presence disappears immediately. + pub fn set_enabled(&self, enabled: bool) { + self.enabled.store(enabled, Ordering::SeqCst); + if !enabled { + self.clear(); + } + } + + /// Clear the activity and drop the IPC connection (no-op when not connected). + pub fn clear(&self) { + if let Ok(mut guard) = self.client.lock() { + if let Some(client) = guard.as_mut() { + let _ = client.clear_activity(); + let _ = client.close(); + } + *guard = None; + } + } + + /// Push the current "now listening" snapshot. Lazily connects on first use + /// when enabled; a no-op (Ok) when disabled. Silent on every IPC failure + /// (Discord closed / sandbox blocked): the connection is dropped so the + /// next update retries cleanly. + pub fn update(&self, meta: &NowListening) { + if !self.enabled.load(Ordering::SeqCst) { + return; + } + + let Ok(mut guard) = self.client.lock() else { + return; + }; + + if guard.is_none() { + // Bridge the Flatpak sandbox to Discord's IPC socket if we're + // running under Flatpak. No-op outside that context. + prepare_flatpak_discord_socket_links(); + // discord-rich-presence 1.x: DiscordIpcClient::new is infallible + // (returns Self directly); failures show up at connect() time. + let mut client = DiscordIpcClient::new(DISCORD_APP_ID); + if client.connect().is_ok() { + *guard = Some(client); + } + } + + let Some(client) = guard.as_mut() else { + return; + }; + + let state_str = format!("by {}", meta.artist); + let small_text = if meta.is_playing { + "Playing".to_string() + } else { + let mins = (meta.current_time / 60.0).floor() as u32; + let secs = (meta.current_time % 60.0).floor() as u32; + format!("Paused at {:02}:{:02}", mins, secs) + }; + let large_image = meta + .cover_url + .clone() + .unwrap_or_else(|| "cover".to_string()); + + let mut act = activity::Activity::new() + .details(&meta.title) + .state(&state_str) + .activity_type(activity::ActivityType::Listening) + .assets( + activity::Assets::new() + .large_image(&large_image) + .small_image("icon") + .large_text(&meta.album) + .small_text(&small_text), + ) + .buttons(vec![activity::Button::new("Get QBZ", QBZ_HOMEPAGE)]); + + if meta.is_playing { + if let Ok(now) = SystemTime::now().duration_since(UNIX_EPOCH) { + let start_time = now.as_secs() as i64 - meta.current_time as i64; + let mut ts = activity::Timestamps::new().start(start_time); + if meta.duration > 0.0 { + ts = ts.end(start_time + meta.duration as i64); + } + act = act.timestamps(ts); + } + } + + if client.set_activity(act).is_err() { + *guard = None; + } + } +} diff --git a/crates/qbz-integrations/src/lib.rs b/crates/qbz-integrations/src/lib.rs index 94a18c22a..e942e57cc 100644 --- a/crates/qbz-integrations/src/lib.rs +++ b/crates/qbz-integrations/src/lib.rs @@ -24,6 +24,7 @@ //! The crate exposes async APIs that can be called from any async runtime. pub mod discogs; +pub mod discord; pub mod error; pub mod lastfm; pub mod listenbrainz; @@ -34,6 +35,7 @@ pub use error::{IntegrationError, IntegrationResult}; // Re-export main types for convenience pub use discogs::DiscogsClient; +pub use discord::{DiscordRpc, NowListening}; pub use lastfm::{LastFmClient, LastFmSession}; pub use listenbrainz::{ListenBrainzClient, ListenBrainzConfig, ListenType}; pub use musicbrainz::{MusicBrainzClient, MusicBrainzConfig}; diff --git a/crates/qbz-slint/src/discord_rpc.rs b/crates/qbz-slint/src/discord_rpc.rs new file mode 100644 index 000000000..a6f911ea8 --- /dev/null +++ b/crates/qbz-slint/src/discord_rpc.rs @@ -0,0 +1,97 @@ +//! Discord Rich Presence controller (Slint side). +//! +//! Owns a process-global [`DiscordRpc`] (the frontend-agnostic core in +//! `qbz-integrations`) and wires it to: +//! - the opt-in toggle (Settings › Integrations), persisted in `ui_prefs`; +//! - playback track-change + play/pause transitions, which push the +//! "now listening" activity; +//! - the shell session lifecycle: [`init`] runs AFTER the session is active +//! (the PR #477 fix — never at early boot), [`clear`] on logout / exit. +//! +//! The IPC is blocking, so every Discord call runs inside `spawn_blocking`. +//! All calls are no-ops when the user has not opted in. + +use std::sync::{Arc, LazyLock}; + +use qbz_app::shell::AppRuntime; +use qbz_integrations::{DiscordRpc, NowListening}; + +use crate::adapter::SlintAdapter; + +type Runtime = Arc>; + +/// Process-global Discord client. Holds the lazy IPC connection + opt-in flag; +/// `set_enabled(false)` tears the connection down so the presence disappears. +static DISCORD: LazyLock = LazyLock::new(DiscordRpc::default); + +/// Apply the persisted opt-in. Called from `init_shell_for_user` — i.e. AFTER +/// the session is active, for BOTH the online and offline entry paths. This is +/// the persistence fix from PR #477: initializing here (not at early boot, +/// before the session/prefs existed) makes "enabled on restart" actually launch. +pub fn init(runtime: &Runtime, handle: &tokio::runtime::Handle) { + let enabled = crate::ui_prefs::load().discord_rpc_enabled; + DISCORD.set_enabled(enabled); + if enabled { + push(runtime, handle); + } +} + +/// Settings toggle: persist the opt-in, apply it, and push the current track +/// (enable) or let `set_enabled(false)` clear the activity (disable). +pub fn set_enabled(enabled: bool, runtime: &Runtime, handle: &tokio::runtime::Handle) { + let mut prefs = crate::ui_prefs::load(); + prefs.discord_rpc_enabled = enabled; + crate::ui_prefs::save(&prefs); + DISCORD.set_enabled(enabled); + if enabled { + push(runtime, handle); + } +} + +/// Tear down the live activity + IPC connection (logout / app exit). No-op when +/// not connected. +pub fn clear(handle: &tokio::runtime::Handle) { + handle.spawn(async { + let _ = tokio::task::spawn_blocking(|| DISCORD.clear()).await; + }); +} + +/// Build the "now listening" snapshot from the live queue + playback state and +/// push it to Discord. No-op when disabled (cheap early return — nothing is +/// fetched). Called on track change and play/pause, mirroring the Tauri +/// service's (track_id, is_playing) transition pushes. +pub fn push(runtime: &Runtime, handle: &tokio::runtime::Handle) { + if !DISCORD.is_enabled() { + return; + } + let runtime = runtime.clone(); + handle.spawn(async move { + let state = runtime.core().get_queue_state().await; + let Some(track) = state.current_track else { + // Nothing playing — drop the activity. + let _ = tokio::task::spawn_blocking(|| DISCORD.clear()).await; + return; + }; + let pb = runtime.core().get_playback_state(); + let title = match track.version.as_deref().filter(|v| !v.is_empty()) { + Some(version) => format!("{} ({version})", track.title), + None => track.title.clone(), + }; + // Discord's large_image needs an http(s) URL or an asset key; local / + // Plex covers are filesystem paths Discord can't fetch, so drop them + // (the core falls back to the "cover" asset key). + let cover_url = track + .artwork_url + .filter(|u| u.starts_with("http://") || u.starts_with("https://")); + let meta = NowListening { + title, + artist: track.artist, + album: track.album, + is_playing: pb.is_playing, + current_time: pb.position as f64, + duration: track.duration_secs as f64, + cover_url, + }; + let _ = tokio::task::spawn_blocking(move || DISCORD.update(&meta)).await; + }); +} diff --git a/crates/qbz-slint/src/main.rs b/crates/qbz-slint/src/main.rs index 3d103aaed..c15445e79 100644 --- a/crates/qbz-slint/src/main.rs +++ b/crates/qbz-slint/src/main.rs @@ -30,6 +30,7 @@ mod commands; mod custom_artwork; mod dates; mod discover_browse; +mod discord_rpc; mod discover_prefs; mod discovery_dismiss; mod fav_cache; @@ -174,6 +175,12 @@ fn init_shell_for_user( scrobbler_settings::init_for_user(user_id); scrobble::start(tokio::runtime::Handle::current()); + // Discord Rich Presence: apply the persisted opt-in AFTER the session is + // active (PR #477 — never at early boot). Runs for both the online and + // offline entry paths since both call init_shell_for_user. No-op + no IPC + // when the user hasn't opted in. + discord_rpc::init(runtime, &tokio::runtime::Handle::current()); + // 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. @@ -6433,6 +6440,8 @@ fn main() -> Result<(), Box> { let weak = window.as_weak(); let handle = tokio_rt.handle().clone(); window.on_logout(move || { + // Drop any Discord "now listening" activity on logout. + discord_rpc::clear(&handle); let runtime = runtime.clone(); let weak = weak.clone(); handle.spawn(async move { @@ -6453,6 +6462,18 @@ fn main() -> Result<(), Box> { }); } + // Discord Rich Presence (Settings > Integrations): seed the toggle from the + // persisted opt-in and wire the change to the controller (persist + apply). + { + let de = window.global::(); + de.set_enabled(crate::ui_prefs::load().discord_rpc_enabled); + let runtime = app_runtime.clone(); + let handle = tokio_rt.handle().clone(); + de.on_set_enabled(move |enabled| { + discord_rpc::set_enabled(enabled, &runtime, &handle); + }); + } + // Settings — a toggle changed: persist it and apply audio ones to the // live player. { diff --git a/crates/qbz-slint/src/playback.rs b/crates/qbz-slint/src/playback.rs index 3287399fa..1ca3cd94e 100644 --- a/crates/qbz-slint/src/playback.rs +++ b/crates/qbz-slint/src/playback.rs @@ -1462,6 +1462,10 @@ pub(crate) async fn refresh_now_playing_meta(runtime: &Runtime, weak: &slint::We // peer's track (Q7). Fire-and-forget; the stale-response guard (F2) // lives in `lyrics::on_track_changed`. crate::lyrics::on_track_changed(weak.clone(), &track); + // Discord Rich Presence: push the new track on this de-duped + // track-change edge (no-op + no IPC when not opted in). Mirrors the + // Tauri service's track_id transition push. + crate::discord_rpc::push(runtime, &tokio::runtime::Handle::current()); // Warm the NEXT queued track's lyrics in the background so the panel is // instant when it becomes current (cache-only; no UI). Generated here // because Tauri only ever fetches the CURRENT track. @@ -3786,6 +3790,10 @@ pub fn start_poll_loop( }; mc.set_playback(status, Some(std::time::Duration::from_secs(position as u64))); } + // Discord Rich Presence: re-push on the play/pause edge so the + // "Playing" / "Paused at mm:ss" state + timestamps stay correct + // (no-op when not opted in). Mirrors the Tauri service. + crate::discord_rpc::push(&runtime, &tokio::runtime::Handle::current()); } was_playing = is_playing; diff --git a/crates/qbz-slint/src/ui_prefs.rs b/crates/qbz-slint/src/ui_prefs.rs index fed3f0e17..da6096a57 100644 --- a/crates/qbz-slint/src/ui_prefs.rs +++ b/crates/qbz-slint/src/ui_prefs.rs @@ -168,6 +168,11 @@ 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, + /// 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.) + #[serde(default)] + pub discord_rpc_enabled: bool, /// Immersive in-view search action: `"disabled"` | `"replace"` | `"next"` | /// `"queue"`. Doubles as the enable switch (`"disabled"` keeps the field /// inert). See [`DEFAULT_IMMERSIVE_SEARCH_ACTION`]. @@ -275,6 +280,7 @@ impl Default for UiPrefs { album_header_gradient: default_album_header_gradient(), intelligent_search: default_intelligent_search(), system_notifications: default_system_notifications(), + discord_rpc_enabled: false, 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/app.slint b/crates/qbz-slint/ui/app.slint index 9d88fe930..631c8b65f 100644 --- a/crates/qbz-slint/ui/app.slint +++ b/crates/qbz-slint/ui/app.slint @@ -26,7 +26,7 @@ export { Theme, ThemeColors } from "foundation/semantic-colors.slint"; export { ThemeState } from "foundation/theme-state.slint"; // Re-export the state globals so the Rust layer can populate them. -export { HomeState, HomeActions, DiscoverState, DiscoverActions, SectionDescriptor, ConfigRow, DiscoverBrowseState, DiscoverBrowseActions, ForYouState, MixState, GenreFilterState, GenreFilterActions, AlbumState, ArtistState, NavState, ShellState, SessionState, SettingsState, AlbumActions, ArtistActions, ArtworkActions, NowPlayingState, QueueState, LyricsState, LyricsLineItem, SearchState, SearchActions, NetworkSidebarState, NetworkSidebarActions, MusicianState, MusicianActions, LabelState, LabelActions, AwardState, AwardActions, AwardEntry, ArtistReleasesState, ArtistReleasesActions, LocationViewState, LocationViewActions, FavoritesState, FavoritesActions, PlaylistPickerState, PlaylistPickerActions, DuplicateConfirmState, DuplicateConfirmActions, PlaylistState, PlaylistActions, SidebarState, SidebarActions, SidebarFolderPopupState, CreatePlaylistState, CreatePlaylistActions, EditPlaylistState, EditPlaylistActions, CreateFolderState, CreateFolderActions, MyQbzCreateState, MyQbzCreateActions, DragState, DragActions, PlaylistManagerState, PlaylistManagerActions, OfflineManagerState, OfflineManagerActions, BlacklistState, BlacklistActions, BlacklistedArtistItem, MyQbzState, MyQbzActions, MixtapeCardItem, MyQbzAddState, MyQbzAddActions, MyQbzAddRow, MyQbzDetailState, MyQbzDetailActions, MixtapeDetailItem, MyQbzEditState, MyQbzEditActions, MyQbzMixState, MyQbzMixActions, DiscoBuilderState, DiscoBuilderActions, DiscoGroup, DiscoCandidate, LocalLibraryState, LocalLibraryActions, LibraryFoldersState, LibFolderEditState, LibraryManageActions, LibraryScanState, LibAlbumFilterState, LocalAlbumState, LocalAlbumActions, TagEditorState, TagEditorActions, FolderEditState, FolderEditActions, ToastState, TextUtil, QconnectDevState, QconnectDevice, CastState, CastDevice, CastActions, AppearanceState, MyQbzBrandingState, EphemeralPlayChoiceState, EphemeralPlayChoiceActions, PlexSettingsState, PlexAuthActions, PlexSectionItem, ScrobbleState, ScrobbleActions, OfflineState, OfflineModeActions, OfflineFavoritesState, OfflineFavoritesActions, ImportLogEntry, PlaylistImportState, PlaylistImportActions, DacWizardState, DacWizardActions, DacCandidateRow, RemediationRow, DacConfigRow, InfoCreditRow, InfoCreditPair, AlbumCreditPerformer, AlbumCreditTrack, TrackInfoState, TrackInfoActions, AlbumInfoState, AlbumInfoActions, BookletState, BookletActions, SuggestionsState, SuggestionsActions, SuggestionCard, VisualizerState, ImmersiveState, ImmersiveSearchActions, ImmersiveActions, MiniPlayerState, WindowControlActions } from "state.slint"; +export { HomeState, HomeActions, DiscoverState, DiscoverActions, SectionDescriptor, ConfigRow, DiscoverBrowseState, DiscoverBrowseActions, ForYouState, MixState, GenreFilterState, GenreFilterActions, AlbumState, ArtistState, NavState, ShellState, SessionState, SettingsState, AlbumActions, ArtistActions, ArtworkActions, NowPlayingState, QueueState, LyricsState, LyricsLineItem, SearchState, SearchActions, NetworkSidebarState, NetworkSidebarActions, MusicianState, MusicianActions, LabelState, LabelActions, AwardState, AwardActions, AwardEntry, ArtistReleasesState, ArtistReleasesActions, LocationViewState, LocationViewActions, FavoritesState, FavoritesActions, PlaylistPickerState, PlaylistPickerActions, DuplicateConfirmState, DuplicateConfirmActions, PlaylistState, PlaylistActions, SidebarState, SidebarActions, SidebarFolderPopupState, CreatePlaylistState, CreatePlaylistActions, EditPlaylistState, EditPlaylistActions, CreateFolderState, CreateFolderActions, MyQbzCreateState, MyQbzCreateActions, DragState, DragActions, PlaylistManagerState, PlaylistManagerActions, OfflineManagerState, OfflineManagerActions, BlacklistState, BlacklistActions, BlacklistedArtistItem, MyQbzState, MyQbzActions, MixtapeCardItem, MyQbzAddState, MyQbzAddActions, MyQbzAddRow, MyQbzDetailState, MyQbzDetailActions, MixtapeDetailItem, MyQbzEditState, MyQbzEditActions, MyQbzMixState, MyQbzMixActions, DiscoBuilderState, DiscoBuilderActions, DiscoGroup, DiscoCandidate, LocalLibraryState, LocalLibraryActions, LibraryFoldersState, LibFolderEditState, LibraryManageActions, LibraryScanState, LibAlbumFilterState, LocalAlbumState, LocalAlbumActions, TagEditorState, TagEditorActions, FolderEditState, FolderEditActions, ToastState, TextUtil, QconnectDevState, QconnectDevice, CastState, CastDevice, CastActions, AppearanceState, MyQbzBrandingState, EphemeralPlayChoiceState, EphemeralPlayChoiceActions, PlexSettingsState, PlexAuthActions, PlexSectionItem, ScrobbleState, ScrobbleActions, DiscordState, OfflineState, OfflineModeActions, OfflineFavoritesState, OfflineFavoritesActions, ImportLogEntry, PlaylistImportState, PlaylistImportActions, DacWizardState, DacWizardActions, DacCandidateRow, RemediationRow, DacConfigRow, InfoCreditRow, InfoCreditPair, AlbumCreditPerformer, AlbumCreditTrack, TrackInfoState, TrackInfoActions, AlbumInfoState, AlbumInfoActions, BookletState, BookletActions, SuggestionsState, SuggestionsActions, SuggestionCard, VisualizerState, ImmersiveState, ImmersiveSearchActions, ImmersiveActions, MiniPlayerState, WindowControlActions } from "state.slint"; // Which top-level screen is shown. The app starts on `splash` while it // restores a saved session, then resolves to `shell` or `login`. diff --git a/crates/qbz-slint/ui/settings/IntegrationsSettings.slint b/crates/qbz-slint/ui/settings/IntegrationsSettings.slint index 8bb88ba63..006be7463 100644 --- a/crates/qbz-slint/ui/settings/IntegrationsSettings.slint +++ b/crates/qbz-slint/ui/settings/IntegrationsSettings.slint @@ -8,7 +8,7 @@ import { Theme } from "../foundation/semantic-colors.slint"; import { Typography } from "../foundation/typography.slint"; import { Radius } from "../foundation/radius.slint"; -import { ScrobbleState, ScrobbleActions } from "../state.slint"; +import { ScrobbleState, ScrobbleActions, DiscordState } from "../state.slint"; import { SettingRow } from "SettingRow.slint"; import { QbzIcon } from "../primitives/QbzIcon.slint"; import { QbzToggle } from "../primitives/QbzToggle.slint"; @@ -264,4 +264,28 @@ export component IntegrationsSettings inherits VerticalLayout { wrap: word-wrap; } } + + // =================================================================== + // DISCORD — Rich Presence "now listening" (opt-in, independent of the + // scrobblers above). State + persistence live in DiscordState / ui_prefs; + // the fire + IPC live in the `discord_rpc` controller. + // =================================================================== + Rectangle { height: 12px; } + GroupHeader { text: @tr("DISCORD"); } + Rectangle { height: 4px; } + SettingRow { + label: @tr("Discord Rich Presence"); + description: @tr("Show what you're listening to as your Discord status. Opt-in — Discord must be running."); + QbzToggle { + checked: DiscordState.enabled; + toggled(v) => { + DiscordState.enabled = v; + DiscordState.set-enabled(v); + } + } + } + SettingRow { + label: @tr("Flatpak socket access"); + description: @tr("Flatpak install and the presence isn't showing? Grant access to Discord's IPC socket, then restart QBZ:\nflatpak override --user --filesystem=xdg-run/discord-ipc-0 com.blitzfc.qbz"); + } } diff --git a/crates/qbz-slint/ui/state.slint b/crates/qbz-slint/ui/state.slint index 248bf5cef..98669d70c 100644 --- a/crates/qbz-slint/ui/state.slint +++ b/crates/qbz-slint/ui/state.slint @@ -1314,6 +1314,13 @@ export global PlexAuthActions { // `scrobble` controller (auth flows + the now-playing/scrobble fire live // there). ADR-008: no pills. +// Discord Rich Presence (Settings > Integrations). Opt-in, default OFF; the +// `enabled` flag is seeded from ui_prefs and `set-enabled` persists + applies it. +export global DiscordState { + in-out property enabled: false; + callback set-enabled(bool); +} + export global ScrobbleState { // --- Master section toggles ------------------------------------------- in-out property enabled: false; // master toggle (default OFF)