mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-17 07:21:58 +00:00
fix duplicate entries to trakt history
This commit is contained in:
parent
56b292f79a
commit
d955631724
1 changed files with 14 additions and 8 deletions
|
|
@ -84,11 +84,10 @@ export const useWatchProgress = (
|
|||
// AppState Listener for background save
|
||||
useEffect(() => {
|
||||
const subscription = AppState.addEventListener('change', async (nextAppState) => {
|
||||
if (nextAppState.match(/inactive|background/)) {
|
||||
if (id && type && durationRef.current > 0) {
|
||||
logger.log('[useWatchProgress] App backgrounded, saving progress');
|
||||
|
||||
// Local save
|
||||
if (id && type && durationRef.current > 0) {
|
||||
if (nextAppState === 'background') {
|
||||
// App is truly backgrounded — save progress and end Trakt session
|
||||
logger.log('[useWatchProgress] App backgrounded, saving progress and ending Trakt session');
|
||||
const progress = {
|
||||
currentTime: currentTimeRef.current,
|
||||
duration: durationRef.current,
|
||||
|
|
@ -101,14 +100,21 @@ export const useWatchProgress = (
|
|||
if (isInPictureInPictureRef.current) {
|
||||
logger.log('[useWatchProgress] In PiP mode, skipping background playback end sync');
|
||||
} else {
|
||||
// Trakt sync (end session)
|
||||
// Use 'user_close' to force immediate sync
|
||||
await traktAutosyncRef.current.handlePlaybackEnd(currentTimeRef.current, durationRef.current, 'user_close');
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error('[useWatchProgress] Error saving background progress:', error);
|
||||
}
|
||||
} else if (nextAppState === 'active') {
|
||||
// App returned to foreground — re-open the Trakt session if not complete.
|
||||
// Use resumeSession (not handlePlaybackStart) so hasStopped is cleared first.
|
||||
if (!isInPictureInPictureRef.current) {
|
||||
logger.log('[useWatchProgress] App foregrounded, re-opening Trakt session');
|
||||
traktAutosyncRef.current.resumeSession(currentTimeRef.current, durationRef.current);
|
||||
}
|
||||
}
|
||||
// 'inactive' is intentionally ignored — it fires for notification shade,
|
||||
// screen dim, system dialogs etc. and should not end the Trakt session.
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -162,7 +168,7 @@ export const useWatchProgress = (
|
|||
};
|
||||
try {
|
||||
await storageService.setWatchProgress(id, type, progress, episodeId);
|
||||
await traktAutosync.handleProgressUpdate(currentTimeRef.current, durationRef.current);
|
||||
await traktAutosyncRef.current.handleProgressUpdate(currentTimeRef.current, durationRef.current);
|
||||
|
||||
// Requirement 1: Auto Episode Tracking (>= 90% completion)
|
||||
const progressPercent = (currentTimeRef.current / durationRef.current) * 100;
|
||||
|
|
|
|||
Loading…
Reference in a new issue