From eff1cee6a3c21b91089061615b15eaf759ade06f Mon Sep 17 00:00:00 2001 From: Kendall Garner <17521368+kgarner7@users.noreply.github.com> Date: Thu, 1 Feb 2024 04:12:39 +0000 Subject: [PATCH] [bugfix]: Fix repeated track scrobbling (#480) * [bugfix]: Fix repeated track scrobbling This commit fixes scrobbling tracks that are repeated in the queue (either due to a REPEAT_ONE or just enqueued multiple times). There are two extra cases: 1. The current player changes. The player alternates from 1 -> 2 -> 1 whenever playback finishes normally, so this is a sort of epoch that can be used to detect both repeat one and track being enqueued multiple times. 2. The current index changes. The player gets set back to 1 in a variety of cases (most often previous/next), so the check in (1) is not enough. However, the index changing will help identify that this is a new song. * use unique id instead --- src/renderer/features/player/hooks/use-scrobble.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/renderer/features/player/hooks/use-scrobble.ts b/src/renderer/features/player/hooks/use-scrobble.ts index 28549049..b2a7b9a3 100644 --- a/src/renderer/features/player/hooks/use-scrobble.ts +++ b/src/renderer/features/player/hooks/use-scrobble.ts @@ -315,12 +315,19 @@ export const useScrobble = () => { useEffect(() => { const unsubSongChange = usePlayerStore.subscribe( - (state) => [state.current.song, state.current.time], + (state) => [state.current.song, state.current.time, state.current.player], handleScrobbleFromSongChange, { // We need the current time to check the scrobble condition, but we only want to // trigger the callback when the song changes - equalityFn: (a, b) => (a[0] as QueueSong)?.id === (b[0] as QueueSong)?.id, + // There are two conditions where this should trigger: + // 1. The song actually changes (the common case) + // 2. The song does not change, but the player dows. This would either be + // a single track on repeat one, or one track added to the queue + // multiple times in a row and playback goes normally (no next/previous) + equalityFn: (a, b) => + (a[0] as QueueSong)?.uniqueId === (b[0] as QueueSong)?.uniqueId && + a[2] === b[2], }, );