Merge pull request #151 from R0m1k3/claude/fix-pomodoro-tab-switch-01WFQEsfPro5ynAgg4VAU3EV

fix: permettre au timer Pomodoro de continuer en arrière-plan
This commit is contained in:
LogiFlow authored and GitHub committed 2025-11-29 09:24:28 +01:00
commit 03986c2547
1 file changed
+27
+27
View File
@@ -73,6 +73,33 @@ export function PomodoroTimer({ onStateChange }: PomodoroTimerProps = {}) {
window.dispatchEvent(new CustomEvent('pomodoroStateChange'));
}, [endTime]);
// Restore timer state on mount if it was running
useEffect(() => {
// Clean up invalid states on mount
if (isRunning && endTime === null) {
// If running but no endTime, stop the timer
setIsRunning(false);
setTimeLeft(TIMER_DURATIONS[mode]);
} else if (endTime !== null && isRunning) {
// Recalculate remaining time based on endTime
const now = Date.now();
const remaining = Math.max(0, Math.ceil((endTime - now) / 1000));
if (remaining > 0) {
setTimeLeft(remaining);
} else {
// Timer expired while page was closed/reloaded
setIsRunning(false);
setEndTime(null);
setTimeLeft(0);
}
} else if (endTime !== null && !isRunning) {
// If paused with an endTime, clean up the endTime
setEndTime(null);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []); // Run only on mount
// Listen for localStorage changes from other instances
useEffect(() => {
const handleStorageChange = () => {