mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-17 15:32:01 +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
|
// AppState Listener for background save
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const subscription = AppState.addEventListener('change', async (nextAppState) => {
|
const subscription = AppState.addEventListener('change', async (nextAppState) => {
|
||||||
if (nextAppState.match(/inactive|background/)) {
|
if (id && type && durationRef.current > 0) {
|
||||||
if (id && type && durationRef.current > 0) {
|
if (nextAppState === 'background') {
|
||||||
logger.log('[useWatchProgress] App backgrounded, saving progress');
|
// App is truly backgrounded — save progress and end Trakt session
|
||||||
|
logger.log('[useWatchProgress] App backgrounded, saving progress and ending Trakt session');
|
||||||
// Local save
|
|
||||||
const progress = {
|
const progress = {
|
||||||
currentTime: currentTimeRef.current,
|
currentTime: currentTimeRef.current,
|
||||||
duration: durationRef.current,
|
duration: durationRef.current,
|
||||||
|
|
@ -101,14 +100,21 @@ export const useWatchProgress = (
|
||||||
if (isInPictureInPictureRef.current) {
|
if (isInPictureInPictureRef.current) {
|
||||||
logger.log('[useWatchProgress] In PiP mode, skipping background playback end sync');
|
logger.log('[useWatchProgress] In PiP mode, skipping background playback end sync');
|
||||||
} else {
|
} else {
|
||||||
// Trakt sync (end session)
|
|
||||||
// Use 'user_close' to force immediate sync
|
|
||||||
await traktAutosyncRef.current.handlePlaybackEnd(currentTimeRef.current, durationRef.current, 'user_close');
|
await traktAutosyncRef.current.handlePlaybackEnd(currentTimeRef.current, durationRef.current, 'user_close');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('[useWatchProgress] Error saving background progress:', 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 {
|
try {
|
||||||
await storageService.setWatchProgress(id, type, progress, episodeId);
|
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)
|
// Requirement 1: Auto Episode Tracking (>= 90% completion)
|
||||||
const progressPercent = (currentTimeRef.current / durationRef.current) * 100;
|
const progressPercent = (currentTimeRef.current / durationRef.current) * 100;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue