Trakt scrobble big fix

This commit is contained in:
tapframe 2025-12-20 20:49:20 +05:30
parent b2a9708856
commit dda34b6982
3 changed files with 39 additions and 25 deletions

View file

@ -1160,15 +1160,29 @@ const AndroidVideoPlayer: React.FC = () => {
}
}, [id, type, paused, currentTime, duration]);
// Use refs to track latest values for unmount cleanup without causing effect re-runs
const currentTimeRef = useRef(currentTime);
const durationRef = useRef(duration);
// Keep refs updated with latest values
useEffect(() => {
currentTimeRef.current = currentTime;
}, [currentTime]);
useEffect(() => {
durationRef.current = duration;
}, [duration]);
// Cleanup effect - only runs on actual component unmount
useEffect(() => {
return () => {
if (id && type && duration > 0) {
if (id && type && durationRef.current > 0) {
saveWatchProgress();
// Final Trakt sync on component unmount
traktAutosync.handlePlaybackEnd(currentTime, duration, 'unmount');
traktAutosync.handlePlaybackEnd(currentTimeRef.current, durationRef.current, 'unmount');
}
};
}, [id, type, currentTime, duration]);
}, [id, type]); // Only id and type - NOT currentTime or duration
const seekToTime = (rawSeconds: number) => {
// Clamp to just before the end of the media.

View file

@ -838,15 +838,29 @@ const KSPlayerCore: React.FC = () => {
}
}, [id, type, paused, duration]);
// Use refs to track latest values for unmount cleanup without causing effect re-runs
const currentTimeRef = useRef(currentTime);
const durationRef = useRef(duration);
// Keep refs updated with latest values
useEffect(() => {
currentTimeRef.current = currentTime;
}, [currentTime]);
useEffect(() => {
durationRef.current = duration;
}, [duration]);
// Cleanup effect - only runs on actual component unmount
useEffect(() => {
return () => {
if (id && type && duration > 0) {
if (id && type && durationRef.current > 0) {
saveWatchProgress();
// Final Trakt sync on component unmount
traktAutosync.handlePlaybackEnd(currentTime, duration, 'unmount');
traktAutosync.handlePlaybackEnd(currentTimeRef.current, durationRef.current, 'unmount');
}
};
}, [id, type, currentTime, duration]);
}, [id, type]); // Only id and type - NOT currentTime or duration
const onPlaying = () => {
if (isMounted.current && !isSeeking.current) {

View file

@ -81,22 +81,8 @@ const UpNextButton: React.FC<UpNextButtonProps> = ({
return timeRemaining < 61 && timeRemaining > 10;
}, [nextEpisode, duration, currentTime]);
// Debug log inputs and computed state on changes
useEffect(() => {
try {
const timeRemaining = duration - currentTime;
logger.log('[UpNextButton] state', {
hasNextEpisode: !!nextEpisode,
currentTime,
duration,
timeRemaining,
isLoading,
shouldShow,
controlsVisible,
controlsFixedOffset,
});
} catch {}
}, [nextEpisode, currentTime, duration, isLoading, shouldShow, controlsVisible, controlsFixedOffset]);
// Debug logging removed to reduce console noise
// The state is computed in shouldShow useMemo above
useEffect(() => {
if (shouldShow && !visible) {