From e966f35b30fa3a18e7d0ceac01c02c0cd92b8fb3 Mon Sep 17 00:00:00 2001 From: victorrhgap Date: Wed, 25 Mar 2026 15:29:27 -0600 Subject: [PATCH] feat(ui): wire QualityFallbackModal into global layout Listen for 'quality-fallback-prompt' custom events dispatched by playbackService, open the modal with track context, and handle try-lower / skip / close actions. cc --- src/routes/+page.svelte | 75 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 500cedfcb..1628ec0a4 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -279,7 +279,8 @@ loadSystemNotificationsPreference, showTrackNotification, updateLastfmNowPlaying, - cleanup as cleanupPlayback + cleanup as cleanupPlayback, + type PlayTrackOptions } from '$lib/services/playbackService'; import { isPlaybackSourceLocal, @@ -388,6 +389,7 @@ import TitleBarNav from '$lib/components/TitleBarNav.svelte'; import Sidebar from '$lib/components/Sidebar.svelte'; import AboutModal from '$lib/components/AboutModal.svelte'; + import QualityFallbackModal from '$lib/components/QualityFallbackModal.svelte'; import NowPlayingBar from '$lib/components/NowPlayingBar.svelte'; import QconnectPanel from '$lib/components/QconnectPanel.svelte'; import Toast from '$lib/components/Toast.svelte'; @@ -871,6 +873,12 @@ let isKeybindingsSettingsOpen = $state(false); let isLinkResolverOpen = $state(false); + // Quality Fallback Modal State + let isQualityFallbackOpen = $state(false); + let qualityFallbackTrackTitle = $state(''); + let qualityFallbackTrack = $state(null); + let qualityFallbackOptions = $state({}); + // Track Info Modal State let isTrackInfoOpen = $state(false); let trackInfoTrackId = $state(null); @@ -3834,9 +3842,64 @@ return albumDownloadCache.get(albumId) || false; } + // Quality Fallback Modal handlers + async function handleQualityFallbackTryLower() { + isQualityFallbackOpen = false; + if (qualityFallbackTrack) { + await playTrack(qualityFallbackTrack, { ...qualityFallbackOptions, forceLowestQuality: true }); + } + } + + async function handleQualityFallbackSkip() { + isQualityFallbackOpen = false; + const next = await nextTrack(); + if (next) { + const nextSource = resolvePlaybackSource(next); + const nextIsLocal = isPlaybackSourceLocal(nextSource, next.is_local ?? false); + const nextSamplingRate = next.sample_rate == null + ? undefined + : nextIsLocal + ? next.sample_rate / 1000 + : next.sample_rate; + await playTrack({ + id: next.id, + title: next.title, + artist: next.artist, + album: next.album, + duration: next.duration_secs, + artwork: next.artwork_url || '', + quality: next.hires ? 'Hi-Res' : 'CD Quality', + albumId: next.album_id || undefined, + artistId: next.artist_id || undefined, + bitDepth: next.bit_depth || undefined, + samplingRate: nextSamplingRate, + source: nextSource, + isLocal: nextIsLocal + }, { + isLocal: nextIsLocal, + source: nextSource, + showLoadingToast: true, + showSuccessToast: true + }); + } else { + setIsPlaying(false); + } + } + onMount(() => { // Bootstrap app (theme, mouse nav, Last.fm restore) const { cleanup: cleanupBootstrap } = bootstrapApp(); + + // Quality fallback modal listener + function handleQualityFallbackPrompt(e: Event) { + const detail = (e as CustomEvent).detail; + qualityFallbackTrackTitle = detail.trackTitle; + qualityFallbackTrack = detail.track; + qualityFallbackOptions = detail.options; + isQualityFallbackOpen = true; + } + window.addEventListener('quality-fallback-prompt', handleQualityFallbackPrompt); + void refreshQobuzConnectRuntimeState(); const qobuzConnectStatusInterval = setInterval(() => { if (isQconnectPanelOpen || isQobuzConnectConnected) { @@ -4625,6 +4688,7 @@ unregisterAll(); // Cleanup keybinding actions clearInterval(qobuzConnectStatusInterval); clearInterval(qconnectPositionReportInterval); + window.removeEventListener('quality-fallback-prompt', handleQualityFallbackPrompt); window.removeEventListener('beforeunload', handleBeforeUnload); document.removeEventListener('visibilitychange', handleVisibilityChange); stopOfflineCacheEventListeners(); @@ -5727,6 +5791,15 @@ onClose={() => isAboutModalOpen = false} /> + + isQualityFallbackOpen = false} + /> +