minor fix to trakt duplicating

This commit is contained in:
chrisk325 2026-03-23 11:39:39 +05:30 committed by GitHub
parent d955631724
commit f5909da584
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -710,11 +710,27 @@ export function useTraktAutosync(options: TraktAutosyncOptions) {
logger.log(`[TraktAutosync] Manual state reset for: ${options.title}`);
}, [options.title]);
// Resume session after app foreground return — clears hasStopped so a fresh
// /scrobble/start can be sent without triggering the remount-duplicate guard.
// Only re-opens if session isn't complete (already scrobbled).
const resumeSession = useCallback(async (currentTime: number, duration: number) => {
if (isSessionComplete.current) {
logger.log(`[TraktAutosync] resumeSession: session complete, skipping`);
return;
}
if (isUnmounted.current) return;
logger.log(`[TraktAutosync] resumeSession: clearing hasStopped/hasStartedWatching and re-opening session`);
hasStopped.current = false;
hasStartedWatching.current = false;
await handlePlaybackStart(currentTime, duration);
}, [handlePlaybackStart]);
return {
isAuthenticated,
handlePlaybackStart,
handleProgressUpdate,
handlePlaybackEnd,
resumeSession,
resetState
};
}