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.

Sign-out keeps a running workout and stops the rest and hold timers

Duarte Santosb35c7ca89984
diff --git a/frontend/src/locales/ar.js b/frontend/src/locales/ar.js
index bf3326b96..89c2b06be 100644
--- a/frontend/src/locales/ar.js
+++ b/frontend/src/locales/ar.js
@@ -285,6 +285,7 @@ export default {
'Sign out?': 'تسجيل الخروج؟',
'Sign out': 'تسجيل الخروج',
'Sign out everywhere?': 'تسجيل الخروج من كل الأجهزة؟',
+ 'You have a workout running. It waits on this device until you’re back on this account.': 'لديك تمرين قيد التشغيل. سينتظرك على هذا الجهاز حتى تعود إلى هذا الحساب.',
'Sign out everywhere': 'تسجيل الخروج من كل الأجهزة',
'Ends this profile’s sessions on all your devices.': 'ينهي جلسات هذا الملف الشخصي على جميع أجهزتك.',
'Signed out on all devices': 'تم تسجيل الخروج من جميع الأجهزة',
diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js
index de5d852d3..f637aa39c 100644
--- a/frontend/src/locales/de.js
+++ b/frontend/src/locales/de.js
@@ -426,6 +426,7 @@ export default {
'Sign out?': 'Abmelden?',
'Sign out': 'Abmelden',
'Sign out everywhere?': 'Überall abmelden?',
+ 'You have a workout running. It waits on this device until you’re back on this account.': 'Du hast ein Training am Laufen. Es wartet auf diesem Gerät, bis du mit diesem Konto zurück bist.',
'Sign out everywhere': 'Überall abmelden',
'Account ID': 'Konto-ID',
'Account ID copied': 'Konto-ID kopiert',
diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js
index 6d31f6eb3..39051c02c 100644
--- a/frontend/src/locales/es.js
+++ b/frontend/src/locales/es.js
@@ -411,6 +411,7 @@ export default {
'Sign out?': '¿Cerrar sesión?',
'Sign out': 'Cerrar sesión',
'Sign out everywhere?': '¿Cerrar sesión en todos los dispositivos?',
+ 'You have a workout running. It waits on this device until you’re back on this account.': 'Tienes un entrenamiento en curso. Te espera en este dispositivo hasta que vuelvas a esta cuenta.',
'Sign out everywhere': 'Cerrar sesión en todos los dispositivos',
'Account ID': 'ID de la cuenta',
'Account ID copied': 'ID de la cuenta copiado',
diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js
index bcb58b68c..9ed82f20c 100644
--- a/frontend/src/locales/fr.js
+++ b/frontend/src/locales/fr.js
@@ -411,6 +411,7 @@ export default {
'Sign out?': 'Se déconnecter ?',
'Sign out': 'Se déconnecter',
'Sign out everywhere?': 'Se déconnecter partout ?',
+ 'You have a workout running. It waits on this device until you’re back on this account.': 'Tu as une séance en cours. Elle t’attend sur cet appareil jusqu’à ton retour sur ce compte.',
'Sign out everywhere': 'Se déconnecter partout',
'Account ID': 'Identifiant du compte',
'Account ID copied': 'Identifiant du compte copié',
diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js
index 1d6a448d7..69cd115e0 100644
--- a/frontend/src/locales/hi.js
+++ b/frontend/src/locales/hi.js
@@ -411,6 +411,7 @@ export default {
'Sign out?': 'साइन आउट करें?',
'Sign out': 'साइन आउट',
'Sign out everywhere?': 'हर जगह साइन आउट करें?',
+ 'You have a workout running. It waits on this device until you’re back on this account.': 'आपका एक वर्कआउट चल रहा है। यह इस डिवाइस पर तब तक इंतज़ार करेगा जब तक आप इस अकाउंट में वापस नहीं आते।',
'Sign out everywhere': 'हर जगह साइन आउट करें',
'Account ID': 'खाता ID',
'Account ID copied': 'खाता ID कॉपी हो गया',
diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.js
index 910fb065f..52defecf4 100644
--- a/frontend/src/locales/hu.js
+++ b/frontend/src/locales/hu.js
@@ -417,6 +417,7 @@ export default {
'Sign out?': 'Kijelentkezel?',
'Sign out': 'Kijelentkezés',
'Sign out everywhere?': 'Kijelentkezel mindenhonnan?',
+ 'You have a workout running. It waits on this device until you’re back on this account.': 'Fut egy edzésed. Ezen az eszközön vár rád, amíg vissza nem jössz ezzel a fiókkal.',
'Sign out everywhere': 'Kijelentkezés mindenhonnan',
'Account ID': 'Fiókazonosító',
'Account ID copied': 'Fiókazonosító kimásolva',
diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js
index 6c505e2b7..396aa5192 100644
--- a/frontend/src/locales/it.js
+++ b/frontend/src/locales/it.js
@@ -411,6 +411,7 @@ export default {
'Sign out?': 'Uscire?',
'Sign out': 'Esci',
'Sign out everywhere?': 'Uscire ovunque?',
+ 'You have a workout running. It waits on this device until you’re back on this account.': 'Hai un allenamento in corso. Ti aspetta su questo dispositivo finché non torni su questo account.',
'Sign out everywhere': 'Esci ovunque',
'Account ID': 'ID account',
'Account ID copied': 'ID account copiato',
diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js
index 79d4a7cff..c39b52817 100644
--- a/frontend/src/locales/ko.js
+++ b/frontend/src/locales/ko.js
@@ -411,6 +411,7 @@ export default {
'Sign out?': '로그아웃할까요?',
'Sign out': '로그아웃',
'Sign out everywhere?': '모든 기기에서 로그아웃할까요?',
+ 'You have a workout running. It waits on this device until you’re back on this account.': '진행 중인 운동이 있습니다. 이 계정으로 돌아올 때까지 이 기기에서 기다립니다.',
'Sign out everywhere': '모든 기기에서 로그아웃',
'Account ID': '계정 ID',
'Account ID copied': '계정 ID를 복사했습니다',
diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js
index 4f97fb8ef..029d5a2d9 100644
--- a/frontend/src/locales/pl.js
+++ b/frontend/src/locales/pl.js
@@ -411,6 +411,7 @@ export default {
'Sign out?': 'Wylogować?',
'Sign out': 'Wyloguj',
'Sign out everywhere?': 'Wylogować wszędzie?',
+ 'You have a workout running. It waits on this device until you’re back on this account.': 'Masz trwający trening. Poczeka na tym urządzeniu, aż wrócisz na to konto.',
'Sign out everywhere': 'Wyloguj wszędzie',
'Account ID': 'ID konta',
'Account ID copied': 'Skopiowano ID konta',
diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.js
index 18b847bc6..f974bf202 100644
--- a/frontend/src/locales/pt-BR.js
+++ b/frontend/src/locales/pt-BR.js
@@ -130,6 +130,7 @@ export const PT_BR_OVERRIDES = {
'Sign out?': 'Sair?',
'Sign out': 'Sair',
'Sign out everywhere?': 'Sair de todos os dispositivos?',
+ 'You have a workout running. It waits on this device until you’re back on this account.': 'Você tem um treino em andamento. Ele fica esperando neste dispositivo até você voltar para esta conta.',
'Sign out everywhere': 'Sair de todos os dispositivos',
'Ends this profile’s sessions on all your devices.': 'Encerra as sessões deste perfil em todos os seus dispositivos.',
'Signed out on all devices': 'Sessão encerrada em todos os dispositivos',
diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js
index d1511247e..795c6e5cb 100644
--- a/frontend/src/locales/pt.js
+++ b/frontend/src/locales/pt.js
@@ -411,6 +411,7 @@ export default {
'Sign out?': 'Terminar sessão?',
'Sign out': 'Terminar sessão',
'Sign out everywhere?': 'Terminar sessão em todos os dispositivos?',
+ 'You have a workout running. It waits on this device until you’re back on this account.': 'Tens um treino a decorrer. Fica à tua espera neste dispositivo até voltares a esta conta.',
'Sign out everywhere': 'Terminar sessão em todos os dispositivos',
'Account ID': 'ID da conta',
'Account ID copied': 'ID da conta copiado',
diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js
index 92357e138..826824c89 100644
--- a/frontend/src/locales/ru.js
+++ b/frontend/src/locales/ru.js
@@ -401,6 +401,7 @@ export default {
'Sign out?': 'Выйти?',
'Sign out': 'Выйти',
'Sign out everywhere?': 'Выйти на всех устройствах?',
+ 'You have a workout running. It waits on this device until you’re back on this account.': 'У тебя идёт тренировка. Она подождёт на этом устройстве, пока ты не вернёшься в этот аккаунт.',
'Sign out everywhere': 'Выйти на всех устройствах',
'Account ID': 'ID аккаунта',
'Account ID copied': 'ID аккаунта скопирован',
diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.js
index b57fc0e62..321a6c72a 100644
--- a/frontend/src/locales/th.js
+++ b/frontend/src/locales/th.js
@@ -417,6 +417,7 @@ export default {
'Sign out?': 'ออกจากระบบ?',
'Sign out': 'ออกจากระบบ',
'Sign out everywhere?': 'ออกจากระบบทุกอุปกรณ์?',
+ 'You have a workout running. It waits on this device until you’re back on this account.': 'คุณมีการออกกำลังกายที่กำลังดำเนินอยู่ ซึ่งจะรออยู่บนอุปกรณ์นี้จนกว่าคุณจะกลับมาที่บัญชีนี้',
'Sign out everywhere': 'ออกจากระบบทุกอุปกรณ์',
'Account ID': 'ID บัญชี',
'Account ID copied': 'คัดลอก ID บัญชีแล้ว',
diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js
index b2287d911..a1a9b0987 100644
--- a/frontend/src/locales/tr.js
+++ b/frontend/src/locales/tr.js
@@ -411,6 +411,7 @@ export default {
'Sign out?': 'Çıkış yapılsın mı?',
'Sign out': 'Çıkış yap',
'Sign out everywhere?': 'Her yerden çıkış yapılsın mı?',
+ 'You have a workout running. It waits on this device until you’re back on this account.': 'Devam eden bir antrenmanın var. Bu hesaba geri dönene kadar bu cihazda seni bekler.',
'Sign out everywhere': 'Her yerden çıkış yap',
'Account ID': 'Hesap kimliği',
'Account ID copied': 'Hesap kimliği kopyalandı',
diff --git a/frontend/src/locales/uk.js b/frontend/src/locales/uk.js
index 582084a5d..1b14737c1 100644
--- a/frontend/src/locales/uk.js
+++ b/frontend/src/locales/uk.js
@@ -267,6 +267,7 @@ export default {
'Sign out?': 'Вийти?',
'Sign out': 'Вийти',
'Sign out everywhere?': 'Вийти на всіх пристроях?',
+ 'You have a workout running. It waits on this device until you’re back on this account.': 'У тебе триває тренування. Воно чекатиме на цьому пристрої, доки ти не повернешся в цей акаунт.',
'Sign out everywhere': 'Вийти на всіх пристроях',
'Ends this profile’s sessions on all your devices.': 'Завершує сеанси цього профілю на всіх твоїх пристроях.',
'Signed out on all devices': 'Вихід виконано на всіх пристроях',
diff --git a/frontend/src/locales/zh-TW.js b/frontend/src/locales/zh-TW.js
index 6026efbfa..bf01451cd 100644
--- a/frontend/src/locales/zh-TW.js
+++ b/frontend/src/locales/zh-TW.js
@@ -407,6 +407,7 @@ export default {
'Sign out?': '確定要登出嗎?',
'Sign out': '登出',
'Sign out everywhere?': '在所有裝置上登出?',
+ 'You have a workout running. It waits on this device until you’re back on this account.': '你有一個進行中的訓練。它會留在這台裝置上,等你回到這個帳號。',
'Sign out everywhere': '所有裝置全部登出',
'Account ID': '帳號 ID',
'Account ID copied': '已複製帳號 ID',
diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js
index ba71b561f..312685c42 100644
--- a/frontend/src/locales/zh.js
+++ b/frontend/src/locales/zh.js
@@ -411,6 +411,7 @@ export default {
'Sign out?': '退出登录?',
'Sign out': '退出登录',
'Sign out everywhere?': '在所有设备上退出登录?',
+ 'You have a workout running. It waits on this device until you’re back on this account.': '你有一个正在进行的训练。它会留在这台设备上,等你回到这个账户。',
'Sign out everywhere': '在所有设备上退出登录',
'Account ID': '账号 ID',
'Account ID copied': '已复制账号 ID',
diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.js
index c5abff5d7..4d4b2ee19 100644
--- a/frontend/src/store/useStore.js
+++ b/frontend/src/store/useStore.js
@@ -765,6 +765,34 @@ export const useStore = create((set, get) => {
all[key] = { server: server || null, uid: user.id, name: user.name || '', at: Date.now(), state }
return writeStashes(all)
}
+ // A workout running here is never on the server (a push leaves `active` out), so a sign-out
+ // with nothing owed used to wipe it. It is kept aside the way owed changes are, on its own:
+ // the rest of the copy is the server's already, and a shared device keeps no more of the
+ // account than it has to. It comes back on the next sign-in here as this account (applyStash).
+ const stashActive = async () => {
+ const user = get().user
+ const a = get().S.active
+ if (!user || !a) return true
+ const all = await readStashes()
+ const server = serverBase()
+ const key = stashKey(server, user.id)
+ const prev = all[key]?.state
+ const state = prev ? clone(prev) : Object.assign(clone(DEF), { _ts: 0, unit: get().S.unit || 'kg' })
+ state.active = clone(a)
+ all[key] = { server: server || null, uid: user.id, name: user.name || '', at: Date.now(), state }
+ return writeStashes(all)
+ }
+ // A sign-out ends the rest and the hold running on this device: the countdown must not go on
+ // over the sign-in screen, or ring for an account that has left. Before the logout request,
+ // while the session can still call the server push off. A hold hands back what it held first.
+ const stopTimers = async () => {
+ try {
+ const ui = (await import('./useUI.js')).useUI.getState()
+ ui.abandonWork?.()
+ ui.stopRest?.()
+ } catch { /* no timers to stop */ }
+ }
+
// Back on the server and account a forced sign-out or disconnect left: the kept changes are
// merged in like a conflict (lib/sync-merge.js), marked owed and pushed, and the stash goes.
// If the push does not land, the copy itself owes them from here and nothing wipes it.
@@ -1343,12 +1371,15 @@ export const useStore = create((set, get) => {
export, or going ahead anyway. `force` goes ahead: the owed copy is kept aside on this
device (stashOwed) and comes back when it next reaches this server as this account. If
even that cannot be written, nothing is wiped ({ owed, count, stashed: false }).
- Otherwise { owed: false } or { owed: true, count, stashed: true }, signed out. */
+ Otherwise { owed: false } or { owed: true, count, stashed: true }, signed out. A workout
+ running here is kept aside either way (stashActive), and the rest and hold timers stop. */
async signOut({ force = false } = {}) {
await settle()
const left = get().unsyncedChanges()
if (left.owed && !force) return owedResult(left)
+ await stopTimers()
if (left.owed && !(await stashOwed())) return owedResult(left, { stashed: false })
+ if (!left.owed && !(await stashActive())) return { owed: true, count: 0, stashed: false }
// The device is signed out either way. A request that did not get through leaves the cookie
// behind, still valid, so the logout is owed until the server answers it (see boot).
try { await api('/api/logout', { method: 'POST', body: '{}' }) } catch (e) { if (!MOBILE) logoutOwed(true) }
@@ -1403,8 +1434,10 @@ export const useStore = create((set, get) => {
await settle()
const left = get().unsyncedChanges()
if (left.owed && !force) return owedResult(left)
+ await stopTimers()
await api('/api/logout/all', { method: 'POST', body: '{}' })
if (left.owed && !(await stashOwed())) return owedResult(left, { stashed: false })
+ if (!left.owed && !(await stashActive())) return { owed: true, count: 0, stashed: false }
await clearLocalSession()
return left.owed ? owedResult(left, { stashed: true }) : { owed: false }
},
diff --git a/frontend/src/store/useStore.sync-status.test.jsx b/frontend/src/store/useStore.sync-status.test.jsx
index 15005d761..6f9f00de1 100644
--- a/frontend/src/store/useStore.sync-status.test.jsx
+++ b/frontend/src/store/useStore.sync-status.test.jsx
@@ -8,8 +8,8 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
vi.mock('../lib/api.js', () => ({ api: vi.fn(), setRemoteAuth: vi.fn() }))
-const { toast } = vi.hoisted(() => ({ toast: vi.fn() }))
-vi.mock('./useUI.js', () => ({ useUI: { getState: () => ({ toast }) } }))
+const { toast, stopRest, abandonWork } = vi.hoisted(() => ({ toast: vi.fn(), stopRest: vi.fn(), abandonWork: vi.fn() }))
+vi.mock('./useUI.js', () => ({ useUI: { getState: () => ({ toast, stopRest, abandonWork }) } }))
import { api } from '../lib/api.js'
import { DEF, useStore } from './useStore.js'
@@ -252,6 +252,48 @@ describe('signing out never loses a change silently', () => {
expect(useStore.getState().user).toEqual(USER)
})
+ it('a workout running with nothing owed is kept on this device and back on the next sign-in', async () => {
+ owedCopy()
+ await new Promise(r => setTimeout(r, 10))
+ useStore.getState().update(s => { s.active = { id: 'run', start: 5, entries: [{ id: 'squat', sets: [{ w: 100, r: 5, done: true }] }] } })
+ api.mockReset()
+ api.mockResolvedValue({ ok: true, rev: 1 })
+ expect(useStore.getState().unsyncedChanges().owed).toBe(false)
+ expect(await useStore.getState().signOut()).toEqual({ owed: false })
+ expect(useStore.getState().S.active).toBeNull()
+ const stash = Object.values(JSON.parse(localStorage.getItem('gym_stash')))
+ expect(stash.map(e => [e.uid, e.state.active?.id, ids(e.state.workouts)])).toEqual([[USER.id, 'run', []]])
+
+ api.mockReset()
+ api.mockImplementation(async (path, o) => (o?.method === 'PUT' ? { ok: true, rev: 3 } : { state: { ...clone(DEF), _ts: 200, workouts: [workout('w1')], _rev: 2 }, rev: 2 }))
+ useStore.getState().setUser(USER)
+ await useStore.getState().adoptProfile(async () => false)
+ expect(useStore.getState().S.active?.id).toBe('run')
+ expect(useStore.getState().S.active.entries[0].sets[0].done).toBe(true)
+ expect(ids(useStore.getState().S.workouts)).toEqual(['w1'])
+ expect(localStorage.getItem('gym_stash')).toBeNull()
+ })
+
+ it('stops the rest and the hold before the logout request, so the push can still be called off', async () => {
+ owedCopy()
+ await new Promise(r => setTimeout(r, 10))
+ api.mockReset(); stopRest.mockClear(); abandonWork.mockClear()
+ api.mockResolvedValue({ ok: true, rev: 1 })
+ await useStore.getState().signOut()
+ expect(stopRest).toHaveBeenCalledTimes(1)
+ expect(abandonWork).toHaveBeenCalledTimes(1)
+ const logout = api.mock.calls.findIndex(([p]) => p === '/api/logout')
+ expect(stopRest.mock.invocationCallOrder[0]).toBeLessThan(api.mock.invocationCallOrder[logout])
+
+ owedCopy()
+ await new Promise(r => setTimeout(r, 10))
+ api.mockReset(); stopRest.mockClear()
+ api.mockResolvedValue({ ok: true, rev: 1 })
+ await useStore.getState().signOutAll()
+ const all = api.mock.calls.findIndex(([p]) => p === '/api/logout/all')
+ expect(stopRest.mock.invocationCallOrder[0]).toBeLessThan(api.mock.invocationCallOrder[all])
+ })
+
it('unsyncedChanges says nothing is owed when nothing is', async () => {
owedCopy()
await new Promise(r => setTimeout(r, 10))
diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsx
index 1b006a3ef..60d909847 100644
--- a/frontend/src/views/Settings.jsx
+++ b/frontend/src/views/Settings.jsx
@@ -337,22 +337,24 @@ export default function Settings({ page = null, find = null, via = null }) {
sign in with, so they have to be paired again, and the confirm says so. Failing, it touches
nothing local: still signed in here, and the toast says so. */
const kept = t('The changes your server has not seen are kept on this device, and added back when it connects as this account again.')
+ // A workout running here is kept aside by the sign-out (useStore stashActive): the confirm says so.
+ const running = () => S.active ? ' ' + t('You have a workout running. It waits on this device until you’re back on this account.') : ''
const leave = (kind, after) => leaveServer(kind, { exportBackup: doExport, exportBackupZip: doExportZip, done: r => { nav('/home'); if (r.stashed) toast(kept); else if (after) toast(after) } })
const disconnect = () => confirmSheet({
title: t('Disconnect from your server?'),
- message: t('This phone switches back to local-only and its copy of your account is removed. First it checks that your server has every change. If not, you choose what happens to them.'),
+ message: t('This phone switches back to local-only and its copy of your account is removed. First it checks that your server has every change. If not, you choose what happens to them.') + running(),
confirmText: t('Disconnect'), danger: true,
onConfirm: () => leave('disconnect', t('Disconnected. Back to local-only')),
})
const signOutHere = () => confirmSheet({
title: t('Sign out?'),
- message: t('Your data is removed from this browser; your profile on the server keeps it. First it checks that the server has every change. If not, you choose what happens to them.'),
+ message: t('Your data is removed from this browser; your profile on the server keeps it. First it checks that the server has every change. If not, you choose what happens to them.') + running(),
confirmText: t('Sign out'), danger: true,
onConfirm: () => leave('signout'),
})
const signOutEverywhere = () => confirmSheet({
title: t('Sign out everywhere?'),
- message: t('Signs this profile out on every device, including this one. Phones paired with it are disconnected and have to be paired again. Your passkeys keep working, so you can sign in with them again anytime.'),
+ message: t('Signs this profile out on every device, including this one. Phones paired with it are disconnected and have to be paired again. Your passkeys keep working, so you can sign in with them again anytime.') + running(),
confirmText: t('Sign out everywhere'), danger: true,
onConfirm: () => leave('everywhere', t('Signed out on all devices')),
})