import { Capacitor } from "@capacitor/core"; import { setupMessageHandler } from "./messages"; import { setupAutoLock } from "./alarms"; import { setupPasskeyProxy } from "./passkey"; import { setupCommands } from "./commands"; // Keep alive for MV3 service worker chrome.runtime.onInstalled.addListener(() => {}); // The chrome.idle.onStateChanged listener lives in ./alarms (the architectural // home for auto-lock timing). Keeping it in only one place avoids drift. async function setupSyncLifecycle(): Promise { if (Capacitor.isNativePlatform()) return; try { const sync = await import("./sync"); const lifecycle = await import("./sync-lifecycle"); // Register the incoming pairing subscriber once. Best-effort: subsequent // sync.connectSyncHost / advertise calls trigger PEER_CONNECTED events // that route through the subscriber. lifecycle.setupIncomingPairingSubscriber(); try { sync.connectSyncHost(); lifecycle.onNativeHostConnected(); } catch { // Native host not installed yet — lifecycle will engage when it is. } } catch (err) { console.warn("setupSyncLifecycle failed:", err); } } export function start() { setupMessageHandler(); void setupAutoLock(); setupCommands(); void setupPasskeyProxy(); void setupSyncLifecycle(); } start();