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
Watch sync does nothing without a watch; UI test waits on one query
Duarte Santos0e566e874ffc
diff --git a/frontend/ios/App/AppUITests/OpenGymUITests.swift b/frontend/ios/App/AppUITests/OpenGymUITests.swiftindex f75a53359..55ae73fec 100644--- a/frontend/ios/App/AppUITests/OpenGymUITests.swift+++ b/frontend/ios/App/AppUITests/OpenGymUITests.swift@@ -126,12 +126,10 @@ final class OpenGymUITests: XCTestCase {let resume = app.buttons["Resume"]let home = app.buttons["Log"]let local = app.buttons["Use on this device"]- var landed = false- for _ in 0..<60 {- if finish.exists || resume.exists || home.exists || local.exists { landed = true; break }- sleep(1)- }- XCTAssertTrue(landed, "the app never showed a screen")+ // One query for any of the four, waited on, rather than four polled every second: on a busy+ // simulator each poll is a whole snapshot of the app, and they ran past XCTest's limit (CI 10-13).+ let anyScreen = app.buttons.matching(NSPredicate(format: "label IN %@", ["Finish", "Resume", "Log", "Use on this device"])).firstMatch+ XCTAssertTrue(anyScreen.waitForExistence(timeout: 120), "the app never showed a screen")if local.exists { chooseLocal() }if !finish.exists && resume.exists { resume.tap() }if !finish.waitForExistence(timeout: 5) {diff --git a/frontend/src/lib/watch-sync.js b/frontend/src/lib/watch-sync.jsindex aafab9830..cd1af228d 100644--- a/frontend/src/lib/watch-sync.js+++ b/frontend/src/lib/watch-sync.js@@ -264,11 +264,18 @@ export async function startWatchSync ({ useStore, useUI }) {}return ready}+ // Whether a watch with the app is there: asked at start and when the app comes back, not on every+ // change. Without one nothing below runs at all: no snapshot, no clips, no bridge call per tick.+ let linked = false+ const checkLink = async () => {+ try { const st = await p.WatchBridge.status(); linked = !!(st && st.paired && st.installed) } catch { linked = false }+ return linked+ }+ await checkLink()const send = async () => {tm = null+ if (!linked) returntry {- const st = await p.WatchBridge.status()- if (!st || !st.paired || !st.installed) returnconst S = useStore.getState().Sconst json = JSON.stringify(buildSnapshot(S, { timer: useUI.getState().timer, ready: readyFor(S) }))if (json !== lastSent) {@@ -284,11 +291,13 @@ export async function startWatchSync ({ useStore, useUI }) {}} catch { /* no watch, or not now: the next change tries again */ }}- const schedule = () => { clearTimeout(tm); tm = setTimeout(send, SEND_DEBOUNCE_MS) }+ const schedule = () => { if (!linked) return; clearTimeout(tm); tm = setTimeout(send, SEND_DEBOUNCE_MS) }const offStore = useStore.subscribe((s, prev) => { if (s.S !== prev.S) schedule() })- const offUI = useUI.subscribe((s, prev) => { if (s.timer !== prev.timer) schedule() })+ // The rest as the watch needs it changes when it starts, stops or is paused, not every second.+ const restOf = t => (t ? `${t.endsAt}|${!!t.paused}|${!!t.ready}` : '')+ const offUI = useUI.subscribe((s, prev) => { if (s.timer !== prev.timer && restOf(s.timer) !== restOf(prev.timer)) schedule() })const sub = await p.WatchBridge.addListener('watchEvent', () => { drainWatchEvents() })- const onVisible = () => { if (document.visibilityState === 'visible') { drainWatchEvents(); schedule() } }+ const onVisible = () => { if (document.visibilityState === 'visible') { drainWatchEvents(); checkLink().then(() => schedule()) } }document.addEventListener('visibilitychange', onVisible)schedule()drainWatchEvents()