A local-first personal finance app
[AI] Add isNativeMobileApp platform flag and gate web-only UI behind it (#9383)
Matiss Janis Aboltins4548275a68da
diff --git a/packages/desktop-client/src/browser-preload.js b/packages/desktop-client/src/browser-preload.jsindex 667c46c61a..a7ea56d6a1 100644--- a/packages/desktop-client/src/browser-preload.js+++ b/packages/desktop-client/src/browser-preload.js@@ -88,16 +88,17 @@ const isUpdateReadyForDownloadPromise = new Promise(resolve => {};});// Skip SW registration in dev so stale cached assets don't override edits-// between page loads. Plugin code that needs a SW can register one itself.-// In dev there is no SW to install, so applyAppUpdate() can't rely on the-// SW lifecycle to swap the page — fall back to a plain reload so callers-// don't hang on the never-resolving promise inside applyAppUpdate.-const updateSW = IS_DEV- ? () => window.location.reload()- : registerSW({- immediate: true,- onNeedRefresh: markUpdateReadyForDownload,- });+// between page loads, and in the native mobile apps, whose assets ship in the+// app bundle and update via the app stores. Plugin code that needs a SW can+// register one itself. Without a SW, applyAppUpdate() falls back to a plain+// reload so callers don't hang on its never-resolving promise.+const updateSW =+ IS_DEV || Platform.isNativeMobileApp+ ? () => window.location.reload()+ : registerSW({+ immediate: true,+ onNeedRefresh: markUpdateReadyForDownload,+ });global.Actual = {IS_DEV,diff --git a/packages/desktop-client/src/components/manager/ConfigServer.tsx b/packages/desktop-client/src/components/manager/ConfigServer.tsxindex b4ee6ae073..62409391cb 100644--- a/packages/desktop-client/src/components/manager/ConfigServer.tsx+++ b/packages/desktop-client/src/components/manager/ConfigServer.tsx@@ -10,6 +10,7 @@ import { Text } from '@actual-app/components/text';import { theme } from '@actual-app/components/theme';import { View } from '@actual-app/components/view';import { isElectron } from '@actual-app/core/shared/environment';+import * as Platform from '@actual-app/core/shared/platform';import { css } from '@emotion/css';import { Link } from '#components/common/Link';@@ -431,7 +432,7 @@ export function ConfigServer() {</Trans>)}</Text>- {!currentUrl && (+ {!currentUrl && !Platform.isNativeMobileApp && (<Textstyle={{fontSize: 16,@@ -534,7 +535,7 @@ export function ConfigServer() {</Button>) : (<>- {!isElectron() && (+ {!isElectron() && !Platform.isNativeMobileApp && (<Buttonvariant="bare"style={{ color: theme.pageTextLink }}diff --git a/packages/desktop-client/src/util/versions.ts b/packages/desktop-client/src/util/versions.tsindex b3c75126a0..354d5082af 100644--- a/packages/desktop-client/src/util/versions.ts+++ b/packages/desktop-client/src/util/versions.ts@@ -54,6 +54,11 @@ export async function getLatestVersion(): Promise<string | 'unknown'> {if (Platform.isPlaywright || import.meta.env.REACT_APP_REVIEW_ID) {return Promise.resolve('v99.9.9');}+ // The native mobile apps update through the app stores, so a newer GitHub+ // release is nothing the user can act on. Skip the request entirely.+ if (Platform.isNativeMobileApp) {+ return Promise.resolve('unknown');+ }try {const response = await fetch(diff --git a/packages/loot-core/src/platform/client/browser-preload/start.ts b/packages/loot-core/src/platform/client/browser-preload/start.tsindex 89a1363029..549492852d 100644--- a/packages/loot-core/src/platform/client/browser-preload/start.ts+++ b/packages/loot-core/src/platform/client/browser-preload/start.ts@@ -1,6 +1,7 @@import { initBackend as initSQLBackend } from 'absurd-sql/dist/indexeddb-main-thread';import { logger } from '#platform/server/log';+import * as Platform from '#shared/platform';import { WorkerBridge } from './worker-bridge';@@ -44,7 +45,7 @@ export function startBrowserBackend(// Capacitor serves the app from a custom URL scheme, which WebKit never// treats as cross-origin isolated, so SharedArrayBuffer is unavailable in// the native mobile app. Always run it in the fallback mode there.- if ('Capacitor' in window) {+ if (Platform.isNativeMobileApp) {localStorage.setItem('SharedArrayBufferOverride', 'true');}diff --git a/packages/loot-core/src/shared/platform.api.ts b/packages/loot-core/src/shared/platform.api.tsindex ce51ccfd52..654af5cf59 100644--- a/packages/loot-core/src/shared/platform.api.ts+++ b/packages/loot-core/src/shared/platform.api.ts@@ -3,6 +3,7 @@ export const isPlaywright = false;export const OS: 'windows' | 'mac' | 'linux' | 'unknown' = 'unknown';export const env: 'web' | 'mobile' | 'unknown' = 'unknown';export const isBrowser: boolean = false;+export const isNativeMobileApp: boolean = false;export const isIOSAgent = false;export const isAndroid = false;diff --git a/packages/loot-core/src/shared/platform.electron.ts b/packages/loot-core/src/shared/platform.electron.tsindex 4043e64ab4..ebcc80d283 100644--- a/packages/loot-core/src/shared/platform.electron.ts+++ b/packages/loot-core/src/shared/platform.electron.ts@@ -17,6 +17,7 @@ export const OS: typeof T.OS = isWindows: 'unknown';export const env: typeof T.env = 'unknown';export const isBrowser: typeof T.isBrowser = false;+export const isNativeMobileApp: typeof T.isNativeMobileApp = false;export const isIOSAgent: typeof T.isIOSAgent = false;export const isIOS: typeof T.isIOS = false;diff --git a/packages/loot-core/src/shared/platform.ts b/packages/loot-core/src/shared/platform.tsindex ce70b1518d..37c82125ff 100644--- a/packages/loot-core/src/shared/platform.ts+++ b/packages/loot-core/src/shared/platform.ts@@ -20,6 +20,14 @@ export const OS: 'windows' | 'mac' | 'linux' | 'unknown' = isWindowsexport const env: 'web' | 'mobile' | 'unknown' = 'web';export const isBrowser: boolean = true;+// True inside the Capacitor (App Store / Play Store) builds. The native shell+// injects window.Capacitor before any page script runs; on the plain web the+// global may also exist once @capacitor/core is loaded, but reports false.+export const isNativeMobileApp: boolean =+ (+ globalThis as { Capacitor?: { isNativePlatform?: () => boolean } }+ ).Capacitor?.isNativePlatform?.() === true;+const userAgent = navigator.userAgent;// True for all browsers on iOS (iPhone/iPad/iPod) — not macOS.diff --git a/upcoming-release-notes/gate-web-only-ui-in-native-mobile-apps.md b/upcoming-release-notes/gate-web-only-ui-in-native-mobile-apps.mdnew file mode 100644index 0000000000..bc181e2c90--- /dev/null+++ b/upcoming-release-notes/gate-web-only-ui-in-native-mobile-apps.md@@ -0,0 +1,6 @@+---+category: Enhancements+authors: [MatissJanis]+---++Mobile apps: stop registering the web update mechanism, and hide the "new version available" notice and the self-hosting setup hint, since updates and setup work differently there