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.

feat(update): gate in-app updater to Android only

Sebastian G2c5678e877ee
diff --git a/frontend/src/lib/mobile.js b/frontend/src/lib/mobile.js
index ab8644933..8af59f896 100644
--- a/frontend/src/lib/mobile.js
+++ b/frontend/src/lib/mobile.js
@@ -15,6 +15,22 @@ import { effectiveRoutineId } from './history.js'
export const MOBILE = import.meta.env.VITE_MOBILE === '1'
+// Some features only make sense on Android. The in-app updater downloads an .apk and hands it
+// to the system package installer — there is no equivalent on iOS (App Store only) or on the
+// web build. On anything but a native Android shell this must stay off.
+//
+// @capacitor/core is imported dynamically (like every other Capacitor dependency here) so it
+// never lands in the web bundle. Capacitor.getPlatform() returns 'android' | 'ios' | 'web'.
+export async function isAndroid() {
+ if (!MOBILE) return false
+ try {
+ const { Capacitor } = await import('@capacitor/core')
+ return Capacitor.getPlatform() === 'android'
+ } catch (e) {
+ return false
+ }
+}
+
const FILE = 'opengym-state.json'
export async function nativeLoad() {
diff --git a/frontend/src/views/Settings.gifsize.test.jsx b/frontend/src/views/Settings.gifsize.test.jsx
index a544911aa..3af1877bf 100644
--- a/frontend/src/views/Settings.gifsize.test.jsx
+++ b/frontend/src/views/Settings.gifsize.test.jsx
@@ -38,7 +38,7 @@ vi.mock('../lib/api.js', () => ({
}))
vi.mock('../lib/push.js', () => ({ pushSupported: () => false, enablePush: vi.fn(), disablePush: vi.fn(), sendTestPush: vi.fn() }))
vi.mock('../lib/wakelock.js', () => ({ wakeLockSupported: () => false }))
-vi.mock('../lib/mobile.js', () => ({ MOBILE: false, shareExport: vi.fn(), syncReminder: vi.fn() }))
+vi.mock('../lib/mobile.js', () => ({ MOBILE: false, isAndroid: () => Promise.resolve(false), shareExport: vi.fn(), syncReminder: vi.fn() }))
vi.mock('./MobileOnboarding.jsx', () => ({ ConnectSheet: () => null }))
vi.mock('../sheets.jsx', () => ({
loadStarterPlan: vi.fn(), confirmSheet: vi.fn(), importFromApp: vi.fn(),
diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsx
index 2dbf65724..c2fe23c60 100644
--- a/frontend/src/views/Settings.jsx
+++ b/frontend/src/views/Settings.jsx
@@ -9,7 +9,7 @@ import { pushSupported, enablePush, disablePush, sendTestPush } from '../lib/pus
import { wakeLockSupported } from '../lib/wakelock.js'
import { t, LANGS, INSTR_LANGS } from '../lib/i18n.js'
import { DEMO, REPO } from '../lib/demo.js'
-import { MOBILE, shareExport, syncReminder } from '../lib/mobile.js'
+import { MOBILE, isAndroid, shareExport, syncReminder } from '../lib/mobile.js'
import { checkForUpdate, downloadAndInstall } from '../lib/update.js'
import { ConnectSheet } from './MobileOnboarding.jsx'
import { loadStarterPlan, confirmSheet, importFromApp, importFromHevy, equipmentProfileSheet } from '../sheets.jsx'
@@ -32,7 +32,9 @@ export default function Settings() {
const [updateInfo, setUpdateInfo] = useState(null) // { hasUpdate, latestVersion, apkUrl, hashUrl } | null
useEffect(() => {
- checkForUpdate().then(setUpdateInfo).catch(() => {})
+ // The in-app updater installs an .apk, so it only applies to the native Android build.
+ // On iOS and the web this check is skipped and the update row never appears.
+ isAndroid().then(ok => { if (ok) checkForUpdate().then(setUpdateInfo).catch(() => {}) })
}, [])
const onUpdateRowClick = () => {
diff --git a/frontend/src/views/week-start.test.jsx b/frontend/src/views/week-start.test.jsx
index 34bf2a3ca..0792e1108 100644
--- a/frontend/src/views/week-start.test.jsx
+++ b/frontend/src/views/week-start.test.jsx
@@ -41,7 +41,7 @@ vi.mock('../lib/api.js', () => ({
}))
vi.mock('../lib/push.js', () => ({ pushSupported: () => false, enablePush: vi.fn(), disablePush: vi.fn(), sendTestPush: vi.fn() }))
vi.mock('../lib/wakelock.js', () => ({ wakeLockSupported: () => false }))
-vi.mock('../lib/mobile.js', () => ({ MOBILE: false, shareExport: vi.fn(), syncReminder: vi.fn() }))
+vi.mock('../lib/mobile.js', () => ({ MOBILE: false, isAndroid: () => Promise.resolve(false), shareExport: vi.fn(), syncReminder: vi.fn() }))
vi.mock('./MobileOnboarding.jsx', () => ({ ConnectSheet: () => null }))
vi.mock('../sheets.jsx', () => ({
loadStarterPlan: vi.fn(), confirmSheet: vi.fn(), importFromApp: vi.fn(),