Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
timer: a hide from before the timer is not a countdown you missed
Boris 'B' Kurktchiev16e747415438
diff --git a/frontend/src/store/useUI.js b/frontend/src/store/useUI.jsindex 01ce0feba..ae8380ee1 100644--- a/frontend/src/store/useUI.js+++ b/frontend/src/store/useUI.js@@ -98,6 +98,11 @@ export const useUI = create((set, get) => ({// Rest timer set to Off. Stopping and returning rather than starting a zero-length timer// keeps every caller honest: the four places that start a rest do not each need to know.if (!(sec > 0)) return+ // Nothing clears pageHiddenAt but a tick, so an app switch with no timer running left it set+ // for good. The next timer's first tick then read it as "this countdown ran out while the app+ // was away" and finished in silence — a one-second rest, started on screen, over on screen,+ // with no beep, no vibration and no flash. Each timer starts from where the page is now.+ pageHiddenAt = document.hidden ? Date.now() : nullconst endsAt = Date.now() + sec * 1000set({ timer: { left: sec, total: sec, endsAt, forIdx } })pushRestTimer(sec)@@ -164,6 +169,7 @@ export const useUI = create((set, get) => ({const total = Math.max(1, Math.round(sec) || 1)const endsAt = Date.now() + total * 1000workDone = onDone+ pageHiddenAt = document.hidden ? Date.now() : null // see startRest: a stale hide is not a catch-upset({ work: { left: total, total, endsAt, label } })workTick = () => {const wk = get().workdiff --git a/frontend/src/store/useUI.test.js b/frontend/src/store/useUI.test.jsindex 89f936d2f..df8de7b4c 100644--- a/frontend/src/store/useUI.test.js+++ b/frontend/src/store/useUI.test.js@@ -95,6 +95,26 @@ describe('opt-in timer screen flash', () => {vi.advanceTimersByTime(1000)expect(useUI.getState().timerFlashId).toBe(1)})++ // Nothing clears the "the app went away" mark but a tick, so an app switch with no timer+ // running left it set for good and the next timer read it as a catch-up on its very first tick.+ // Only a timer short enough to finish on that first tick can hit it, which is why it went+ // unnoticed: a one-second rest, started on screen and over on screen, ran out in silence.+ it('a hide and a show BEFORE the rest starts is no catch-up: it still flashes', () => {+ useStore.setState({ S: { ...useStore.getState().S, timerFlash: true } })+ goHidden(); goVisible() // switched apps and came back, with no timer running+ useUI.getState().startRest(1)+ vi.advanceTimersByTime(1000)+ expect(useUI.getState().timerFlashId).toBe(1)+ })++ it('a hide and a show BEFORE the hold starts is no catch-up: it still flashes', () => {+ useStore.setState({ S: { ...useStore.getState().S, timerFlash: true } })+ goHidden(); goVisible() // switched apps and came back, with no timer running+ useUI.getState().startWork(1, 'Plank', vi.fn())+ vi.advanceTimersByTime(1000)+ expect(useUI.getState().timerFlashId).toBe(1)+ })})// The rest and the hold mean opposite things and the store has always said so, but only