Timer flash: blink the real theme instead of a black/white overlay, skip it while the app is backgrounded

The completion alert (Settings → "Flash screen when timer ends") laid an
opaque black/white rectangle over the whole screen, so the app's own UI
flickered into view between pulses. It now flips document.documentElement's
data-theme (light/dark) three times and settles back on whatever theme the
user actually had — same duration, no overlay, no rectangle. Fully dark ->
light, dark, light; fully light -> dark, light, dark; either way it lands
back where it started.

Separately: the rest/work timers reuse their tick on 'visibilitychange' to
stay accurate after the tab is throttled in the background. That reuse had
a side effect — reopening the app (or the tab regaining focus) after the
countdown had already finished while hidden replayed the completion beep,
vibration, flash and toast, even though nothing was actually watching when
it ended. Now those perceptible effects only fire if the countdown reaches
zero while the app is genuinely visible; finishing hidden only sends the
existing push notification, and reopening later stays silent.
This commit is contained in:
mzspicoli committed 2026-09-02 07:27:30 +02:00
1 parent 272bf785ee
commit ad4bee99be
4 files changed
+72 -21

No files matched your search

+17 -3
View File
@@ -1,8 +1,22 @@
import { useEffect } from 'react'
import { useUI } from '../store/useUI.js'
// A new key restarts the CSS sequence even when two timers finish close together.
// The layer never catches taps and ends transparent, so it can safely stay mounted.
// Flips the app's real light/dark theme on and off twice (~2.4s) instead of laying an
// opaque black/white rectangle over the screen — the alert reads as the app itself
// blinking, and it always settles back on whatever theme the user actually had.
export default function TimerFlash() {
const id = useUI(s => s.timerFlashId)
return id ? <div key={id} className="timer-flash" aria-hidden="true" /> : null
useEffect(() => {
if (!id) return
const de = document.documentElement
const original = de.dataset.theme
const opposite = original === 'light' ? 'dark' : 'light'
const steps = [opposite, original, opposite, original]
const timers = steps.map((theme, i) => setTimeout(() => { de.dataset.theme = theme }, i * 600))
return () => {
timers.forEach(clearTimeout)
de.dataset.theme = original
}
}, [id])
return null
}