Bugfix-Runde vom Board: Coach-Speichern auf Android (#42), Baender wie Koerpergewicht (#39), Einheitenwechsel rechnet um (#22), Mitte-Tab im Workout (#29/#21), Kopie-Namen, Geister-Wochentag, Swap-Picker

- #42: "Save and use the Coach" blieb auf Android 16 grau. Der sichere Speicher wird jetzt mit
  4 s Timeout angesprochen (coach-secrets.js withTimeout), die Geraete-Einstellung wird VOR dem
  Schluessel geschrieben, und jeder Fehler landet als Toast statt in einem stummen Promise.
- #39: isBodyweightEq zaehlt 'band'/'resistance band' mit (54 Katalog-Uebungen) — ein Reps-Stepper,
  Progression in Wdh./Saetzen; der Bodyweight-Schalter je Uebung ueberstimmt weiterhin.
- #22: Settings → Gewichtseinheit fragt: Zahlen umrechnen (lib/units.js convertStateUnit ueber
  Saetze, Drops, topW, Ziele, inc, Warm-up-Configs, exWeights, barWeights, Koerpergewicht, Zielgewicht;
  lb auf 0.5, kg auf 0.25 gerundet, Hin- und Rueckweg stabil) oder nur die Beschriftung aendern.
  Fussnote entsprechend, alter Hinweis-String raus. 5 neue Strings in 14 Packs.
- #29/#21: der Mitte-Tab heisst auf dem Workout-Screen "Workout" und leuchtet; sonst "Resume",
  das zum gemerkten Eintrag (S.active.cur) fuehrt, der sich seit !92 nie von selbst bewegt.
- !85: Kopie einer Kopie wird "Name (Copy 2)", nicht "(Copy) (Copy)".
- !94: ein Wochentag, dessen Routine nicht mehr existiert, loest keine Bestaetigung aus.
- !72: das "+" im Swap-Picker uebernimmt sofort mit Standard-Config wie ueberall sonst.
This commit is contained in:
Duarte Santos committed 2026-09-05 13:58:07 +02:00
1 parent 3773f65355
commit b5769b9c38
25 files changed
+251 -34

No files matched your search

