From 9bec4bb785bd3d0c59d192634b0c9848ddf46000 Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Tue, 25 Aug 2026 22:05:07 +0200 Subject: [PATCH] settings: show the version, and let the rest timer be turned off MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two things people asked for on release day, both small, both awkward to live without. The version was not visible anywhere. mflova asked how to tell which build the phone app is running and andi242 said he had wondered the same that morning; issue #7 asks for it too. The support template in #install-help has been telling people to read it off "the bottom of Settings" — where it was not. It is there now, read from package.json at build time so it cannot drift from the release it shipped in. On the phone there is no address bar and no about box, so this was the only missing way to answer "did the update actually install". The rest timer had no off switch. andi242, in the per-exercise-timers thread: "I don't use rest timers, so I find it's a bit tedious to skip the timer every time." v1.2.10 made that worse rather than better — it now rests after every set except the last of the session, so an exercise that used to end quietly no longer does, and there was still no way out. "Off" now sits at the top of the same list as 60/90/120/150/180. The guard is inside startRest rather than at the four places that call it, for the same reason the rest-after-a-set rule became one shared condition: a rule that has to be repeated is a rule that gets forgotten. 'Off' already exists in all twelve locale packs, so this adds no translation work. --- frontend/src/store/useUI.js | 3 +++ frontend/src/store/useUI.test.js | 28 ++++++++++++++++++++++++++++ frontend/src/views/Settings.jsx | 8 ++++++-- frontend/vite.config.js | 7 +++++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 frontend/src/store/useUI.test.js 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: {