1import { createEffect, createMemo, createSignal, lazy, onCleanup, onMount, Show, Suspense } from "solid-js";2import { ACCENT_COLORS } from "../shared/types";3import type { AccentColorName, PasskeyEntry, PendingPasskeyRequest, ProFeature, VaultEntry } from "../shared/types";4import { LockView } from "./views/Lock";5import { Onboarding } from "./views/Onboarding";6import { ProCelebration } from "./views/ProCelebration";7import { VaultView, type SortOrder } from "./views/Vault";8import { EntryView } from "./views/Entry";9import { AddView } from "./views/Add";10import { PeachWordmark } from "./components/PeachMark";11import { PasskeyApprovalView } from "./views/PasskeyApproval";12import { PasskeyEntryView } from "./views/PasskeyEntry";13import { extractDomain } from "../shared/domain";14import { popupCopy } from "./copy";15import {16 DEFAULT_BINDINGS,17 formatKeybinding,18 getActiveBindings,19 matchKeybinding,20 SHORTCUT_DESCRIPTORS,21 type Keybinding,22 type ShortcutAction,23} from "../shared/shortcuts";24import { generateTOTP } from "../crypto/totp";2526const ImportView = lazy(() => import("./views/Import").then(m => ({ default: m.ImportView })));27const ExportView = lazy(() => import("./views/Export").then(m => ({ default: m.ExportView })));28const SettingsView = lazy(() => import("./views/Settings").then(m => ({ default: m.SettingsView })));29const HealthView = lazy(() => import("./views/Health").then(m => ({ default: m.HealthView })));30const TrashView = lazy(() => import("./views/TrashView").then(m => ({ default: m.TrashView })));31const PanicView = lazy(() => import("./views/Panic").then(m => ({ default: m.PanicView })));3233type View =34 | "lock"35 | "pro-celebration"36 | "entry"37 | "list"38 | "add"39 | "settings"40 | "import"41 | "export"42 | "health"43 | "trash"44 | "panic";45type BootState = "loading" | "ready";4647const canarySuppressMap = new Map<string, boolean>();48let shellRingAnimation: Animation | null = null;4950export function isCanarySuppressed(entryId: string): boolean {51 return canarySuppressMap.get(entryId) ?? false;52}5354export function setCanarySuppressed(entryId: string, suppressed: boolean): void {55 canarySuppressMap.set(entryId, suppressed);56}5758export function clearCanarySuppressions(): void {59 canarySuppressMap.clear();60}6162export function triggerRing() {63 const shell = document.getElementById("hd-shell");64 if (!shell) return;6566 shellRingAnimation?.cancel();67 shell.dataset.glowing = "true";68 const animation = shell.animate(69 [70 { offset: 0, boxShadow: "var(--copy-shadow)" },71 {72 offset: 0.3,73 boxShadow:74 "0 2px 8px rgba(0,0,0,0.5), 0 14px 48px rgba(0,0,0,0.6), 0 0 0 1.5px color-mix(in srgb, var(--peach-accent) 58%, transparent), 0 0 22px color-mix(in srgb, var(--peach-accent) 18%, transparent)",75 },76 { offset: 1, boxShadow: "var(--copy-shadow)" },77 ],78 {79 duration: 720,80 easing: "cubic-bezier(0.4, 0, 0.2, 1)",81 fill: "none",82 }83 );84 shellRingAnimation = animation;85 const clearGlow = () => {86 if (shellRingAnimation !== animation) return;87 shellRingAnimation = null;88 delete shell.dataset.glowing;89 };90 animation.onfinish = clearGlow;91 animation.oncancel = clearGlow;92}939495export function triggerPipPulse() {96 const pip = document.querySelector(".peach-status-pip, .pip");97 if (pip) {98 pip.classList.remove("pulse");99 void (pip as HTMLElement).offsetWidth;100 pip.classList.add("pulse");101 }102}103104function humanizeError(error: string | undefined): string | undefined {105 if (!error) return error;106 if (error === "STORAGE_QUOTA_EXCEEDED") {107 return "Peach has run out of browser storage. Delete some entries or clear browser storage to continue.";108 }109 return error;110}111112async function sendMessage(msg: any): Promise<any> {113 const MESSAGE_TIMEOUT_MS = 5000;114115 return new Promise((resolve) => {116 let settled = false;117 const timeoutId = window.setTimeout(() => {118 if (settled) return;119 settled = true;120 resolve({ ok: false, error: "SERVICE_WORKER_UNAVAILABLE" });121 }, MESSAGE_TIMEOUT_MS);122123 try {124 chrome.runtime.sendMessage(msg, (response) => {125 if (settled) return;126 settled = true;127 window.clearTimeout(timeoutId);128129 if (chrome.runtime.lastError) {130 resolve({131 ok: false,132 error:133 chrome.runtime.lastError.message ?? "SERVICE_WORKER_UNAVAILABLE",134 });135 return;136 }137138 if (response === undefined) {139 resolve({ ok: false, error: "SERVICE_WORKER_UNAVAILABLE" });140 return;141 }142143 if (response && response.ok === false) {144 response.error = humanizeError(response.error);145 }146 resolve(response);147 });148 } catch (error) {149 if (settled) return;150 settled = true;151 window.clearTimeout(timeoutId);152 resolve({153 ok: false,154 error:155 error instanceof Error ? error.message : "SERVICE_WORKER_UNAVAILABLE",156 });157 }158 });159}160161export { sendMessage };162163const ENTRY_TRANSITION_EXIT_MS = 95;164const ENTRY_TRANSITION_SETTLE_MS = 135;165166export default function App() {167 const [bootState, setBootState] = createSignal<BootState>("loading");168 const [view, setView] = createSignal<View>("lock");169 const [contentPhase, setContentPhase] = createSignal<"enter" | "exit" | "idle">(170 "enter"171 );172 const [contentTransitioning, setContentTransitioning] = createSignal(false);173 const [hasVault, setHasVault] = createSignal(false);174 const [onboarded, setOnboarded] = createSignal(true);175 const [entries, setEntries] = createSignal<VaultEntry[]>([]);176 const [selectedEntry, setSelectedEntry] = createSignal<VaultEntry | null>(null);177 const [editEntry, setEditEntry] = createSignal<VaultEntry | undefined>(undefined);178 const [accentColor, setAccentColor] = createSignal<AccentColorName>("peach");179 const [theme, setTheme] = createSignal<"dark" | "light">("dark");180 const [displayFont, setDisplayFont] = createSignal<"cormorant-italic" | "cormorant" | "inter" | "system">("cormorant-italic");181 const [textSize, setTextSize] = createSignal<"small" | "medium" | "large">("medium");182 const [reduceMotion, setReduceMotion] = createSignal<boolean>(false);183 const [lockOnClose, setLockOnClose] = createSignal(true);184 const [autoLockMinutes, setAutoLockMinutes] = createSignal(5);185 const [breachMonitoring, setBreachMonitoring] = createSignal(true);186 const [shortcutBindings, setShortcutBindings] = createSignal<Record<ShortcutAction, Keybinding>>(DEFAULT_BINDINGS);187 const [showShortcutsHelp, setShowShortcutsHelp] = createSignal(false);188 const [trashRetentionDays, setTrashRetentionDays] = createSignal(30);189 const [restoreView, setRestoreView] = createSignal<"file" | null>(null);190 const [pendingPasskey, setPendingPasskey] = createSignal<PendingPasskeyRequest | null>(null);191 const [currentTabDomain, setCurrentTabDomain] = createSignal<string>("");192 193 194 195 196 const [proStatus, setProStatus] = createSignal(false);197 const [settingsInitialSection, setSettingsInitialSection] = createSignal<string | null>(null);198 const [upgradeHighlight, setUpgradeHighlight] = createSignal<ProFeature | null>(null);199 const [sortOrder, setSortOrder] = createSignal<SortOrder>("url-first");200 const [listSearchSeed, setListSearchSeed] = createSignal("");201 const [listSearchSeedNonce, setListSearchSeedNonce] = createSignal(0);202 const [pendingCelebration, setPendingCelebration] = createSignal(false);203 const [pendingProNotice, setPendingProNotice] = createSignal<{ feature: string } | null>(null);204 205 206 207 const [returnToPanic, setReturnToPanic] = createSignal(false);208209 let contentPhaseTimer: number | undefined;210211 function applyAccent(name: AccentColorName) {212 const color = ACCENT_COLORS.find(c => c.name === name) ?? ACCENT_COLORS[0]!;213 const hex = color.hex;214 document.documentElement.style.setProperty("--peach-accent", hex);215 216 217 document.documentElement.style.setProperty("--peach-glow", hex + "2A");218 document.documentElement.style.setProperty("--peach-surface-tint", hex + "09");219 document.documentElement.style.setProperty("--peach-border-accent", hex + "24");220 }221222 createEffect(() => {223 applyAccent(accentColor());224 });225226 createEffect(() => {227 document.documentElement.classList.toggle("light", theme() === "light");228 document.body.classList.toggle("light", theme() === "light");229 });230231 createEffect(() => {232 document.documentElement.setAttribute("data-display-font", displayFont());233 });234235 createEffect(() => {236 document.documentElement.setAttribute("data-text-size", textSize());237 });238239 createEffect(() => {240 if (reduceMotion()) {241 document.documentElement.setAttribute("data-motion", "reduce");242 } else {243 document.documentElement.removeAttribute("data-motion");244 }245 });246247 const selectedIndex = createMemo(() => {248 const currentId = selectedEntry()?.id;249 if (!currentId) return entries().length > 0 ? 0 : -1;250 return entries().findIndex((entry) => entry.id === currentId);251 });252253 async function applyAccentColor(name: AccentColorName) {254 applyAccent(name);255 setAccentColor(name);256 await sendMessage({ type: "UPDATE_SETTINGS", payload: { accentColor: name } });257 }258259 async function applyTheme(t: "dark" | "light") {260 setTheme(t);261 await sendMessage({ type: "UPDATE_SETTINGS", payload: { theme: t } });262 }263264 async function applyDisplayFont(f: "cormorant-italic" | "cormorant" | "inter" | "system") {265 setDisplayFont(f);266 await sendMessage({ type: "UPDATE_SETTINGS", payload: { displayFont: f } });267 }268269 async function applyTextSize(size: "small" | "medium" | "large") {270 setTextSize(size);271 await sendMessage({ type: "UPDATE_SETTINGS", payload: { textSize: size } });272 }273274 async function applyReduceMotion(enabled: boolean) {275 setReduceMotion(enabled);276 await sendMessage({ type: "UPDATE_SETTINGS", payload: { reduceMotion: enabled } });277 }278279 280 281 282 async function applyShortcuts(active: Record<ShortcutAction, Keybinding>) {283 setShortcutBindings(active);284 const overrides: Record<string, Keybinding> = {};285 for (const action of Object.keys(active) as ShortcutAction[]) {286 const a = active[action];287 const d = DEFAULT_BINDINGS[action];288 const same = a.key === d.key289 && Boolean(a.ctrl) === Boolean(d.ctrl)290 && Boolean(a.meta) === Boolean(d.meta)291 && Boolean(a.shift) === Boolean(d.shift)292 && Boolean(a.alt) === Boolean(d.alt);293 if (!same) overrides[action] = a;294 }295 await sendMessage({ type: "UPDATE_SETTINGS", payload: { shortcuts: overrides } });296 }297298 async function applyLockOnClose(enabled: boolean) {299 setLockOnClose(enabled);300 await sendMessage({301 type: "UPDATE_SETTINGS",302 payload: { lockOnClose: enabled },303 });304 }305306 async function applyAutoLockMinutes(minutes: number) {307 setAutoLockMinutes(minutes);308 await sendMessage({309 type: "UPDATE_SETTINGS",310 payload: { autoLockMinutes: minutes },311 });312 }313314 async function applyBreachMonitoring(enabled: boolean) {315 setBreachMonitoring(enabled);316 await sendMessage({317 type: "UPDATE_SETTINGS",318 payload: { breachMonitoring: enabled },319 });320 }321322 onMount(async () => {323 324 325 326 327 328 const [unlockResponse, vaultResponse, , celebrationResponse] = await Promise.all([329 sendMessage({ type: "IS_UNLOCKED" }),330 sendMessage({ type: "HAS_VAULT" }),331 refreshCurrentTab(),332 sendMessage({ type: "SHOULD_PLAY_CELEBRATION" }),333 ]);334 const unlocked = Boolean(335 (unlockResponse as { ok: boolean; data?: boolean }).data336 );337 const vaultExists = Boolean(338 (vaultResponse as { ok: boolean; data?: boolean }).data339 );340 const shouldCelebrate = Boolean(341 (celebrationResponse as { ok: boolean; data?: boolean }).data342 );343 setHasVault(vaultExists);344 345 346 347 try {348 const onboardingState = await chrome.storage.local.get("peach_onboarded");349 const seen = onboardingState.peach_onboarded === true;350 if (vaultExists && !seen) {351 await chrome.storage.local.set({ peach_onboarded: true });352 setOnboarded(true);353 } else {354 setOnboarded(seen);355 }356 } catch {357 358 setOnboarded(true);359 }360 await Promise.all([restoreSettings(), refreshProStatus()]);361362 363 if (shouldCelebrate) {364 await sendMessage({ type: "MARK_CELEBRATION_PLAYED" });365 }366367 if (unlocked && vaultExists) {368 await openVault(undefined, shouldCelebrate);369 if (shouldCelebrate) {370 setView("pro-celebration");371 window.setTimeout(() => setView("entry"), 2500);372 }373 } else if (shouldCelebrate) {374 setPendingCelebration(true);375 }376377 await refreshPendingPasskey();378379 380 const handleTabActivated = () => { void refreshCurrentTab(); };381 const handleTabUpdated = (_tabId: number, changeInfo: { url?: string; status?: string }) => {382 if (changeInfo.url || changeInfo.status === "complete") void refreshCurrentTab();383 };384 try {385 chrome.tabs.onActivated.addListener(handleTabActivated);386 chrome.tabs.onUpdated.addListener(handleTabUpdated);387 onCleanup(() => {388 chrome.tabs.onActivated.removeListener(handleTabActivated);389 chrome.tabs.onUpdated.removeListener(handleTabUpdated);390 });391 } catch {392 393 }394395 setBootState("ready");396 document.getElementById("pre-lock")?.setAttribute("hidden", "true");397398 399 if (chrome.storage.session) {400 const session = await chrome.storage.session.get(["pendingProGate", "pendingProNotice"]) as401 Record<string, { feature?: string } | undefined>;402 if (session.pendingProGate?.feature) {403 await chrome.storage.session.remove("pendingProGate");404 setUpgradeHighlight((session.pendingProGate.feature as ProFeature) ?? null);405 setSettingsInitialSection("license");406 setView("settings");407 } else if (session.pendingProNotice?.feature) {408 await chrome.storage.session.remove("pendingProNotice");409 setPendingProNotice({ feature: session.pendingProNotice.feature ?? "" });410 }411 }412413 414 415 416 417 void Promise.all([418 import("./views/Settings").catch(() => {}),419 import("./views/Import").catch(() => {}),420 import("./views/Export").catch(() => {}),421 import("./views/Health").catch(() => {}),422 import("./views/TrashView").catch(() => {}),423 ]);424425 426 427 428 let popupPort: chrome.runtime.Port | null = null;429 try {430 popupPort = chrome.runtime.connect({ name: "popup" });431 } catch { }432 onCleanup(() => { try { popupPort?.disconnect(); } catch {} });433434 435 436 const handleRuntimeMessage = (msg: { type?: string; payload?: { feature?: ProFeature } }) => {437 if (msg?.type === "VAULT_LOCKED" && view() !== "lock") handleLock();438 if (msg?.type === "PRO_GATE_TRIGGERED") {439 440 441 setUpgradeHighlight(msg.payload?.feature ?? null);442 setSettingsInitialSection("license");443 setView("settings");444 }445 };446 chrome.runtime.onMessage.addListener(handleRuntimeMessage);447 onCleanup(() => chrome.runtime.onMessage.removeListener(handleRuntimeMessage));448449 450 451 452 const SHORTCUT_HANDLERS: Partial<Record<ShortcutAction, () => void>> = {453 copy_password: () => {454 const entry = selectedEntry();455 if (entry?.password) void popupCopy(entry.password, "Password").then((ok) => { if (ok) triggerRing(); });456 },457 copy_username: () => {458 const entry = selectedEntry();459 if (entry?.username) void popupCopy(entry.username, "Username").then((ok) => { if (ok) triggerRing(); });460 },461 copy_totp: () => {462 const entry = selectedEntry();463 if (!entry?.totp) return;464 try {465 const { code } = generateTOTP(entry.totp);466 void popupCopy(code, "2FA").then((ok) => { if (ok) triggerRing(); });467 } catch { }468 },469 new_entry: () => handleAdd(),470 edit_entry: () => {471 const entry = selectedEntry();472 if (!entry || entry.type === "passkey") return;473 setEditEntry(entry);474 setView("add");475 },476 delete_entry: () => {477 if (selectedEntry()) void handleDelete();478 },479 lock_vault: () => { void handleHeaderLock(); },480 search: () => openList(),481 nav_prev: () => navigate(-1),482 nav_next: () => navigate(1),483 jump_vault: () => setView("entry"),484 jump_settings: () => setView("settings"),485 show_help: () => setShowShortcutsHelp(true),486 };487488 489 490 491 const ENTRY_SCOPED: ReadonlySet<ShortcutAction> = new Set([492 "copy_password", "copy_username", "copy_totp",493 "edit_entry", "delete_entry", "nav_prev", "nav_next",494 ]);495496 const handleGlobalKeydown = (e: KeyboardEvent) => {497 const v = view();498 const inInput = (e.target as HTMLElement)?.tagName === "INPUT"499 || (e.target as HTMLElement)?.tagName === "TEXTAREA"500 || (e.target as HTMLElement)?.isContentEditable;501 const isPrintableSearchKey =502 e.key.length === 1 &&503 !e.ctrlKey &&504 !e.metaKey &&505 !e.altKey;506507 508 if (v === "pro-celebration") return;509510 511 512 if (showShortcutsHelp()) {513 if (e.key === "Escape") { e.preventDefault(); setShowShortcutsHelp(false); }514 return;515 }516517 518 if (e.key === "Escape") {519 if (v === "list") { setView("entry"); return; }520 if (v === "settings" || v === "import" || v === "export" || v === "add" || v === "health") { handleBack(); return; }521 }522523 524 525 526 const bindings = shortcutBindings();527 for (const action of Object.keys(bindings) as ShortcutAction[]) {528 const binding = bindings[action];529 if (!matchKeybinding(e, binding)) continue;530 531 532 const hasMod = binding.ctrl || binding.meta || binding.alt || binding.shift;533 if (!hasMod && binding.key.length === 1 && inInput) return;534 if (ENTRY_SCOPED.has(action) && v !== "entry") return;535 e.preventDefault();536 SHORTCUT_HANDLERS[action]?.();537 return;538 }539540 541 542 543 544 if (v === "entry" && !inInput && isPrintableSearchKey) {545 e.preventDefault();546 primeListSearch(e.key);547 return;548 }549 };550 window.addEventListener("keydown", handleGlobalKeydown);551 onCleanup(() => window.removeEventListener("keydown", handleGlobalKeydown));552553 const handleStorageChanged = (554 changes: Record<string, chrome.storage.StorageChange>,555 areaName: string556 ) => {557 if (areaName !== "session") return;558 if (!Object.keys(changes).some((key) => key.startsWith("passkey_pending_"))) {559 return;560 }561 void refreshPendingPasskey();562 };563564 chrome.storage.onChanged.addListener(handleStorageChanged);565 onCleanup(() => chrome.storage.onChanged.removeListener(handleStorageChanged));566 });567568 async function refreshCurrentTab() {569 try {570 const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });571 const url = tab?.url ?? tab?.pendingUrl ?? "";572 setCurrentTabDomain(url ? (extractDomain(url) ?? "") : "");573 } catch {574 setCurrentTabDomain("");575 }576 }577578 async function refreshPendingPasskey() {579 const res = await sendMessage({ type: "GET_PENDING_PASSKEY" });580 setPendingPasskey((res as { ok: boolean; data?: PendingPasskeyRequest | null }).data ?? null);581 }582583 async function refreshProStatus() {584 const res = await sendMessage({ type: "GET_LICENSE" });585 const data = (res as { ok: boolean; data?: { valid?: boolean; plan?: string } }).data;586 setProStatus(Boolean(data?.valid && data?.plan === "pro"));587 }588589 async function restoreSettings() {590 const res = await sendMessage({ type: "GET_SETTINGS" });591 const s = (res as { ok: boolean; data?: any }).data ?? {};592 if (s.accentColor && ACCENT_COLORS.some(c => c.name === s.accentColor)) {593 setAccentColor(s.accentColor as AccentColorName);594 }595 setTheme(s.theme === "light" ? "light" : "dark");596 if (s.displayFont === "cormorant" || s.displayFont === "inter" || s.displayFont === "system") {597 setDisplayFont(s.displayFont);598 } else {599 setDisplayFont("cormorant-italic");600 }601 if (s.textSize === "small" || s.textSize === "large") {602 setTextSize(s.textSize);603 } else {604 setTextSize("medium");605 }606 setReduceMotion(s.reduceMotion === true);607 setLockOnClose(s.lockOnClose !== false);608 setAutoLockMinutes(typeof s.autoLockMinutes === "number" ? s.autoLockMinutes : 5);609 setBreachMonitoring(s.breachMonitoring !== false);610 setTrashRetentionDays(typeof s.trashRetentionDays === "number" ? s.trashRetentionDays : 30);611 setShortcutBindings(getActiveBindings(s.shortcuts));612 }613614 async function applyTrashRetention(days: number) {615 setTrashRetentionDays(days);616 await sendMessage({ type: "UPDATE_SETTINGS", payload: { trashRetentionDays: days } });617 }618619 function primeListSearch(seed: string) {620 setListSearchSeed(seed);621 setListSearchSeedNonce((value) => value + 1);622 openList();623 }624625 626 627 628 async function loadEntries(): Promise<VaultEntry[] | null> {629 const response = await sendMessage({ type: "GET_ENTRIES" });630 const res = response as { ok: boolean; data?: VaultEntry[]; error?: string };631632 633 634 635 636 if (!res.ok) {637 if (638 res.error === "vault locked" ||639 res.error === "SERVICE_WORKER_UNAVAILABLE" ||640 (typeof res.error === "string" && res.error.includes("locked"))641 ) {642 handleLock();643 return null; 644 }645 return [];646 }647648 const loadedEntries = res.data ?? [];649 setEntries(loadedEntries);650651 const currentId = selectedEntry()?.id;652 if (currentId) {653 setSelectedEntry(654 loadedEntries.find((entry) => entry.id === currentId) ?? loadedEntries[0] ?? null655 );656 }657658 return loadedEntries;659 }660661 async function openVault(preferredEntryId?: string, skipViewSet = false) {662 663 const retDays = trashRetentionDays();664 if (retDays > 0) {665 void sendMessage({666 type: "PURGE_EXPIRED_TRASH",667 payload: { retentionMs: retDays * 86_400_000 },668 });669 }670671 const loadedEntries = await loadEntries();672673 674 675 if (loadedEntries === null) return;676677 678 let nextSelectedEntry: VaultEntry | null = null;679 if (preferredEntryId) {680 nextSelectedEntry = loadedEntries.find((e) => e.id === preferredEntryId) ?? null;681 }682 if (!nextSelectedEntry) {683 const tabDomain = currentTabDomain();684 if (tabDomain) {685 nextSelectedEntry = loadedEntries.find((e) => {686 if (e.type === "login") {687 if (e.url && (extractDomain(e.url) ?? "") === tabDomain) return true;688 for (const extra of e.additionalUrls ?? []) {689 if ((extractDomain(extra) ?? "") === tabDomain) return true;690 }691 return false;692 }693 if (e.type === "passkey" && e.rpId) return e.rpId === tabDomain;694 return false;695 }) ?? null;696 }697 }698 nextSelectedEntry ??= loadedEntries[0] ?? null;699700 setSelectedEntry(nextSelectedEntry);701 setEditEntry(undefined);702 setContentTransitioning(false);703 setContentPhase("enter");704 queueContentIdle();705 if (!skipViewSet) setView("entry");706 }707708 async function handleUnlock() {709 setHasVault(true);710 triggerPipPulse();711 await restoreSettings();712 const celebrating = pendingCelebration();713 if (celebrating) {714 await sendMessage({ type: "MARK_CELEBRATION_PLAYED" });715 setPendingCelebration(false);716 }717 await openVault(undefined, celebrating);718 if (celebrating) {719 setView("pro-celebration");720 window.setTimeout(() => setView("entry"), 2500);721 }722 }723724 function handleSelectEntry(entry: VaultEntry) {725 setSelectedEntry(entry);726 setContentTransitioning(false);727 setContentPhase("enter");728 queueContentIdle();729 setView("entry");730 }731732 function handleAdd() {733 setEditEntry(undefined);734 setView("add");735 }736737 async function handleDelete() {738 const entry = selectedEntry();739 if (!entry) return;740 await sendMessage({ type: "DELETE_ENTRY", payload: { id: entry.id } });741 const loadedEntries = await loadEntries() ?? [];742 setSelectedEntry(loadedEntries[0] ?? null);743 setView("entry");744 }745746 async function handleDeleteMany(ids: string[]) {747 for (const id of ids) {748 await sendMessage({ type: "DELETE_ENTRY", payload: { id } });749 }750 const loadedEntries = await loadEntries() ?? [];751 752 const stillExists = loadedEntries.find(e => e.id === selectedEntry()?.id);753 if (!stillExists) setSelectedEntry(loadedEntries[0] ?? null);754 }755756 async function handleSave(savedEntry?: VaultEntry) {757 await openVault(savedEntry?.id);758 }759760 function handleBack() {761 setEditEntry(undefined);762 setView("entry");763 }764765 function handleLock() {766 clearCanarySuppressions();767 setEntries([]);768 setSelectedEntry(null);769 setEditEntry(undefined);770 setContentPhase("idle");771 setView("lock");772 }773774 function handleHeaderLock() {775 776 777 778 handleLock();779 void sendMessage({ type: "LOCK" });780 }781782 function navigate(dir: number) {783 const allEntries = entries();784 if (allEntries.length === 0) return;785 const currentIndex = selectedIndex();786 const baseIndex = currentIndex >= 0 ? currentIndex : 0;787 const nextIndex = (baseIndex + dir + allEntries.length) % allEntries.length;788 setSelectedEntry(allEntries[nextIndex]);789 setContentPhase("enter");790 queueContentIdle();791 }792793 function openList() {794 setView("list");795 }796797 function openHealth() {798 setEditEntry(undefined);799 setView("health");800 }801802 function handleOpenFileImport() {803 setRestoreView("file");804 }805806 const isShellOverlayOpen = () => view() !== "entry" || restoreView() !== null;807808 function handleFixEntry(entry: VaultEntry) {809 if (entry.type === "passkey") {810 setSelectedEntry(entry);811 setView("entry");812 return;813 }814 setEditEntry(entry);815 setView("add");816 }817818 const isLockedView = () => view() === "lock";819 const selectedPasskeyEntry = createMemo(() =>820 selectedEntry()?.type === "passkey" ? (selectedEntry() as PasskeyEntry) : null821 );822823 async function handleApprovePendingPasskey() {824 const pending = pendingPasskey();825 if (!pending) return;826 await sendMessage({ type: "APPROVE_PASSKEY", payload: { requestId: pending.requestId } });827 setPendingPasskey(null);828 }829830 async function handleDenyPendingPasskey() {831 const pending = pendingPasskey();832 if (!pending) return;833 await sendMessage({ type: "DENY_PASSKEY", payload: { requestId: pending.requestId } });834 setPendingPasskey(null);835 }836837 function queueContentIdle(after?: () => void) {838 if (contentPhaseTimer) window.clearTimeout(contentPhaseTimer);839 contentPhaseTimer = window.setTimeout(() => {840 setContentPhase("idle");841 after?.();842 }, ENTRY_TRANSITION_SETTLE_MS);843 }844845 return (846 <div class="popup-root peach-theme">847 <Show when={bootState() === "ready"}>848 <Show849 when={!pendingPasskey()}850 fallback={851 <PasskeyApprovalView852 type={pendingPasskey()!.type}853 rpName={pendingPasskey()!.rpName}854 rpId={pendingPasskey()!.rpId}855 userName={pendingPasskey()!.userName}856 userDisplayName={pendingPasskey()!.userDisplayName}857 onApprove={handleApprovePendingPasskey}858 onDeny={handleDenyPendingPasskey}859 />860 }861 >862 <Show863 when={!isLockedView()}864 fallback={865 <Show866 when={onboarded() || hasVault()}867 fallback={868 <Onboarding869 onComplete={() => { setOnboarded(true); }}870 />871 }872 >873 <LockView874 hasVault={hasVault()}875 ready={bootState() === "ready"}876 isPro={proStatus()}877 onUnlock={handleUnlock}878 />879 </Show>880 }881 >882 <Show883 when={view() !== "pro-celebration"}884 fallback={<ProCelebration />}885 >886 <section887 id="hd-shell"888 class="peach-shell peach-theme"889 data-surface="extension"890 >891 <header class="peach-chrome" classList={{ "is-hidden-for-overlay": isShellOverlayOpen() }}>892 <PeachWordmark unlocked />893 <div class="peach-chrome-actions">894 <button895 class="peach-btn peach-btn--ghost peach-btn--sm peach-icon-btn"896 onClick={() => setView("settings")}897 aria-label="Settings"898 >899 <svg width="14" height="14" viewBox="0 0 14 14" fill="none">900 <path901 d="M5.91 1.11C6.38-.02 7.62-.02 8.09 1.11L8.31 1.64C8.48 2.05 8.91 2.27 9.34 2.17L9.9 2.04C11.1 1.76 11.98 2.64 11.7 3.84L11.57 4.4C11.47 4.83 11.69 5.26 12.1 5.43L12.63 5.65C13.76 6.12 13.76 7.36 12.63 7.83L12.1 8.05C11.69 8.22 11.47 8.65 11.57 9.08L11.7 9.64C11.98 10.84 11.1 11.72 9.9 11.44L9.34 11.31C8.91 11.21 8.48 11.43 8.31 11.84L8.09 12.37C7.62 13.5 6.38 13.5 5.91 12.37L5.69 11.84C5.52 11.43 5.09 11.21 4.66 11.31L4.1 11.44C2.9 11.72 2.02 10.84 2.3 9.64L2.43 9.08C2.53 8.65 2.31 8.22 1.9 8.05L1.37 7.83C.24 7.36.24 6.12 1.37 5.65L1.9 5.43C2.31 5.26 2.53 4.83 2.43 4.4L2.3 3.84C2.02 2.64 2.9 1.76 4.1 2.04L4.66 2.17C5.09 2.27 5.52 2.05 5.69 1.64L5.91 1.11Z"902 stroke="currentColor"903 stroke-width="0.9"904 />905 <circle cx="7" cy="7" r="2.1" stroke="currentColor" stroke-width="0.9" />906 </svg>907 </button>908 <button909 class="peach-btn peach-btn--ghost peach-btn--sm peach-icon-btn"910 onClick={handleAdd}911 aria-label="New entry"912 >913 <svg width="11" height="11" viewBox="0 0 11 11" fill="none" stroke="currentColor" stroke-width="1.1" stroke-linecap="round">914 <path d="M5.5 1v9M1 5.5h9" />915 </svg>916 </button>917 <button918 class="peach-btn peach-btn--ghost peach-btn--sm peach-icon-btn peach-lock-btn"919 onClick={() => void handleHeaderLock()}920 aria-label="Lock vault"921 >922 <svg class="peach-lock-icon" width="14" height="16" viewBox="0 0 14 16" fill="none">923 <path924 d="M3.75 6V4.75C3.75 2.96 5.21 1.5 7 1.5C8.79 1.5 10.25 2.96 10.25 4.75V6"925 stroke="currentColor"926 stroke-width="1"927 stroke-linecap="round"928 />929 <rect x="1.5" y="6" width="11" height="8.5" rx="2.2" stroke="currentColor" stroke-width="1" />930 <circle cx="7" cy="10.25" r="1" fill="currentColor" />931 </svg>932 </button>933 </div>934 </header>935936 <Show when={pendingProNotice() !== null}>937 <div class="peach-pro-notice-banner">938 <span>✦ {pendingProNotice()?.feature === "sync" ? "Sync" : "A Pro feature"} requires Peach Pro</span>939 <button940 class="peach-pro-notice-link"941 onClick={() => {942 setUpgradeHighlight((pendingProNotice()?.feature as ProFeature) ?? null);943 setSettingsInitialSection("license");944 setView("settings");945 setPendingProNotice(null);946 }}947 >948 Learn more →949 </button>950 <button class="peach-pro-notice-close" onClick={() => setPendingProNotice(null)} aria-label="Dismiss">✕</button>951 </div>952 </Show>953954 <div class="peach-shell-body">955 <div class="peach-shell-veil"></div>956 <div class="peach-content-frame" data-content-phase={contentPhase()} classList={{ navigating: contentTransitioning() }}>957 <Show958 when={selectedPasskeyEntry()}959 fallback={960 <EntryView961 entry={selectedEntry()}962 onDelete={handleDelete}963 onFieldSaved={() => void loadEntries()}964 onEscape={() => { setView("list"); }}965 />966 }967 >968 <PasskeyEntryView entry={selectedPasskeyEntry()} onDelete={handleDelete} />969 </Show>970 </div>971972 <section class="peach-search-wrap" classList={{ "is-hidden-for-overlay": isShellOverlayOpen() }}>973 <div class="peach-search-bar">974 <span class="peach-search-icon">975 <svg width="13" height="13" viewBox="0 0 13 13" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round">976 <circle cx="5.5" cy="5.5" r="3.75" />977 <path d="M8.75 8.75L11.5 11.5" />978 </svg>979 </span>980 <input981 class="peach-search-input"982 placeholder="search vault..."983 autocomplete="off"984 aria-label="Search vault entries"985 onClick={openList}986 onFocus={openList}987 readOnly988 />989 <div class="peach-search-meta">990 <span class="peach-search-counter">991 {entries().length > 0992 ? `${selectedIndex() + 1} / ${entries().length}`993 : "0 entries"}994 </span>995 <span class="peach-divider"></span>996 <button997 class="peach-btn peach-btn--ghost peach-btn--sm peach-icon-btn"998 onClick={() => navigate(-1)}999 aria-label="Previous entry"1000 disabled={entries().length === 0}1001 >1002 <svg width="6" height="11" viewBox="0 0 6 11" fill="none" stroke="currentColor" stroke-width="1.1" stroke-linecap="round" stroke-linejoin="round">1003 <path d="M5 1L1 5.5L5 10" />1004 </svg>1005 </button>1006 <button1007 class="peach-btn peach-btn--ghost peach-btn--sm peach-icon-btn"1008 onClick={() => navigate(1)}1009 aria-label="Next entry"1010 disabled={entries().length === 0}1011 >1012 <svg width="6" height="11" viewBox="0 0 6 11" fill="none" stroke="currentColor" stroke-width="1.1" stroke-linecap="round" stroke-linejoin="round">1013 <path d="M1 1L5 5.5L1 10" />1014 </svg>1015 </button>1016 </div>1017 </div>1018 </section>1019 </div>10201021 <Show when={view() === "list"}>1022 <VaultView1023 entries={entries()}1024 selectedEntryId={selectedEntry()?.id}1025 currentTabDomain={currentTabDomain()}1026 sortOrder={sortOrder()}1027 searchSeed={listSearchSeed()}1028 searchSeedNonce={listSearchSeedNonce()}1029 onSelectEntry={handleSelectEntry}1030 onSortOrderChange={setSortOrder}1031 onAdd={handleAdd}1032 onClose={() => setView("entry")}1033 onOpenTrash={() => setView("trash")}1034 onDeleteMany={handleDeleteMany}1035 />1036 </Show>1037 <Show when={view() === "settings"}>1038 <Suspense fallback={<div class="peach-loading"><PeachWordmark /></div>}>1039 <SettingsView1040 entriesCount={entries().length}1041 breachMonitoring={breachMonitoring()}1042 lockOnClose={lockOnClose()}1043 autoLockMinutes={autoLockMinutes()}1044 trashRetentionDays={trashRetentionDays()}1045 theme={theme()}1046 accentColor={accentColor()}1047 displayFont={displayFont()}1048 textSize={textSize()}1049 reduceMotion={reduceMotion()}1050 isPro={proStatus()}1051 initialSection={settingsInitialSection()}1052 upgradeHighlight={upgradeHighlight()}1053 onBreachMonitoringChange={applyBreachMonitoring}1054 onLockOnCloseChange={applyLockOnClose}1055 onAutoLockMinutesChange={applyAutoLockMinutes}1056 onTrashRetentionChange={applyTrashRetention}1057 onThemeChange={applyTheme}1058 onAccentChange={applyAccentColor}1059 onDisplayFontChange={applyDisplayFont}1060 onTextSizeChange={applyTextSize}1061 onReduceMotionChange={applyReduceMotion}1062 shortcuts={shortcutBindings()}1063 onShortcutsChange={applyShortcuts}1064 onLicenseChange={refreshProStatus}1065 onBack={() => { setSettingsInitialSection(null); setUpgradeHighlight(null); handleBack(); }}1066 onImport={() => setView("import")}1067 onExport={() => setView("export")}1068 onBreachCheckDone={loadEntries}1069 onOpenHealth={openHealth}1070 onOpenFileImport={handleOpenFileImport}1071 onOpenPanic={() => setView("panic")}1072 />1073 </Suspense>1074 </Show>1075 <Show when={view() === "add"}>1076 <AddView1077 entry={editEntry()}1078 entries={entries()}1079 onBack={handleBack}1080 onSave={handleSave}1081 />1082 </Show>1083 <Show when={view() === "import"}>1084 <Suspense fallback={<div class="peach-loading"><PeachWordmark /></div>}>1085 <ImportView onBack={handleBack} onImport={handleSave} />1086 </Suspense>1087 </Show>1088 <Show when={view() === "export"}>1089 <Suspense fallback={<div class="peach-loading"><PeachWordmark /></div>}>1090 <ExportView1091 onBack={() => {1092 if (returnToPanic()) {1093 setReturnToPanic(false);1094 setView("panic");1095 } else {1096 handleBack();1097 }1098 }}1099 />1100 </Suspense>1101 </Show>1102 <Show when={view() === "panic"}>1103 <Suspense fallback={<div class="peach-loading"><PeachWordmark /></div>}>1104 <PanicView1105 onCancel={() => setView("settings")}1106 onOpenExport={() => {1107 setReturnToPanic(true);1108 setView("export");1109 }}1110 onDestroyed={async () => {1111 clearCanarySuppressions();1112 setEntries([]);1113 setSelectedEntry(null);1114 setEditEntry(undefined);1115 setHasVault(false);1116 setOnboarded(false);1117 setProStatus(false);1118 setPendingPasskey(null);1119 setUpgradeHighlight(null);1120 setSettingsInitialSection(null);1121 setPendingProNotice(null);1122 setPendingCelebration(false);1123 setReturnToPanic(false);1124 setContentPhase("idle");1125 setView("lock");1126 }}1127 />1128 </Suspense>1129 </Show>1130 <Show when={view() === "health"}>1131 <Suspense fallback={<div class="peach-loading"><PeachWordmark /></div>}>1132 <HealthView1133 entries={entries()}1134 isPro={proStatus()}1135 onFixEntry={handleFixEntry}1136 onBack={() => setView("settings")}1137 onRefresh={loadEntries}1138 />1139 </Suspense>1140 </Show>1141 <Show when={view() === "trash"}>1142 <Suspense fallback={<div class="peach-loading"><PeachWordmark /></div>}>1143 <TrashView1144 onBack={() => setView("list")}1145 onRestored={() => void loadEntries()}1146 />1147 </Suspense>1148 </Show>1149 <Show when={restoreView() === "file"}>1150 <Suspense fallback={<div class="peach-loading"><PeachWordmark /></div>}>1151 <ImportView1152 mode="onboarding"1153 replacesExistingVault={true}1154 onBack={() => setRestoreView(null)}1155 onImport={async () => {1156 setRestoreView(null);1157 await handleUnlock();1158 }}1159 />1160 </Suspense>1161 </Show>1162 </section>1163 </Show>1164 </Show>1165 </Show>1166 </Show>1167 <Show when={showShortcutsHelp()}>1168 <ShortcutsHelpOverlay1169 bindings={shortcutBindings()}1170 onClose={() => setShowShortcutsHelp(false)}1171 />1172 </Show>1173 </div>1174 );1175}11761177function ShortcutsHelpOverlay(props: {1178 bindings: Record<ShortcutAction, Keybinding>;1179 onClose: () => void;1180}) {1181 return (1182 <div class="peach-shortcuts-help-backdrop" onClick={props.onClose}>1183 <div class="peach-shortcuts-help-card" onClick={(e) => e.stopPropagation()}>1184 <div class="peach-shortcuts-help-head">1185 <h3>Keyboard shortcuts</h3>1186 <button class="peach-shortcuts-help-close" onClick={props.onClose} aria-label="Close">✕</button>1187 </div>1188 <div class="peach-shortcuts-help-body">1189 <p class="peach-settings-sub-label">ENTRY VIEW</p>1190 <ul>1191 {SHORTCUT_DESCRIPTORS.filter((d) => d.scope === "entry").map((d) => (1192 <li>1193 <span>{d.label}</span>1194 <kbd>{formatKeybinding(props.bindings[d.action])}</kbd>1195 </li>1196 ))}1197 </ul>1198 <p class="peach-settings-sub-label">ANYWHERE</p>1199 <ul>1200 {SHORTCUT_DESCRIPTORS.filter((d) => d.scope === "global").map((d) => (1201 <li>1202 <span>{d.label}</span>1203 <kbd>{formatKeybinding(props.bindings[d.action])}</kbd>1204 </li>1205 ))}1206 </ul>1207 </div>1208 </div>1209 </div>1210 );1211}