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
Custom exercises: a short clip in the detail sheet loops by itself even when its file is there before the sheet has slid in, instead of waiting for a tap
Duarte Santosc8d24991b30b
diff --git a/frontend/src/components/CustomMedia.jsx b/frontend/src/components/CustomMedia.jsxindex 045c74d55..f695b0e8f 100644--- a/frontend/src/components/CustomMedia.jsx+++ b/frontend/src/components/CustomMedia.jsx@@ -237,8 +237,16 @@ function CustomVideo({ m, id, cls, name, toggle, mini, still }) {if (!el || !main.url) returnif (shouldPlay) {const p = el.play()- // Refused (no user gesture where the browser wants one): it waits for a tap instead.- if (p && typeof p.then === 'function') p.then(() => setPlaying(true), () => { setPlaying(false); setAsked(false) })+ // Refused (no user gesture where the browser wants one): it waits for a tap instead. Only a+ // refusal is one: an AbortError is this effect's own pause() cutting the play() short — a+ // sheet still sliding in is off screen for the observer's first answer — and once the box+ // is on screen the effect asks it to play again.+ if (p && typeof p.then === 'function') {+ p.then(() => setPlaying(true), e => {+ if (e?.name === 'NotAllowedError') { setPlaying(false); setAsked(false) }+ else setPlaying(!el.paused)+ })+ }} else el.pause()}, [shouldPlay, main.url])diff --git a/frontend/src/components/Media.test.jsx b/frontend/src/components/Media.test.jsxindex ed2babc95..323e23c84 100644--- a/frontend/src/components/Media.test.jsx+++ b/frontend/src/components/Media.test.jsx@@ -174,6 +174,53 @@ describe('Media — a custom exercise', () => {} finally { globalThis.IntersectionObserver = IO }})+ // QA, v1.3.9: reopened within the half-minute its file stays cached, the sheet was still sliding+ // in when the file was there. The observer's first answer (off screen) paused the play() just+ // started, the AbortError that followed was taken for a refusal, and the clip never started.+ it('a play() cut short by its own pause (the sheet still sliding in) plays once the box is on screen', async () => {+ const observers = []+ const IO = globalThis.IntersectionObserver+ globalThis.IntersectionObserver = class { constructor(cb) { this.cb = cb; observers.push(this) } observe() {} disconnect() {} }+ let reject = null+ HTMLMediaElement.prototype.play = vi.fn(function () { return new Promise((res, rej) => { reject = rej }) })+ HTMLMediaElement.prototype.pause = vi.fn(function () {+ reject?.(Object.assign(new Error('The play() request was interrupted by a call to pause().'), { name: 'AbortError' }))+ })+ try {+ await holding(MAIN, POSTER)+ await mountCustom(custom({ media: clip(10) }))+ expect(HTMLMediaElement.prototype.play).toHaveBeenCalledTimes(1)+ await act(async () => { observers.at(-1).cb([{ isIntersecting: false }]) })+ await settle()+ expect(HTMLMediaElement.prototype.pause).toHaveBeenCalled()+ HTMLMediaElement.prototype.play = vi.fn(function () { return Promise.resolve() })+ await act(async () => { observers.at(-1).cb([{ isIntersecting: true }]) })+ await settle()+ expect(HTMLMediaElement.prototype.play).toHaveBeenCalledTimes(1)+ expect(host.querySelector('.gifhint').textContent).toContain('tap to pause')+ } finally { globalThis.IntersectionObserver = IO }+ })++ it('a short clip the browser refuses to start unasked waits for a tap', async () => {+ const observers = []+ const IO = globalThis.IntersectionObserver+ globalThis.IntersectionObserver = class { constructor(cb) { this.cb = cb; observers.push(this) } observe() {} disconnect() {} }+ HTMLMediaElement.prototype.play = vi.fn(function () { return Promise.reject(Object.assign(new Error('no gesture'), { name: 'NotAllowedError' })) })+ try {+ await holding(MAIN, POSTER)+ await mountCustom(custom({ media: clip(10) }))+ expect(HTMLMediaElement.prototype.play).toHaveBeenCalledTimes(1)+ await act(async () => { observers.at(-1).cb([{ isIntersecting: true }]) })+ await settle()+ expect(HTMLMediaElement.prototype.play).toHaveBeenCalledTimes(1)+ expect(host.querySelector('.gifhint').textContent).toContain('tap to play')+ HTMLMediaElement.prototype.play = vi.fn(function () { return Promise.resolve() })+ act(() => { host.querySelector('.exmedia').click() })+ await settle()+ expect(HTMLMediaElement.prototype.play).toHaveBeenCalledTimes(1)+ } finally { globalThis.IntersectionObserver = IO }+ })+it('a long video waits for a tap, then plays with sound and its own controls', async () => {await holding(MAIN, POSTER)await mountCustom(custom({ media: clip(45) }))