diff --git a/frontend/src/store/useUI.js b/frontend/src/store/useUI.js index d1a121a..53d2928 100644 --- a/frontend/src/store/useUI.js +++ b/frontend/src/store/useUI.js @@ -76,6 +76,9 @@ export const useUI = create((set, get) => ({ startRest(sec) { get().stopRest() + // 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 const endsAt = Date.now() + sec * 1000 set({ timer: { left: sec, total: sec, endsAt } }) requestRestNotificationPermission() diff --git a/frontend/src/store/useUI.test.js b/frontend/src/store/useUI.test.js new file mode 100644 index 0000000..32c9a1c --- /dev/null +++ b/frontend/src/store/useUI.test.js @@ -0,0 +1,28 @@ +// @vitest-environment happy-dom +// useUI pulls in api.js, which reads navigator.userAgent at module scope. +import { describe, expect, it, beforeEach, afterEach, vi } from 'vitest' +import { useUI } from './useUI.js' + +// "Off" has to hold at the timer itself, not at the four places that start one — the same +// reason the rest-after-a-set rule is a shared condition rather than four copies. +describe('rest timer set to Off', () => { + beforeEach(() => { vi.useFakeTimers(); useUI.setState({ timer: null }) }) + afterEach(() => { useUI.getState().stopRest(); vi.useRealTimers() }) + + it('starts nothing', () => { + useUI.getState().startRest(0) + expect(useUI.getState().timer).toBe(null) + }) + + it('stops a rest that is already running', () => { + useUI.getState().startRest(90) + expect(useUI.getState().timer).not.toBe(null) + useUI.getState().startRest(0) + expect(useUI.getState().timer).toBe(null) + }) + + it('still runs for a real duration', () => { + useUI.getState().startRest(90) + expect(useUI.getState().timer.total).toBe(90) + }) +}) diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsx index eb2d053..2f4c0a4 100644 --- a/frontend/src/views/Settings.jsx +++ b/frontend/src/views/Settings.jsx @@ -131,7 +131,7 @@ export default function Settings() {
update(s => { s.restSec = v })} - options={[60, 90, 120, 150, 180].map(v => ({ value: v, label: v + 's' }))} /> + options={[{ value: 0, label: t('Off') }, ...[60, 90, 120, 150, 180].map(v => ({ value: v, label: v + 's' }))]} /> {/* Default for a rest-pause burst added live on a plain set — a planned exercise's own "Rest (s)" (in its Intensifier config) overrides this, same as the main rest timer is the fallback whenever an exercise has no progression rule of its own. */} @@ -223,8 +223,12 @@ export default function Settings() { subtitle={t('to install openGym as a full-screen app.') + ' ' + (user ? t('Your data syncs with your profile — sign in anywhere to see it.') : t('Guest data stays on this device — export a backup now and then!'))} />
} + {/* The version, at the bottom of Settings — which is where the support template has been + telling people to look for it, and where it was not. On the phone build there is no + address bar and no about box, so without this there is no way to tell which build you + are running, or whether an update actually installed. */}
- openGym · {t('free & open source (AGPL v3)')}
+ openGym v{__APP_VERSION__} · {t('free & open source (AGPL v3)')}
source code · exercise data: hasaneyldrm/exercises-dataset (MIT)
exercise images and animations © Gym visual
diff --git a/frontend/vite.config.js b/frontend/vite.config.js index bda3efa..88905d8 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -1,3 +1,4 @@ +import { readFileSync } from 'node:fs' import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' @@ -28,7 +29,13 @@ const umami = { } } +// The version people are asked for in #install-help and on every bug report. Read from +// package.json so it cannot drift from the release it was built in, and inlined at build +// time so no runtime fetch is involved. +const pkgVersion = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version + export default defineConfig({ + define: { __APP_VERSION__: JSON.stringify(pkgVersion) }, plugins: [react(), umami], base: './', server: {