From 2c5678e877ee3ac161569c06eac4671a1a5e5472 Mon Sep 17 00:00:00 2001 From: Sebastian G Date: Thu, 3 Sep 2026 10:16:31 +0200 Subject: [PATCH] feat(update): gate in-app updater to Android only The updater downloads an .apk and hands it to the system package installer, which only exists on Android. Add an isAndroid() flag in mobile.js and run the update check behind it, so the update row never appears on iOS or the web build. --- frontend/src/lib/mobile.js | 16 ++++++++++++++++ frontend/src/views/Settings.gifsize.test.jsx | 2 +- frontend/src/views/Settings.jsx | 6 ++++-- frontend/src/views/week-start.test.jsx | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/frontend/src/lib/mobile.js b/frontend/src/lib/mobile.js index ab86449..8af59f8 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 a544911..3af1877 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 2dbf657..c2fe23c 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 34bf2a3..0792e11 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(),