Skip to content

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.

iOS: the Vibrate switch works on the iPhone, and a UI test walks the app in the simulator

Duarte Santos0c0fa743b6d9
diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml
index 40334f7de..ae671bcf8 100644
--- a/.github/workflows/ios.yml
+++ b/.github/workflows/ios.yml
@@ -81,6 +81,53 @@ jobs:
frontend/ios/App/build/first-screen.png
retention-days: 7
+ # A walk through the app in the simulator (ios/App/AppUITests): a rest that ends while the app
+ # is in the background must arrive as a notification, a sheet must stay above the keyboard.
+ # The exercise media are left out of this build; the screenshots show placeholders.
+ ui-tests:
+ runs-on: macos-26
+ timeout-minutes: 60
+ steps:
+ - uses: actions/checkout@v7
+ - uses: actions/setup-node@v7
+ with:
+ node-version: 22
+ cache: npm
+ cache-dependency-path: frontend/package-lock.json
+ - run: npm ci
+ working-directory: frontend
+ - run: npm run build:mobile && rm -rf ios/App/App/public/exercise-media
+ working-directory: frontend
+ - run: ruby ios/ci/add-ui-tests.rb
+ working-directory: frontend
+ - name: Run the UI tests
+ working-directory: frontend/ios/App
+ run: |
+ UDID=$(xcrun simctl list devices available -j | node -e '
+ const d = JSON.parse(require("fs").readFileSync(0)).devices
+ const all = Object.entries(d).filter(([k]) => k.includes("iOS")).flatMap(([, v]) => v)
+ process.stdout.write(all.filter(x => /^iPhone/.test(x.name)).pop().udid)')
+ xcrun simctl boot "$UDID" && xcrun simctl bootstatus "$UDID" -b
+ set -o pipefail
+ xcodebuild test -workspace App.xcworkspace -scheme AppUITests -destination "id=$UDID" \
+ -resultBundlePath build/ui.xcresult CODE_SIGNING_ALLOWED=NO \
+ | tee build/ui-tests.log | grep -E "error:|Test Case|passed|failed|TEST" || exit 1
+ - name: Keep the screenshots
+ if: always()
+ working-directory: frontend/ios/App
+ run: |
+ mkdir -p build/shots
+ xcrun xcresulttool export attachments --path build/ui.xcresult --output-path build/shots || true
+ ls build/shots
+ - uses: actions/upload-artifact@v6
+ if: always()
+ with:
+ name: ios-ui-tests
+ path: |
+ frontend/ios/App/build/ui-tests.log
+ frontend/ios/App/build/shots
+ retention-days: 7
+
# The App Store build without its signature, for the release machine to put the full-quality
# animations in and sign (scripts/ios/finish-ipa.sh). Built for devices; its media are the
# repo's 180 px ones.
diff --git a/frontend/ios/App/App/RestAlertPlugin.swift b/frontend/ios/App/App/RestAlertPlugin.swift
index e6868894c..ea3776a22 100644
--- a/frontend/ios/App/App/RestAlertPlugin.swift
+++ b/frontend/ios/App/App/RestAlertPlugin.swift
@@ -16,8 +16,8 @@ import UserNotifications
* hold() calls the notification off; resuming schedules it again.
*
* tone() plays the end tone with the app in front through the audio session, which turns music
- * down for it and back up after (a page's Web Audio cannot). buzz() is the phone's one vibration:
- * iOS has no patterns.
+ * down for it and back up after (a page's Web Audio cannot). buzz() stands in for the page's
+ * navigator.vibrate, which iOS does not have.
*/
@objc(RestAlertPlugin)
public class RestAlertPlugin: CAPPlugin, CAPBridgedPlugin {
@@ -94,9 +94,30 @@ public class RestAlertPlugin: CAPPlugin, CAPBridgedPlugin {
call.resolve()
}
+ /**
+ * The page's vibration pattern (on, off, on, … in milliseconds). iOS has one vibration of its
+ * own length and no patterns, so each pulse of 100 ms or more is that vibration at its moment
+ * in the pattern, and a shorter one (a set tick) is a tap of the haptic engine.
+ */
@objc func buzz(_ call: CAPPluginCall) {
- AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
- call.resolve()
+ let pattern = (call.getArray("pattern") as? [NSNumber])?.map { $0.doubleValue } ?? [400]
+ DispatchQueue.main.async {
+ var at = 0.0
+ for (i, ms) in pattern.enumerated() {
+ if i % 2 == 0 && ms > 0 {
+ let long = ms >= 100
+ DispatchQueue.main.asyncAfter(deadline: .now() + at / 1000) {
+ if long {
+ AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
+ } else {
+ UIImpactFeedbackGenerator(style: .medium).impactOccurred()
+ }
+ }
+ }
+ at += ms
+ }
+ call.resolve()
+ }
}
@objc func tone(_ call: CAPPluginCall) {
diff --git a/frontend/ios/App/AppUITests/OpenGymUITests.swift b/frontend/ios/App/AppUITests/OpenGymUITests.swift
new file mode 100644
index 000000000..5f5c40ba4
--- /dev/null
+++ b/frontend/ios/App/AppUITests/OpenGymUITests.swift
@@ -0,0 +1,77 @@
+import XCTest
+
+/**
+ * Walks the iPhone app the way someone new does and checks what only a real phone shows: that the
+ * end of a rest still arrives as a notification once the app has left the screen (RestAlertPlugin),
+ * and that a sheet with a text field stays above the keyboard. Run by .github/workflows/ios.yml,
+ * which adds this target to the project for the run only (ios/ci/add-ui-tests.rb). The run's
+ * build carries no exercise media, so the screenshots it keeps show placeholders.
+ */
+final class OpenGymUITests: XCTestCase {
+ let app = XCUIApplication()
+ let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
+
+ override func setUp() {
+ continueAfterFailure = false
+ }
+
+ private func shot(_ name: String) {
+ let a = XCTAttachment(screenshot: XCUIScreen.main.screenshot())
+ a.name = name
+ a.lifetime = .keepAlways
+ add(a)
+ }
+
+ private func tap(_ e: XCUIElement, _ what: String, timeout: TimeInterval = 15) {
+ XCTAssertTrue(e.waitForExistence(timeout: timeout), "\(what) did not show up")
+ e.tap()
+ }
+
+ private func button(startingWith prefix: String) -> XCUIElement {
+ app.buttons.matching(NSPredicate(format: "label BEGINSWITH %@", prefix)).firstMatch
+ }
+
+ /** "Allow" on the notification question, whenever iOS asks it. */
+ private func allowNotificationsIfAsked() {
+ let allow = springboard.alerts.buttons["Allow"]
+ if allow.waitForExistence(timeout: 6) { allow.tap() }
+ }
+
+ func testRestEndsWithANotificationInTheBackground() {
+ app.launch()
+ tap(app.buttons["Use on this device"], "the onboarding choice", timeout: 40)
+ shot("1-home")
+ tap(app.buttons["Load starter plan"], "Load starter plan")
+ tap(button(startingWith: "Full Body"), "the Full Body plan")
+ tap(app.buttons["Choose a different workout"], "Choose a different workout")
+ tap(app.staticTexts["Full Body A"], "Full Body A")
+ shot("2-workout")
+ tap(app.buttons["Set 1 done"], "Set 1 done")
+ allowNotificationsIfAsked()
+ XCTAssertTrue(button(startingWith: "1:").waitForExistence(timeout: 10), "no rest countdown after a set")
+ shot("3-rest")
+
+ XCUIDevice.shared.press(.home)
+ // The rest is 90 s; its end has to arrive on its own, with the app in the background.
+ let banner = springboard.descendants(matching: .any)
+ .matching(NSPredicate(format: "label CONTAINS[c] %@", "Next set")).firstMatch
+ let arrived = banner.waitForExistence(timeout: 120)
+ shot("4-notification")
+ XCTAssertTrue(arrived, "the end of the rest never arrived as a notification")
+ }
+
+ func testWeighInSheetStaysAboveTheKeyboard() {
+ app.launch()
+ let local = app.buttons["Use on this device"]
+ if local.waitForExistence(timeout: 40) { local.tap() }
+ tap(app.buttons["Log"], "Log (body weight)")
+ let field = app.textFields.firstMatch
+ tap(field, "the weight field")
+ XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 10), "no keyboard")
+ shot("5-keyboard")
+ let save = app.buttons["Save"]
+ XCTAssertTrue(save.waitForExistence(timeout: 5), "no Save button")
+ let keyboardTop = app.keyboards.firstMatch.frame.minY
+ XCTAssertLessThanOrEqual(save.frame.maxY, keyboardTop + 1, "Save sits under the keyboard")
+ }
+}
diff --git a/frontend/ios/ci/add-ui-tests.rb b/frontend/ios/ci/add-ui-tests.rb
new file mode 100644
index 000000000..7d4f238d5
--- /dev/null
+++ b/frontend/ios/ci/add-ui-tests.rb
@@ -0,0 +1,29 @@
+# Adds the UI test target (ios/App/AppUITests) and a scheme for it to App.xcodeproj, for one CI
+# run (.github/workflows/ios.yml). Kept out of the committed project so the app's own project
+# stays what Capacitor generated. Uses the xcodeproj gem that ships with CocoaPods.
+require 'xcodeproj'
+
+dir = File.expand_path('../App', __dir__)
+proj = Xcodeproj::Project.open(File.join(dir, 'App.xcodeproj'))
+app = proj.targets.find { |t| t.name == 'App' }
+tests = proj.new_target(:ui_test_bundle, 'AppUITests', :ios, '15.5')
+tests.add_dependency(app)
+group = proj.main_group.new_group('AppUITests', 'AppUITests')
+tests.add_file_references([group.new_file('OpenGymUITests.swift')])
+tests.build_configurations.each do |c|
+ s = c.build_settings
+ s['TEST_TARGET_NAME'] = 'App'
+ s['PRODUCT_BUNDLE_IDENTIFIER'] = 'ch.duartesantos.opengym.uitests'
+ s['SWIFT_VERSION'] = '5.0'
+ s['GENERATE_INFOPLIST_FILE'] = 'YES'
+ s['TARGETED_DEVICE_FAMILY'] = '1,2'
+ s['CODE_SIGN_STYLE'] = 'Automatic'
+end
+proj.save
+
+scheme = Xcodeproj::XCScheme.new
+scheme.add_build_target(app)
+scheme.set_launch_target(app)
+scheme.add_test_target(tests)
+scheme.save_as(File.join(dir, 'App.xcodeproj'), 'AppUITests', true)
+puts 'added AppUITests'
diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx
index e3ab903a3..e63f3466e 100644
--- a/frontend/src/App.jsx
+++ b/frontend/src/App.jsx
@@ -7,7 +7,7 @@ import { setWeightDecimals } from './lib/format.js'
import { accentValue, applyAccent } from './lib/accent.js'
import { setLang, useLang, baseLang } from './lib/i18n.js'
import { effectiveLang } from './lib/default-lang.js'
-import { setPlayOnSilent, setVibrate, setAlarmBuzzer } from './lib/sound.js'
+import { setPlayOnSilent, setVibrate, setAlarmBuzzer, setNativeBuzzer } from './lib/sound.js'
import { buzzAsAlarm } from './lib/rest-alert.js'
import { setNav } from './lib/nav.js'
import { setSystemBarsLight } from './lib/system-bars.js'
@@ -16,7 +16,7 @@ import { useWakeLock } from './lib/wakelock.js'
import { installViewportGuard } from './lib/viewport-guard.js'
import { installChipDrag } from './lib/hchips.js'
import { syncPushSubscription } from './lib/push.js'
-import { MOBILE } from './lib/mobile.js'
+import { MOBILE, nativePlatform } from './lib/mobile.js'
import { exitWorkoutEdit, startFlow } from './sheets.jsx'
import Icon from './components/Icon.jsx'
import TabBar from './components/TabBar.jsx'
@@ -79,6 +79,8 @@ function Shell() {
// Android app: "Vibrate when the phone is on silent" sends the end-of-rest buzz through the
// native side as an alarm (#375). buzzAsAlarm answers false off Android, so iOS buzzes as before.
useEffect(() => { setAlarmBuzzer(MOBILE && S.vibrate !== false && S.vibrateOnSilent ? buzzAsAlarm : null) }, [S.vibrate, S.vibrateOnSilent])
+ // iPhone app: the page cannot buzz (no navigator.vibrate), its native side can.
+ useEffect(() => { if (MOBILE) nativePlatform().then(p => { if (p === 'ios') setNativeBuzzer(buzzAsAlarm) }) }, [])
const isGuest = useStore(s => s.isGuest())
const needsMobileOnboarding = useStore(s => s.needsMobileOnboarding)
const langV = useLang() // re-renders the whole shell when the language (pack) changes
diff --git a/frontend/src/lib/sound.js b/frontend/src/lib/sound.js
index 8e38da52c..3d42d7cc8 100644
--- a/frontend/src/lib/sound.js
+++ b/frontend/src/lib/sound.js
@@ -167,10 +167,18 @@ export function setPlayOnSilent(on) {
let buzz = true
export function setVibrate(on) { buzz = on !== false }
// Offered where the browser can buzz at all: iOS has no navigator.vibrate. The Android app needs
-// android.permission.VIBRATE in its manifest, without which the WebView drops every call.
-export const vibrateSupported = () => typeof navigator !== 'undefined' && typeof navigator.vibrate === 'function'
+// android.permission.VIBRATE in its manifest, without which the WebView drops every call. The
+// iPhone app buzzes through its native side instead (RestAlertPlugin.swift buzz), which App.jsx
+// hands in here as the native buzzer.
+let nativeBuzzer = null
+export function setNativeBuzzer(fn) { nativeBuzzer = typeof fn === 'function' ? fn : null }
+export const vibrateSupported = () => !!nativeBuzzer || (typeof navigator !== 'undefined' && typeof navigator.vibrate === 'function')
export function vibrate(p) {
if (!buzz) return
+ if (nativeBuzzer) {
+ try { Promise.resolve(nativeBuzzer(p)).catch(() => {}) } catch (e) { /* */ }
+ return
+ }
try { navigator.vibrate && navigator.vibrate(p) } catch (e) { /* */ }
}
diff --git a/frontend/src/lib/sound.test.js b/frontend/src/lib/sound.test.js
index 348de62bf..0d961914c 100644
--- a/frontend/src/lib/sound.test.js
+++ b/frontend/src/lib/sound.test.js
@@ -436,6 +436,22 @@ describe('vibrate switch', () => {
expect(sound.vibrateSupported()).toBe(false)
expect(() => sound.vibrate(30)).not.toThrow()
})
+
+ it('the iPhone app, without navigator.vibrate, buzzes through its native side', () => {
+ Object.defineProperty(navigator, 'vibrate', { value: undefined, configurable: true, writable: true })
+ const native = []
+ sound.setNativeBuzzer(p => { native.push(p); return Promise.resolve(true) })
+ try {
+ expect(sound.vibrateSupported()).toBe(true)
+ sound.vibrate([200, 100, 200])
+ sound.setVibrate(false)
+ sound.vibrate(30)
+ expect(native).toEqual([[200, 100, 200]])
+ } finally {
+ sound.setNativeBuzzer(null)
+ sound.setVibrate(true)
+ }
+ })
})
// #375: the end of a rest or a hold, with "Vibrate when the phone is on silent" on in the Android