Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix]: Fix repeated track scrobbling #480

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/renderer/features/player/hooks/use-scrobble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,29 @@ 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,
state.current.index,
],
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 three 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)
// 3. The song does not change, but the queue position does. This would happen if
// the same song has been enqueued multiple times in a row, and the prev/next
// button is pressed. In this case, the player is forced to 1, which may not cause
// condition 2 to fire. Thus, comparing the queue index will catch this case
jeffvli marked this conversation as resolved.
Show resolved Hide resolved
equalityFn: (a, b) =>
(a[0] as QueueSong)?.id === (b[0] as QueueSong)?.id &&
a[2] === b[2] &&
a[3] === b[3],
},
);

Expand Down
Loading