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.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Merge the workout and alerts batch: a louder rest chime, vibration in the app with its own switch, keyboard shortcuts, 'Don't count for progression' per exercise, clearer deload wording (#133, #294)
Duarte Santosa05094003282
diff --cc frontend/src/App.jsxindex f60ce55f1,3d981c30e..bc0c7b9d8--- a/frontend/src/App.jsx+++ b/frontend/src/App.jsx@@@ -4,8 -4,8 +4,8 @@@ import { useStore } from './store/useStimport { useUI } from './store/useUI.js'import { bindUI } from './components/ui.jsx'import { ACCENTS, setWeightDecimals } from './lib/format.js'-import { setLang, useLang } from './lib/i18n.js'+import { setLang, useLang, baseLang } from './lib/i18n.js'- import { setPlayOnSilent } from './lib/sound.js'+ import { setPlayOnSilent, setVibrate } from './lib/sound.js'import { setNav } from './lib/nav.js'import { initBackButton } from './lib/back.js'import { useWakeLock } from './lib/wakelock.js'diff --cc frontend/src/index.cssindex 6b058a8c1,4cca84839..fce2fe23d--- a/frontend/src/index.css+++ b/frontend/src/index.css@@@ -1022,10 -1022,10 +1022,14 @@@ body.chips-dragging *{cursor:inherit}.progline.warn{color:var(--yellow)}.progline svg{flex:none;margin-top:2px}+/* "Last time" / "Best set" under the plan line (#173): a button that switches between the two,+ looking like the plain line it replaced, with a small icon to say it can be tapped. */+.refline{width:100%;display:flex;align-items:flex-start;gap:6px;margin-bottom:4px;padding:0;text-align:left}+.refline svg{flex:none;margin-top:2px;font-size:12px}+ /* an exercise kept out of progression for this session, with its undo */+ .noprog{display:flex;align-items:center;gap:7px;margin:0 0 6px;font-size:13px;line-height:1.38;color:var(--orange)}+ .noprog svg{flex:none}+ .noprog .chip{margin-left:auto;padding:3px 11px;font-size:13px;color:var(--orange);background:color-mix(in srgb,var(--orange) 14%,transparent)}/* start a timed set (issue #16) — sits where you'd otherwise reach for the checkbox */.setrow .setgo{diff --cc frontend/src/lib/pt-br-locale.test.jsindex 7dd25ad3e,03d02609c..9f2c8504a--- a/frontend/src/lib/pt-br-locale.test.js+++ b/frontend/src/lib/pt-br-locale.test.js@@@ -27,21 -27,11 +27,21 @@@ describe('Brazilian Portuguese locale'.sort(byCodeUnit)const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')- expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(680)- expect(inherited).toHaveLength(680)- // If this fails, review the changed keys and wording before accepting a new hash. From+ // Every override names a real source string, so the two sets partition pt-PT's keys between+ // them and the fingerprint below covers everything not overridden. A typo'd override key+ // would otherwise sit in the file translating nothing.+ const stray = Object.keys(PT_BR_OVERRIDES).filter(key => !(key in pt))+ expect(stray, 'override keys that are not pt-PT keys').toEqual([])+ expect(Object.keys(PT_BR_OVERRIDES).length + inherited.length).toBe(Object.keys(pt).length)+ // …and each one really reaches the pack, whatever the spread order does.+ for (const [key, value] of Object.entries(PT_BR_OVERRIDES)) expect(ptBR[key], key).toBe(value)++ // The counts themselves are read off the pack rather than pinned here: a new UI string lands+ // in pt.js and pt-BR.js together and moves both, and a number in a test that every new string+ // has to be taught is a number nobody reads. What the numbers stood for is asserted above.+ // If the hash fails, review the changed keys and wording before accepting a new one. From// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list- expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('49142c74c455e337f0e4a3dc3610a1104a93f6d3246b96360a45799489ed78ff')- expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('c047dadd0f7070905a992f4afd8848225bbbeeb983116f6988a55a702eccaa43')++ expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('4d5518e63f7c98ecaff9f42e1a655243f2b2970b69db97e743d9a8a9804ecbe1')})test('does not leak European Portuguese UI terms', () => {diff --cc frontend/src/sheets.jsxindex f37b5ce01,5cc1c9498..0f440bb25--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@@ -35,15 -34,9 +35,15 @@@ import { nextUnfinishedUnit } from './limport { swapActiveExercise } from './lib/active-exercise-swap.js'import { useSheetKeyboard, useRevealActiveChip, tappable } from './lib/use-sheet-keyboard.js'import { isFav, toggleFav, sortFavouritesFirst } from './lib/favourites.js'- import { buildSessionEntries, buildPlannedEntry } from './lib/session-start.js'+ import { buildSessionEntries, buildPlannedEntry, builtOutOfProgression } from './lib/session-start.js'import { buildCombinedEntries, deriveSessionName } from './lib/session-merge.js'import { workoutsOn, backfillStart, backfillEnd, completeBackfill } from './lib/backfill.js'+import { moveWorkout, sameWorkout, startTimeOf, durationMinOf, setWorkoutDuration } from './lib/workout-date.js'+import { editCompletedSession } from './lib/session-edit.js'+import { stampWorkout } from './lib/sync-merge.js'+import { weeklyWeights } from './lib/bodyweight.js'+import { workoutText } from './lib/workout-text.js'+import { copyText } from './lib/clipboard.js'const S = () => useStore.getState().Sconst update = (...a) => useStore.getState().update(...a)diff --cc frontend/src/store/useUI.jsindex 1e1e17965,f7e2eb72a..28b885b94--- a/frontend/src/store/useUI.js+++ b/frontend/src/store/useUI.js@@@ -58,45 -58,6 +58,45 @@@ let timerTick = nullet workInt = nulllet workTick = nulllet workDone = null+const MAX_WORK_OVERTIME_SEC = 15 * 60++const stopRestTicking = () => {+ if (timerInt) clearInterval(timerInt); timerInt = null+ if (timerTick) document.removeEventListener('visibilitychange', timerTick); timerTick = null+}+// The rest countdown's tick, from a start or from a resume: the same endsAt-based count either+// way, so a paused rest carries on exactly as a started one runs.+const runRest = (set, get) => {+ stopRestTicking()+ timerTick = () => {+ const tm = get().timer+ if (!tm || tm.ready || tm.paused) return+ const left = Math.max(0, Math.round((tm.endsAt - Date.now()) / 1000))+ const seenLive = !document.hidden && pageHiddenAt === null+ if (!document.hidden) pageHiddenAt = null+ if (left === tm.left) return+ const snd = useStore.getState().S.sound+ if (left <= 0) {+ if (seenLive) {- beep(snd, 880, 0.15); beep(snd, 880, 0.15, 0.25); beep(snd, 1320, 0.4, 0.5)++ chime(snd)+ vibrate([200, 100, 200]); get().flashTimer()+ }+ // The toast stays even when the rest ran out while the app was hidden: a guest, or anyone+ // without push permission, gets no notification, and a countdown that silently vanishes+ // on reopen reads like a bug. Only the loud parts (beep, vibration, flash) are gated.+ get().toast(t('Rest over — next set!'))+ maybeRestNotification()+ cancelPushRestTimer()+ stopRestTicking()+ set({ timer: { ...tm, left: 0, ready: true } })+ return+ }+ if (left <= 3) beep(snd, 660, 0.1)+ set({ timer: { ...tm, left } })+ }+ timerInt = setInterval(timerTick, 1000)+ document.addEventListener('visibilitychange', timerTick)+}export const useUI = create((set, get) => ({sheets: [], // { id, render:(close)=>JSX, kind:'sheet'|'center', locked }@@@ -207,11 -149,12 +207,13 @@@purpose: the two mean opposite things, they must never run together, and a work set issomething 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. */++ `onDone(elapsedSec, { chimed, abandoned })` 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; `abandoned`++ when a rest displaced the hold (abandonWork). */startWork(sec, label, onDone) {- get().stopWork()+ get().abandonWork() // a hold this one replaces keeps what it held, same as a rest replacing oneget().stopRest()const total = Math.max(1, Math.round(sec) || 1)const endsAt = Date.now() + total * 1000@@@ -227,14 -169,14 +229,16 @@@if (left === wk.left) returnconst snd = useStore.getState().S.soundif (left <= 0) {- if (seenLive) {+ if (seenLive && !wk.alerted) {- beep(snd, 880, 0.15); beep(snd, 880, 0.15, 0.25); beep(snd, 1320, 0.4, 0.5)+ chime(snd)vibrate([200, 100, 200]); get().flashTimer()}+ if (wk.overtime && left > -MAX_WORK_OVERTIME_SEC) { set({ work: { ...wk, left, alerted: true } }); return }const done = workDoneget().stopWork()- if (done) done(wk.total - left)- // `chimed` tells the set's own tick that this end has already sounded and buzzed.- if (done) done(wk.total, { chimed: seenLive })++ // `chimed` tells the set's own tick that this end has already sounded and buzzed — not++ // so when overtime ran out, whose end chime played when the target was reached.++ if (done) done(wk.total - left, { chimed: seenLive && !wk.alerted })return}if (left <= 3) beep(snd, 660, 0.1)@@@ -254,24 -195,6 +258,24 @@@get().stopWork()if (done) done(elapsed)},+ // A rest is starting while a hold runs that is not the one being ticked — a set finished on+ // another row, or on another exercise, which the List layout puts one tap away. The hold cannot+ // survive (the two must never run together) but the time it held is real, so it is handed back+ // before it goes and its own row keeps it. The `abandoned` flag tells the owner this was not a+ // finish: the row is not ticked off and earns no rest of its own, since the rest that displaced+ // the hold is the one now running.+ abandonWork() {+ const wk = get().work+ if (!wk) { get().stopWork(); return }+ const elapsed = wk.total - wk.left+ const done = workDone+ get().stopWork()+ // Under two seconds there is nothing to keep: that is a play button tapped by accident, or+ // tapped and thought better of, and rounding it up to one second the way an early finish does+ // would write a one-second plank over a real plan. (finishWorkEarly's Math.max(1, …) is right+ // for what it is: you pressed Done, so you held it, however briefly.)- if (done && elapsed >= 2) done(elapsed, true)++ if (done && elapsed >= 2) done(elapsed, { abandoned: true })+ },// Abandon without logging anything.stopWork() {if (workInt) clearInterval(workInt); workInt = nulldiff --cc frontend/src/views/Settings.sound.test.jsxindex 9af042db5,7b28c873d..7e4df258e--- a/frontend/src/views/Settings.sound.test.jsx+++ b/frontend/src/views/Settings.sound.test.jsx@@@ -131,15 -131,43 +131,56 @@@ describe('Settings — Sounds switch un})})+describe('Settings — optional timed-set overtime', () => {+ it('offers the opt-in beside the timer alerts and writes the preference', () => {+ mount()+ const row = rowTitled('Keep timing after target')+ expect(row).toBeTruthy()+ expect(row.querySelector('.lrow-s').textContent).toBe('Timed sets continue up to 15 extra minutes. Tap Done to log the actual duration.')+ const sw = switchIn(row)+ expect(sw.getAttribute('aria-label')).toBe('Keep timing after target')+ act(() => { sw.click() })+ expect(mocks.S.timedSetOvertime).toBe(true)+ })+})+++ // Discord (asierlama): the buzz on or off on its own, the way the sound is.+ describe('Settings — vibrate', () => {+ const setVibrateApi = value => Object.defineProperty(navigator, 'vibrate', { value, configurable: true, writable: true })+ afterEach(() => { delete navigator.vibrate })++ it('is offered where the browser can vibrate, on by default, below the sound rows', () => {+ setVibrateApi(() => true)+ mount()+ const row = rowTitled('Vibrate')+ expect(row).toBeTruthy()+ expect(switchIn(row).getAttribute('aria-checked')).toBe('true')+ const rows = [...host.querySelectorAll('.lrow')]+ expect(rows.indexOf(row)).toBeGreaterThan(rows.indexOf(rowTitled('Sounds')))+ expect(rows.indexOf(row)).toBeLessThan(rows.indexOf(rowTitled('Flash screen when timer ends')))+ })++ it('stays on offer with Sounds off: the buzz does not depend on the sound', () => {+ setVibrateApi(() => true)+ mocks.S.sound = false+ mount()+ expect(rowTitled('Vibrate')).toBeTruthy()+ })++ it('writes vibrate to the store, off and back on', () => {+ setVibrateApi(() => true)+ mount()+ act(() => { switchIn(rowTitled('Vibrate')).click() })+ expect(mocks.S.vibrate).toBe(false)+ mount()+ expect(switchIn(rowTitled('Vibrate')).getAttribute('aria-checked')).toBe('false')+ act(() => { switchIn(rowTitled('Vibrate')).click() })+ expect(mocks.S.vibrate).toBe(true)+ })++ it('is not offered where there is nothing to buzz (iOS has no navigator.vibrate)', () => {+ setVibrateApi(undefined)+ mount()+ expect(rowTitled('Vibrate')).toBeUndefined()+ })+ })diff --cc frontend/src/views/Workout.jsxindex accc82734,be3982908..19f32d345--- a/frontend/src/views/Workout.jsx+++ b/frontend/src/views/Workout.jsx@@@ -19,14 -18,21 +19,20 @@@ import Icon from '../components/Icon.jsimport { Button, Check, NumberField } from '../components/ui.jsx'import { defaultIncrement, weightIncrement, stepWeight } from '../lib/progression.js'import { progressionGuidance } from '../lib/progression-copy.js'- import { buildPlannedEntry, plannedConfigOf } from '../lib/session-start.js'+ import { buildPlannedEntry, plannedConfigOf, builtOutOfProgression } from '../lib/session-start.js'import { glyphOf } from '../lib/glyphs.js'-import { isWarmupRow, isDropSet, isRestPauseSet, dropsOf, clustersOf, addDrop, addCluster, removeDropAt, removeClusterAt, setDropAt, setClusterAt, nextDropWeight, nextBurstReps, isSideSet, makeSideSet, setSideField, toggleSide, addSideDrop, removeSideDropAt, setSideDropAt, addSideCluster, removeSideClusterAt, setSideClusterAt } from '../lib/workout-model.js'+import { markAllSetsDone } from '../lib/backfill.js'+import { bestSetFor } from '../lib/exercise-history.js'+import { isWarmupRow, isDropSet, isRestPauseSet, dropsOf, clustersOf, addDrop, addCluster, removeDropAt, removeClusterAt, setDropAt, setClusterAt, nextDropWeight, nextBurstReps, isSideSet, makeSideSet, setSideField, toggleSide, addSideDrop, removeSideDropAt, setSideDropAt, addSideCluster, removeSideClusterAt, setSideClusterAt, WEIGHT_ORIGIN_MANUAL } from '../lib/workout-model.js'import { canMoveActiveWorkoutUnit, moveActiveWorkoutUnit } from '../lib/active-workout-order.js'+ import { nextOpenSet, workoutKeyAction } from '../lib/workout-keys.js'import { MUSCLE_NAME } from '../lib/muscles.js'-const SWIPE_MIN_DISTANCE = 48-const SWIPE_AXIS_RATIO = 1.25-const SWIPE_IGNORED_TARGETS = 'button,input,textarea,select,a,[role="button"],[role="checkbox"],[role="switch"],[role="slider"],[contenteditable="true"],.exmedia,[data-swipe-ignore]'+ // How long after a key starts a hold the same key is not yet its "Done" (#133). A USB button+ // that bounces, or a double press, sends two presses a moment apart: the first starts the hold,+ // and the second logged it at one second.+ const HOLD_KEY_GRACE_MS = 1500+/* ---------- start chooser (no active workout) ---------- */function StartChooser() {const nav = useNavigate()@@@ -74,7 -80,7 +80,7 @@@ function Elapsed({ start })// "last time" recap and the progression line — leaving the name, the ⋯ menu, the one-line plan// the rows are measured against, and the sets.// Nothing dropped is lost: it is all still on the ⋯ menu, or one ⋮ switch back to list/cards.- function ExerciseBlock({ entryIdx, compact, dense, editing, onToggle, onToggleSide, onField, onAddSet, onRemoveSet, onAddWarmup, onRemoveSetAt, onStartTimed, onPairPrev, onPairNext, onSetRowRef, onProgressionSettings, onSwap, onMoveUp, onMoveDown, canMoveUp, canMoveDown, onRemoveExercise, busy }) {-function ExerciseBlock({ entryIdx, compact, dense, onToggle, onToggleSide, onField, onAddSet, onRemoveSet, onAddWarmup, onRemoveSetAt, onStartTimed, onPairPrev, onPairNext, onSetRowRef, onProgressionSettings, onNoProg, onSwap, onMoveUp, onMoveDown, canMoveUp, canMoveDown, onRemoveExercise, busy }) {++function ExerciseBlock({ entryIdx, compact, dense, editing, onToggle, onToggleSide, onField, onAddSet, onRemoveSet, onAddWarmup, onRemoveSetAt, onStartTimed, onPairPrev, onPairNext, onSetRowRef, onProgressionSettings, onNoProg, onSwap, onMoveUp, onMoveDown, canMoveUp, canMoveDown, onRemoveExercise, busy }) {const S = useStore(s => s.S)const update = useStore(s => s.update)const working = useUI(s => s.work)@@@ -765,7 -764,8 +795,8 @@@ function ActiveWorkout()onAddWarmup: () => addWarmup(idx),onRemoveSetAt: i => removeSetAt(idx, i),onStartTimed: i => startTimed(idx, i),- onProgressionSettings: () => openProgressionSettings(idx),+ onProgressionSettings: editing ? null : () => openProgressionSettings(idx),+ onNoProg: routineKeepsOut(A.entries[idx]) ? null : on => setNoProg(idx, on),})const navigateUnit = direction => {const targetFor = active => {@@@ -926,28 -923,9 +959,28 @@@// 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, { chimed = false } = {}) => {- mutEntry(idx, en => { en.sets[i].sec = elapsed })+ // How long to hold: the row's own seconds, unless it is carrying a plan from a hold that was+ // displaced before it finished. `sec` on a timed row is both the plan and the log, so writing+ // what a part-held set managed would otherwise become the next hold's target — 3 seconds of a+ // 30 second plank, and every hold after it is 3 seconds. planSec keeps the plan aside until+ // the row is held to the end, ticked, or given a duration you typed yourself, and it never+ // reaches S.workouts (lib/finish-workout.js).+ const plan = (!e.sets[i].done && e.sets[i].planSec) || e.sets[i].sec || 45- useUI.getState().startWork(plan, exerciseNameFor(exOr(e.id)), (elapsed, abandoned) => {++ useUI.getState().startWork(plan, exerciseNameFor(exOr(e.id)), (elapsed, { abandoned = false, chimed = false } = {}) => {+ // A hold a rest displaced (useUI.abandonWork: a set ticked on another row, or another+ // exercise) keeps its seconds and nothing else. It is not a finish: the row stays unticked+ // and starts no rest, because the rest that displaced the hold is already counting down —+ // and the plan it was held against is put aside so the row still knows what it is asking for.+ if (abandoned) {+ // A row ticked by hand while its hold ran comes through here too — toggle starts the rest+ // that displaces the hold, so the hand-back lands on a row that is already ticked. It+ // still wants the seconds (that is what was held, not the target), but a finished row has+ // no use for a plan set aside.+ mutEntry(idx, en => { if (en.sets[i].planSec == null && !en.sets[i].done) en.sets[i].planSec = plan; en.sets[i].sec = elapsed })+ return+ }+ mutEntry(idx, en => { en.sets[i].sec = elapsed; delete en.sets[i].planSec })- 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 })})}@@@ -967,10 -948,8 +1003,10 @@@if (side) e.sets[i] = toggleSide(e.sets[i], side)else e.sets[i].done = !e.sets[i].donechecked = e.sets[i].done- if (e.sets[i].done) {+ // A finished row has no use for a plan set aside by a hold that did not finish.+ if (checked && e.sets[i].planSec != null) delete e.sets[i].planSec+ if (e.sets[i].done && !editing) {- 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.