Files
FarmaFinder/apps/frontend/src/utils/native.js
T
Antoni Nuñez Romeu 190b3d163d
Run Tests on Branches / Backend Tests (push) Successful in 3m38s
Run Tests on Branches / Frontend Tests (push) Successful in 3m28s
Restructure with Turborepo
2026-07-06 15:51:53 +02:00

39 lines
1.1 KiB
JavaScript

// Capacitor bootstrap — no-ops on the web, configures native shell on mobile.
// Plugins are dynamic-imported so the web bundle isn't penalized.
let initStarted = false;
export function isNativeApp() {
return typeof window !== 'undefined' && Boolean(window.Capacitor?.isNativePlatform?.());
}
export async function initNativeShell() {
if (initStarted || !isNativeApp()) return;
initStarted = true;
try {
const { StatusBar, Style } = await import('@capacitor/status-bar');
await StatusBar.setBackgroundColor({ color: '#27633a' }).catch(() => {});
await StatusBar.setStyle({ style: Style.Light }).catch(() => {});
} catch {
/* plugin not present — fine on web */
}
try {
const { SplashScreen } = await import('@capacitor/splash-screen');
await SplashScreen.hide({ fadeOutDuration: 250 }).catch(() => {});
} catch {
/* plugin not present — fine on web */
}
try {
const { App } = await import('@capacitor/app');
App.addListener('backButton', ({ canGoBack }) => {
if (canGoBack) window.history.back();
else App.exitApp();
});
} catch {
/* plugin not present — fine on web */
}
}