mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-09-20 01:47:29 +02:00
Fix #63: decide layout from compile-time platform, not the webview user-agent
This commit is contained in:
+14
-5
@@ -1,10 +1,19 @@
|
||||
// Centralized platform detection. iOS WebViews report iPhone/iPad/iPod in the user
|
||||
// agent (not the literal "ios"), so they must be matched explicitly.
|
||||
// Platform is the compile-time build target, injected by the backend into
|
||||
// window.__HELIX_PLATFORM__ before app scripts run (see src-tauri/src/lib.rs). The UA is only a
|
||||
// fallback when that global is absent (SSR/prerender, plain-browser dev): some desktop WebKitGTK
|
||||
// builds report a mobile-looking user-agent. (#63)
|
||||
type HelixPlatform = { mobile: boolean; android: boolean; ios: boolean };
|
||||
|
||||
const injected: HelixPlatform | undefined =
|
||||
typeof window !== 'undefined'
|
||||
? (window as unknown as { __HELIX_PLATFORM__?: HelixPlatform }).__HELIX_PLATFORM__
|
||||
: undefined;
|
||||
|
||||
const ua = typeof navigator !== 'undefined' ? navigator.userAgent : '';
|
||||
|
||||
export const isAndroid = /android/i.test(ua);
|
||||
export const isIOS = /iphone|ipad|ipod/i.test(ua);
|
||||
export const isMobile = isAndroid || isIOS;
|
||||
export const isAndroid = injected ? injected.android : /android/i.test(ua);
|
||||
export const isIOS = injected ? injected.ios : /iphone|ipad|ipod/i.test(ua);
|
||||
export const isMobile = injected ? injected.mobile : isAndroid || isIOS;
|
||||
|
||||
// Themes that use the dark color scheme. Used by applyTheme() to toggle the
|
||||
// `dark` class on the root element. Keep this in sync when adding new themes.
|
||||
|
||||
Reference in New Issue
Block a user