// src/mobile/entry.ts — the mobile WebView's single entrypoint (god document §4.3). // // Order is load-bearing: the chrome shim must install `globalThis.chrome` // before any other module evaluates, and the brain boots before the UI // mounts so `bridge.sendMessage`'s first call has a handler waiting. // // `background/entry.ts` already self-invokes `start()` at its own module // bottom (verified against source — this diverges from the god document's // illustrative sketch, which shows calling `start()` again explicitly; doing // that here would run session-restore, setupAutoLock, and // setupClipboardClearAlarm a second time). Importing it for the side effect // is sufficient. `popup/index.tsx` similarly self-mounts `` and, on // native platforms, also calls `setupMessageHandler()` again — harmless, // since that registration is idempotent (see chrome-shim.ts's dispatch // comment for why running it twice doesn't invoke `handleMessage` twice). import "./chrome-shim"; import "../background/entry"; import "../popup/index"; import { ensureSettingsLoaded, isUnlocked, lock } from "../background/vault"; import { isRecoveryConfirmPending } from "../background/recovery-pending"; import { denyAllPendingPasskeyRequests } from "../background/passkey"; import { nativePlugin } from "../shared/native"; // Lock-on-close, mobile-shaped (§4.4 point 1): entry.ts's real lock-on-close // listens for the popup's `chrome.runtime.onConnect` port disconnecting — // there is no such port here, so peach-android's NativeBridge pushes // foreground/background over the bridge instead. Same intent (mirrors // entry.ts's onDisconnect body exactly), native trigger. nativePlugin<{ onLifecycle(cb: (s: "foreground" | "background") => void): void }>("PeachNative")?.onLifecycle( (state) => { if (state !== "background") return; void (async () => { await denyAllPendingPasskeyRequests(); const settings = await ensureSettingsLoaded(); if (!isUnlocked() || settings.lockOnClose === false) return; if (await isRecoveryConfirmPending()) return; lock(); })(); } );