Skip to content

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.

Flush pending state save immediately when tab backgrounds/closes

Duarte Santos10fa150d091e
diff --git a/api/server.js b/api/server.js
index da11acf35..d8f2d6c85 100644
--- a/api/server.js
+++ b/api/server.js
@@ -116,6 +116,7 @@ setInterval(() => {
const rid = effectiveRoutineId(S, now.date);
if (!rid) continue; // rest day — nothing planned
const routine = (S.routines || []).find(r => r.id === rid);
+ console.log('reminder firing', user.id, rid);
user.lastReminder = now.date;
saveDb();
sendPush(user.id, {
diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.js
index 02b364a2b..490004f8a 100644
--- a/frontend/src/store/useStore.js
+++ b/frontend/src/store/useStore.js
@@ -35,6 +35,16 @@ export const useStore = create((set, get) => {
}
}
+ // A setting changed right before switching away/closing the tab must not get lost mid-debounce
+ // (e.g. setting the reminder time then immediately backgrounding to test it).
+ document.addEventListener('visibilitychange', () => {
+ if (document.visibilityState === 'hidden' && pushTm) {
+ clearTimeout(pushTm)
+ pushTm = null
+ get().pushState()
+ }
+ })
+
return {
S: loadState(),
user: (() => { try { return JSON.parse(localStorage.getItem('gym_user')) || null } catch { return null } })(),