+12 -3
View File
@@ -20,10 +20,19 @@ function plugin() {
return pluginPromise
}
// A native call that never answers must not hang the setup screen behind a greyed-out button
// (issue #42: "Save and use the Coach" stayed disabled forever on one Android 16 phone). After
// this long the platform store is treated as unavailable and the process-local map takes over.
const NATIVE_TIMEOUT_MS = 4000
export const withTimeout = (promise, ms = NATIVE_TIMEOUT_MS) => new Promise((resolve, reject) => {
const tm = setTimeout(() => reject(new Error('secure storage timed out')), ms)
promise.then(v => { clearTimeout(tm); resolve(v) }, e => { clearTimeout(tm); reject(e) })
})
export async function getApiKey() {
const p = await plugin()
if (p) {
try { const v = await p.get(KEY); return typeof v === 'string' && v ? v : null } catch { /* fall through */ }
try { const v = await withTimeout(p.get(KEY)); return typeof v === 'string' && v ? v : null } catch { /* fall through */ }
}
return memory.get(KEY) || null
}
@@ -32,12 +41,12 @@ export async function setApiKey(value) {
if (!v) return clearApiKey()
const p = await plugin()
if (p) {
try { await p.set(KEY, v); memory.delete(KEY); return } catch { /* fall through */ }
try { await withTimeout(p.set(KEY, v)); memory.delete(KEY); return } catch { /* fall through */ }
}
memory.set(KEY, v)
}
export async function clearApiKey() {
const p = await plugin()
if (p) { try { await p.remove(KEY) } catch { /* nothing to clear */ } }
if (p) { try { await withTimeout(p.remove(KEY)) } catch { /* nothing to clear */ } }
memory.delete(KEY)
}
+5 -1
View File
@@ -142,8 +142,12 @@ export const isCardio = idOrEx => (typeof idOrEx === 'string' ? EXIDX[idOrEx] :
// catalogue. This seeds the `bw` flag on a fresh config so a push-up never asks for a weight
// nobody was going to enter. It is only the default: the flag lives on the config, so a dip
// done with a belt can turn it off and a custom exercise can turn it on.
// Equipment with no meaningful load in kg: your own body, or a band whose "weight" is a colour.
// Both default to the bodyweight model (one reps stepper, progression in reps then sets); the
// per-exercise Bodyweight switch still overrides it either way (issue #39).
const BODYWEIGHT_EQ = new Set(['body weight', 'band', 'resistance band'])
export const isBodyweightEq = idOrEx =>
(typeof idOrEx === 'string' ? EXIDX[idOrEx] : idOrEx)?.eq === 'body weight'
BODYWEIGHT_EQ.has((typeof idOrEx === 'string' ? EXIDX[idOrEx] : idOrEx)?.eq)
// An id that resolves to nothing — a plan file built against a different exercise dataset,
// a custom exercise deleted on another device before the sync arrived — still has to
+3 -3
View File
@@ -27,11 +27,11 @@ describe('Brazilian Portuguese locale', () => {
.sort(byCodeUnit)
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(618)
expect(inherited).toHaveLength(596)
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(620)
expect(inherited).toHaveLength(598)
// If this fails, review the changed keys and wording before accepting a new hash. From
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('1f6ae623aa2a6234b7454b5b6b59512e66a03b39dda46b1b0f359942b970907d')
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('5f1f5dcac5d51dd96f9d1e3506c6a65fd098071b971739686f3cc0360cca35ec')
})
test('does not leak European Portuguese UI terms', () => {
+4 -1
View File
@@ -7,6 +7,9 @@ import { uid } from './format.js'
export function copyRoutine(routine, suffix = 'Copy') {
const copy = structuredClone(routine)
copy.id = uid()
copy.name = routine.name + ' (' + suffix + ')'
// "Push (Copy)" copied again becomes "Push (Copy 2)", not "Push (Copy) (Copy)".
const esc = suffix.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
const m = new RegExp('^(.*) \\(' + esc + '(?: (\\d+))?\\)$').exec(routine.name || '')
copy.name = m ? m[1] + ' (' + suffix + ' ' + ((Number(m[2]) || 1) + 1) + ')' : routine.name + ' (' + suffix + ')'
return copy
}
+11
View File
@@ -77,3 +77,14 @@ describe('copyRoutine', () => {
expect(copy.id).not.toBe('r2')
})
})
describe('copyRoutine of a copy', () => {
it('numbers the copies instead of stacking suffixes', () => {
const first = copyRoutine({ id: 'r', name: 'Push', ex: [] })
expect(first.name).toBe('Push (Copy)')
const second = copyRoutine(first)
expect(second.name).toBe('Push (Copy 2)')
expect(copyRoutine(second).name).toBe('Push (Copy 3)')
expect(copyRoutine({ id: 'r', name: 'Push (Kopie)', ex: [] }, 'Kopie').name).toBe('Push (Kopie 2)')
})
})
+54
View File
@@ -0,0 +1,54 @@
// Converting a profile between kg and lb. Until now the unit switch only relabelled the numbers
// (60 kg became "60 lb", issue #22); this walks every stored weight once. Rounded to what a gym
// can load: lb to the nearest 0.5, kg to the nearest 0.25 — enough that a value converted there
// and back lands where it started for any plate-loadable number.
const LB_PER_KG = 2.2046226218
export function convertWeight(value, from, to) {
if (from === to || value == null || value === '' || !Number.isFinite(Number(value))) return value
const v = Number(value)
if (to === 'lb') return Math.round(v * LB_PER_KG * 2) / 2
return Math.round(v / LB_PER_KG * 4) / 4
}
const convSet = (set, from, to) => {
if (!set || typeof set !== 'object') return set
const out = { ...set }
if (out.w != null) out.w = convertWeight(out.w, from, to)
if (Array.isArray(out.drops)) out.drops = out.drops.map(d => ({ ...d, w: convertWeight(d.w, from, to) }))
return out
}
const convTarget = (cfg, from, to) => {
if (!cfg || typeof cfg !== 'object') return cfg
const out = { ...cfg }
if (out.weight != null) out.weight = convertWeight(out.weight, from, to)
// A per-exercise increment is a load too — 2.5 kg is 5 lb, not 2.5 lb.
if (out.inc > 0 && (out.mode == null || out.mode === 'reps')) out.inc = convertWeight(out.inc, from, to)
if (Array.isArray(out.warmup)) out.warmup = out.warmup.map(w => (w && w.weight != null ? { ...w, weight: convertWeight(w.weight, from, to) } : w))
return out
}
const convEntry = (e, from, to) => {
if (!e || typeof e !== 'object') return e
return {
...e,
...(e.topW != null ? { topW: convertWeight(e.topW, from, to) } : {}),
...(e.target ? { target: convTarget(e.target, from, to) } : {}),
...(Array.isArray(e.sets) ? { sets: e.sets.map(s => convSet(s, from, to)) } : {}),
}
}
/** A new state object with every weight expressed in `to`, and `unit` set to it. */
export function convertStateUnit(S, to) {
const from = S.unit || 'kg'
if (from === to) return S
const c = v => convertWeight(v, from, to)
const out = { ...S, unit: to }
if (Array.isArray(S.bodyweight)) out.bodyweight = S.bodyweight.map(b => ({ ...b, w: c(b.w) }))
if (S.targetW != null) out.targetW = c(S.targetW)
if (S.exWeights) out.exWeights = Object.fromEntries(Object.entries(S.exWeights).map(([k, v]) => [k, v && typeof v === 'object' ? { ...v, w: c(v.w) } : c(v)]))
if (S.barWeights) out.barWeights = Object.fromEntries(Object.entries(S.barWeights).map(([k, v]) => [k, c(v)]))
if (Array.isArray(S.routines)) out.routines = S.routines.map(r => ({ ...r, ex: (r.ex || []).map(cfg => convTarget(cfg, from, to)) }))
if (Array.isArray(S.workouts)) out.workouts = S.workouts.map(w => ({ ...w, entries: (w.entries || []).map(e => convEntry(e, from, to)) }))
if (S.active) out.active = { ...S.active, entries: (S.active.entries || []).map(e => convEntry(e, from, to)) }
return out
}
+52
View File
@@ -0,0 +1,52 @@
import { describe, it, expect } from 'vitest'
import { convertWeight, convertStateUnit } from './units.js'
describe('convertWeight', () => {
it('rounds lb to a half and kg to a quarter', () => {
expect(convertWeight(60, 'kg', 'lb')).toBe(132.5)
expect(convertWeight(135, 'lb', 'kg')).toBe(61.25)
expect(convertWeight(2.5, 'kg', 'lb')).toBe(5.5)
})
it('leaves the value alone for the same unit, nothing, or garbage', () => {
expect(convertWeight(60, 'kg', 'kg')).toBe(60)
expect(convertWeight(null, 'kg', 'lb')).toBe(null)
expect(convertWeight('', 'kg', 'lb')).toBe('')
expect(convertWeight('abc', 'kg', 'lb')).toBe('abc')
})
it('round-trips plate-loadable numbers', () => {
for (const kg of [20, 42.5, 60, 100, 142.5]) {
expect(convertWeight(convertWeight(kg, 'kg', 'lb'), 'lb', 'kg')).toBe(kg)
}
})
})
describe('convertStateUnit', () => {
const S = {
unit: 'kg', targetW: 80, bodyweight: [{ d: '2026-01-01', w: 82.4, t: 1 }],
exWeights: { '0025': { w: 80, d: '2026-01-01' }, legacy: 100 }, barWeights: { '0025': 20 },
routines: [{ id: 'r', ex: [{ id: '0025', sets: 3, reps: 5, weight: 80, inc: 2.5, warmup: [{ weight: 40, reps: 8 }] }, { id: 'plank', mode: 'time', sec: 30, inc: 5 }] }],
workouts: [{ id: 'w', entries: [{ id: '0025', topW: 80, target: { weight: 80 }, sets: [{ w: 80, r: 5, done: true, drops: [{ w: 60, r: 5 }] }] }] }],
active: { id: 'a', entries: [{ id: '0025', sets: [{ w: 82.5, r: 5, done: false }] }] },
workoutView: 'list',
}
it('converts every stored weight and keeps everything else', () => {
const out = convertStateUnit(S, 'lb')
expect(out.unit).toBe('lb')
expect(out.targetW).toBe(176.5)
expect(out.bodyweight[0]).toEqual({ d: '2026-01-01', w: 181.5, t: 1 })
expect(out.exWeights['0025'].w).toBe(176.5)
expect(out.exWeights.legacy).toBe(220.5)
expect(out.barWeights['0025']).toBe(44)
expect(out.routines[0].ex[0]).toMatchObject({ weight: 176.5, inc: 5.5, warmup: [{ weight: 88, reps: 8 }] })
expect(out.routines[0].ex[1]).toEqual({ id: 'plank', mode: 'time', sec: 30, inc: 5 }) // seconds stay seconds
expect(out.workouts[0].entries[0]).toMatchObject({ topW: 176.5, target: { weight: 176.5 } })
expect(out.workouts[0].entries[0].sets[0]).toMatchObject({ w: 176.5, done: true, drops: [{ w: 132.5, r: 5 }] })
expect(out.active.entries[0].sets[0].w).toBe(182)
expect(out.workoutView).toBe('list')
expect(S.unit).toBe('kg') // the input is not mutated
expect(S.workouts[0].entries[0].sets[0].w).toBe(80)
})
it('is a no-op for the unit already in use', () => {
expect(convertStateUnit(S, 'kg')).toBe(S)
})
})