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.

The end of a hold sounds once: the chime and its buzz pattern, without the set tick's beep clipping it or its short buzz cutting the pattern off (Discord)

Duarte Santos0f5124e3eba0
diff --git a/frontend/src/store/useUI.js b/frontend/src/store/useUI.js
index d343cd9e2..f7e2eb72a 100644
--- a/frontend/src/store/useUI.js
+++ b/frontend/src/store/useUI.js
@@ -149,9 +149,10 @@ export const useUI = create((set, get) => ({
purpose: the two mean opposite things, they must never run together, and a work set is
something you are watching — so it gets no server push (that endpoint says "rest over",
and a plank does not need a notification you are staring at anyway).
- `onDone(elapsedSec)` is called both when the countdown reaches zero and on an early
- finish; the elapsed time is what actually gets logged, so stopping at 0:38 of a 0:45
- hold records 0:38 rather than crediting the full target. */
+ `onDone(elapsedSec, { chimed })` is called both when the countdown reaches zero and on an
+ early finish; the elapsed time is what actually gets logged, so stopping at 0:38 of a 0:45
+ hold records 0:38 rather than crediting the full target. `chimed` is true when the countdown
+ ran out in front of you and the end chime and buzz have just played. */
startWork(sec, label, onDone) {
get().stopWork()
get().stopRest()
@@ -174,7 +175,8 @@ export const useUI = create((set, get) => ({
}
const done = workDone
get().stopWork()
- if (done) done(wk.total)
+ // `chimed` tells the set's own tick that this end has already sounded and buzzed.
+ if (done) done(wk.total, { chimed: seenLive })
return
}
if (left <= 3) beep(snd, 660, 0.1)
diff --git a/frontend/src/views/Workout.hold.test.jsx b/frontend/src/views/Workout.hold.test.jsx
new file mode 100644
index 000000000..7ff6b152e
--- /dev/null
+++ b/frontend/src/views/Workout.hold.test.jsx
@@ -0,0 +1,83 @@
+// @vitest-environment happy-dom
+// The end of a hold, against the real store and work timer: it sounds once. The chime and its
+// buzz pattern belong to the timer (store/useUI.js); the set it ticks adds neither its own beep,
+// which clipped the chime's first note, nor its short buzz, which cut the pattern off.
+import React, { act } from 'react'
+import { createRoot } from 'react-dom/client'
+import { MemoryRouter } from 'react-router-dom'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import Workout from './Workout.jsx'
+import { DEF, useStore } from '../store/useStore.js'
+import { useUI } from '../store/useUI.js'
+import { beep, chime, vibrate } from '../lib/sound.js'
+
+vi.mock('../lib/sound.js', () => ({ beep: vi.fn(), chime: vi.fn(), vibrate: vi.fn(), unlock: vi.fn() }))
+vi.mock('../lib/api.js', () => ({ api: vi.fn(() => Promise.resolve({})), appBase: () => '/' }))
+
+globalThis.IS_REACT_ACT_ENVIRONMENT = true
+const clone = value => JSON.parse(JSON.stringify(value))
+const plank = () => ({ id: '1001', target: { mode: 'time', sets: 2, sec: 10 }, sets: [{ sec: 10, w: 0, done: false }, { sec: 10, w: 0, done: false }] })
+
+let root
+let container
+
+function renderWorkout(entries) {
+ const S = clone(DEF)
+ S.sound = true
+ S.active = { id: 'hold-test', d: '2026-09-23', start: Date.now(), routineId: null, name: 'Hold', bw: null, cur: 0, entries }
+ useStore.setState({ S, user: null })
+ container = document.createElement('div')
+ document.body.appendChild(container)
+ root = createRoot(container)
+ act(() => root.render(<MemoryRouter><Workout /></MemoryRouter>))
+}
+
+const startHold = () => {
+ const go = container.querySelector('button[aria-label="Start set"]')
+ expect(go).toBeTruthy()
+ act(() => go.click())
+ expect(useUI.getState().work).not.toBeNull()
+}
+const tickBeeps = () => beep.mock.calls.filter(call => call[1] === 1040)
+const doneOf = () => useStore.getState().S.active.entries[0].sets.map(s => s.done)
+
+beforeEach(() => {
+ vi.useFakeTimers()
+ localStorage.clear()
+ vi.mocked(beep).mockClear(); vi.mocked(chime).mockClear(); vi.mocked(vibrate).mockClear()
+ useUI.setState({ sheets: [], toastMsg: '', timer: null, work: null })
+ root = null
+ container = null
+})
+
+afterEach(() => {
+ if (root) act(() => root.unmount())
+ if (container) container.remove()
+ useUI.getState().stopRest()
+ useUI.getState().stopWork()
+ vi.clearAllTimers()
+ vi.useRealTimers()
+})
+
+describe('the end of a hold', () => {
+ it('ran out on its own: the chime and its buzz pattern, and no tick beep or short buzz after them', () => {
+ renderWorkout([plank()])
+ startHold()
+ act(() => { vi.advanceTimersByTime(11_000) })
+ expect(doneOf()).toEqual([true, false])
+ expect(chime).toHaveBeenCalledOnce()
+ expect(tickBeeps()).toEqual([])
+ expect(vibrate.mock.calls).toEqual([[[200, 100, 200]]])
+ })
+
+ it('finished early with Done: the set ticks the way a tap does, beep and buzz', () => {
+ renderWorkout([plank()])
+ startHold()
+ act(() => { vi.advanceTimersByTime(4_000) })
+ act(() => useUI.getState().finishWorkEarly())
+ expect(doneOf()).toEqual([true, false])
+ expect(chime).not.toHaveBeenCalled()
+ expect(tickBeeps()).toHaveLength(1)
+ expect(vibrate).toHaveBeenLastCalledWith(30)
+ })
+})
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx
index 72c908d80..f58fbded1 100644
--- a/frontend/src/views/Workout.jsx
+++ b/frontend/src/views/Workout.jsx
@@ -919,13 +919,16 @@ function ActiveWorkout() {
// This tap may be the only one before the hold's countdown beeps (a timed first exercise):
// get the audio context running while it still counts as a gesture (iOS, #152).
unlock(S.sound)
- useUI.getState().startWork(e.sets[i].sec || 45, exerciseNameFor(exOr(e.id)), elapsed => {
+ useUI.getState().startWork(e.sets[i].sec || 45, exerciseNameFor(exOr(e.id)), (elapsed, { chimed = false } = {}) => {
mutEntry(idx, en => { en.sets[i].sec = elapsed })
- if (!useStore.getState().S.active.entries[idx].sets[i].done) toggle(idx, i)
+ if (!useStore.getState().S.active.entries[idx].sets[i].done) toggle(idx, i, undefined, { quiet: chimed })
})
}
- const toggle = (idx, i, side) => {
+ // `quiet`: the hold that ticks this set has just ended with the chime and its buzz pattern
+ // (store/useUI.js). The tick's own beep would sound over the chime's first note and clip it,
+ // and its short buzz would cut the pattern off: a new vibrate call replaces the running one.
+ const toggle = (idx, i, side, { quiet = false } = {}) => {
// Ticking a set ends the typing in that row: drop the keyboard before the rest timer, the
// effort sheet or the next exercise moves in. WebKit keeps the input focused across the
// button tap, and a focused input with its keyboard gone is what leaves the tab bar
@@ -942,7 +945,7 @@ function ActiveWorkout() {
else e.sets[i].done = !e.sets[i].done
checked = e.sets[i].done
if (e.sets[i].done) {
- beep(S.sound, 1040, 0.12); vibrate(30)
+ if (!quiet) { beep(S.sound, 1040, 0.12); vibrate(30) }
// The unit that owns the ticked set — not the marked one. Since !92 the marker no longer
// follows a finished exercise, and in list mode any exercise can be worked on, so judging
// the marker's unit here declared the workout complete after one set elsewhere.