4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 1 | import { writable } from 'svelte/store'; |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 2 | import { |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 3 | isDismissed, |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 4 | requestPersistence, |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 5 | setDismissed, |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 6 | type InstallContext |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 7 | } from './protection-model'; |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 8 | |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 9 | export const storageUnprotected = writable(false); |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 10 | export const recoveryDismissed = writable(false); |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 11 | |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 12 | export const isDeviceBuild = import.meta.env.VITE_MALICE_TARGET === 'device'; |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 13 | |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 14 | export function installContext(): InstallContext { |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 15 | const standalone = |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 16 | window.matchMedia('(display-mode: standalone)').matches || |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 17 | (navigator as Navigator & { standalone?: boolean }).standalone === true; |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 18 | return { device: isDeviceBuild, standalone }; |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 19 | } |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 20 | |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 21 | export function loadDismissals(account: string): void { |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 22 | recoveryDismissed.set(isDismissed(localStorage, 'recovery', account)); |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 23 | } |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 24 | |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 25 | export async function protectStorage(account: string): Promise<void> { |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 26 | const result = await requestPersistence(navigator.storage).catch(() => null); |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 27 | storageUnprotected.set(isDeviceBuild && result !== null && !result.persisted && !isDismissed(localStorage, 'storage', account)); |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 28 | } |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 29 | |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 30 | export function dismissStorageWarning(account: string): void { |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 31 | setDismissed(localStorage, 'storage', account); |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 32 | storageUnprotected.set(false); |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 33 | } |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 34 | |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 35 | export function dismissRecoveryPrompt(account: string): void { |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 36 | setDismissed(localStorage, 'recovery', account); |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 37 | recoveryDismissed.set(true); |
4929dcd34937 | atagen | 2026-10-26 04:43 UTC | 38 | } |