From 103c69664b9de46de82054d0054dfd15ab5ee995 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Thu, 10 Jul 2025 01:25:31 -0700 Subject: [PATCH] fix: improve now playing detection reliability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Always fetch fresh data from Last.fm for now playing detection - Add confidence-based detection with progress tracking - Implement dynamic polling intervals (10s when playing, 30s idle) - Add marquee animation for now playing text in header - Fix release date formatting to show only year - Add gradient fade effects to marquee edges - Enhanced logging for debugging detection issues 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/lib/components/Header.svelte | 96 +++++----------- src/lib/components/NowPlayingBar.svelte | 144 ++++++++++++++++++++++++ src/lib/utils/lastfmStreamManager.ts | 75 ++++++------ src/lib/utils/nowPlayingDetector.ts | 68 ++++++++++- src/routes/api/lastfm/stream/+server.ts | 32 +++++- 5 files changed, 301 insertions(+), 114 deletions(-) create mode 100644 src/lib/components/NowPlayingBar.svelte diff --git a/src/lib/components/Header.svelte b/src/lib/components/Header.svelte index 78e70a1..8e86cef 100644 --- a/src/lib/components/Header.svelte +++ b/src/lib/components/Header.svelte @@ -2,6 +2,7 @@ import Avatar from './Avatar.svelte' import SegmentedController from './SegmentedController.svelte' import NavDropdown from './NavDropdown.svelte' + import NowPlayingBar from './NowPlayingBar.svelte' import { albumStream } from '$lib/stores/album-stream' import { nowPlayingStream } from '$lib/stores/now-playing-stream' import type { Album } from '$lib/types/lastfm' @@ -23,6 +24,15 @@ const nowPlaying = state.albums.find((album) => album.isNowPlaying) currentlyPlayingAlbum = nowPlaying || null isPlayingMusic = !!nowPlaying + + // Debug logging + if (nowPlaying) { + console.log('Header: Now playing detected:', { + artist: nowPlaying.artist.name, + album: nowPlaying.name, + track: nowPlaying.nowPlayingTrack + }) + } }) return unsubscribe @@ -32,7 +42,12 @@ $effect(() => { const unsubscribe = nowPlayingStream.subscribe((state) => { const hasNowPlaying = Array.from(state.updates.values()).some((update) => update.isNowPlaying) - if (!hasNowPlaying && currentlyPlayingAlbum) { + console.log('Header: nowPlayingStream update:', { + hasNowPlaying, + updatesCount: state.updates.size + }) + // Only clear if we explicitly know music stopped + if (!hasNowPlaying && currentlyPlayingAlbum && state.updates.size > 0) { // Music stopped currentlyPlayingAlbum = null isPlayingMusic = false @@ -82,31 +97,25 @@ style="--gradient-opacity: {gradientOpacity}; --padding-progress: {paddingProgress}" >
- isHoveringAvatar = true} - onmouseleave={() => isHoveringAvatar = false} + onmouseenter={() => { + isHoveringAvatar = true + console.log('Header: Hovering avatar, showing now playing?', { + isHoveringAvatar: true, + isPlayingMusic, + currentlyPlayingAlbum: currentlyPlayingAlbum?.name + }) + }} + onmouseleave={() => (isHoveringAvatar = false)} >