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
fix(media): exercise loops autoplay in the Android app (muted attribute); search: the name as typed wins with a typo or a plural too
Duarte Santos2172b8e7f2ef
diff --git a/frontend/src/components/Media.autoplay.test.jsx b/frontend/src/components/Media.autoplay.test.jsxnew file mode 100644index 000000000..dbaa52d99--- /dev/null+++ b/frontend/src/components/Media.autoplay.test.jsx@@ -0,0 +1,17 @@+import { describe, expect, it, vi } from 'vitest'+import { autoplayMuted } from './Media.jsx'++// Android's WebView autoplays only a video that carries the muted *attribute*; React sets the+// property alone, and the catalogue loops sat on their first frame in the phone app.+describe('autoplayMuted', () => {+ it('sets the muted attribute and starts playback, swallowing a refusal', async () => {+ const el = { muted: false, defaultMuted: false, attrs: {}, setAttribute(k, v) { this.attrs[k] = v }, play: vi.fn(() => Promise.reject(new Error('NotAllowedError'))) }+ autoplayMuted(el)+ expect(el.muted).toBe(true)+ expect(el.defaultMuted).toBe(true)+ expect(el.attrs.muted).toBe('')+ expect(el.play).toHaveBeenCalled()+ await Promise.resolve()+ })+ it('ignores the unmount call', () => { expect(() => autoplayMuted(null)).not.toThrow() })+})diff --git a/frontend/src/components/Media.jsx b/frontend/src/components/Media.jsxindex 4480c2f2a..723d119c7 100644--- a/frontend/src/components/Media.jsx+++ b/frontend/src/components/Media.jsx@@ -45,7 +45,7 @@ function BuiltinMedia({ ex, id, compact, minimizable }) {{failed === 'all'? <div className="exmedia-x"><Icon name="dumbbell" /></div>: showGif && isVideoSrc(gifSrc(ex, body))- ? <video className="catvid" src={gifSrc(ex, body)} poster={imgSrc(ex, body)} autoPlay muted loop playsInline disablePictureInPicture+ ? <video ref={autoplayMuted} className="catvid" src={gifSrc(ex, body)} poster={imgSrc(ex, body)} autoPlay muted loop playsInline disablePictureInPicturearia-label={exerciseNameFor(ex)} onError={onError} />: <img decoding="async" draggable={false} src={showGif ? gifSrc(ex, body) : imgSrc(ex, body)} alt={exerciseNameFor(ex)} onError={onError} />}{minimizable && (@@ -62,6 +62,19 @@ function BuiltinMedia({ ex, id, compact, minimizable }) {)}+// React sets `muted` as a property only, never as the attribute, and Android's WebView (the phone+// app) allows autoplay only for a video that carries the attribute: the loop sat on its first frame+// there while every desktop browser played it. Set it before the first frame and start playback+// ourselves; a refusal leaves the still showing, which a tap can still start.+export function autoplayMuted(el) {+ if (!el) return+ el.muted = true+ el.defaultMuted = true+ el.setAttribute('muted', '')+ const p = el.play?.()+ if (p && typeof p.catch === 'function') p.catch(() => {})+}+// A still that will not load (offline and never cached, a lapsed session on a gated instance, a// CDN hiccup) gets the same neutral tile as an exercise without media, instead of the browser's// broken-image glyph in a list of them (#281). The failure is remembered per image, so a listdiff --git a/frontend/src/lib/exercises.js b/frontend/src/lib/exercises.jsindex c91cdae7e..69def1c33 100644--- a/frontend/src/lib/exercises.js+++ b/frontend/src/lib/exercises.js@@ -400,7 +400,8 @@ function formsOfUncached(tok) {for (const s of SYNONYMS[tok] || []) out.push(s)if (tok.length >= 4 && tok.endsWith('es') && !tok.endsWith('ses')) out.push(tok.slice(0, -2), tok.slice(0, -1))else if (tok.length >= 4 && tok.endsWith('ses')) out.push(tok.slice(0, -2))- else if (tok.length >= 4 && tok.endsWith('s') && !tok.endsWith('ss')) out.push(tok.slice(0, -1))+ // Three letters is enough for "ups" ("pull ups" is "pull-up"); "abs" is a word of its own.+ else if (tok.length >= 3 && tok.endsWith('s') && !tok.endsWith('ss') && tok !== 'abs') out.push(tok.slice(0, -1))return [...new Set(out)]}@@ -522,18 +523,27 @@ const EQ_PRIOR = { barbell: 4, dumbbell: 4, cable: 3, 'leverage machine': 3, 'boconst CAT_PRIOR = { strength: 3, calisthenics: 3, olympic: 2, plyometrics: 1, isometric: 1, stretching: -3, mobility: -3, rehab: -4, yoga: -2, pilates: -2 }const priorOf = e => (CLASSIC.has(e.id) ? 3 : 0) + (EQ_PRIOR[e.eq] || 0) + (CAT_PRIOR[e.cat] || 0)+// A name that is the query itself wins outright: as typed or in the singular 50, with the typos+// the search allows for its length 40 ("sqat" is the exercise called "squat", not "dumbbell squat").+function wholeNameScore(plain, typedForms) {+ if (typedForms.includes(plain)) return 50+ return typedForms.some(q => { const max = typosFor(q); return max && editDistance(q, plain, max) <= max }) ? 40 : 0+}+// The matches in order of how well they match, shorter names first among equals (the plain// "barbell squat" before its six variations), and the list's own order after that: custom// exercises, which callers put first, stay first among equal matches.function rankByRelevance(found, tokens) {const ctx = queryContext(tokens)- const typed = tokens.join(' ')+ // The query as typed, and with each word in its singular: "pull ups" is the name "pull-up".+ const typedForms = [...new Set([tokens, tokens.map(tok => formsOf(tok).find(f => f !== tok && !f.includes(' ')) || tok)]+ .map(list => list.join(' ').replace(/[-‐-―]/g, ' ')))]const scored = found.map((e, i) => {const entry = corpusOf(e)// The name exactly as typed wins outright ("burpee" before "dumbbell burpee"), and every// word the name has beyond the query costs a little, more than the equipment preference.const plain = entry.name.split(' (')[0].replace(/[-‐-―]/g, ' ')- const whole = plain === typed.replace(/[-‐-―]/g, ' ') ? 50 : 0+ const whole = wholeNameScore(plain, typedForms)const extra = Math.max(0, entry.nameWords.length - tokens.length) * 3return { e, i, score: tokens.reduce((sum, tok) => sum + tokenScore(entry, tok, ctx), 0) + priorOf(e) + whole - extra, len: entry.nameWords.length }})diff --git a/frontend/src/lib/search-typo.test.js b/frontend/src/lib/search-typo.test.jsindex e45714d56..6684f9834 100644--- a/frontend/src/lib/search-typo.test.js+++ b/frontend/src/lib/search-typo.test.js@@ -127,3 +127,11 @@ it('finds something close when nothing matches exactly', () => {expect(close.slice(0, 5).some(e => /dumbbell.*curl/.test(e.n))).toBe(true)expect(similarExercises(EXDB, ' ')).toEqual([])})++it('puts the exercise named as typed first, typo or plural included', () => {+ const first = q => searchExercises(EXDB, q)[0]?.n+ expect(first('sqat')).toBe('squat')+ expect(first('pull ups')).toBe('pull-up')+ expect(first('push ups')).toBe('push-up')+ expect(first('burpee')).toBe('burpee')+})