// Per-install setting for PIN-idle-auto-lock. 0 = disabled. // Values match the dropdown options (5/15/30/60 minutes). const KEY = 'chatapp.autoLockMinutes.v1'; export type AutoLockMinutes = 0 | 5 | 15 | 30 | 60; const VALID: AutoLockMinutes[] = [0, 5, 15, 30, 60]; export function getAutoLockMinutes(): AutoLockMinutes { try { const raw = window.localStorage.getItem(KEY); if (!raw) return 0; const n = Number(raw); if (VALID.includes(n as AutoLockMinutes)) return n as AutoLockMinutes; return 0; } catch { return 0; } } type Listener = (value: AutoLockMinutes) => void; const listeners = new Set(); export function subscribeAutoLockSetting(l: Listener): () => void { listeners.add(l); return () => listeners.delete(l); } export function notifyAutoLockChanged(value: AutoLockMinutes): void { for (const l of listeners) { try { l(value); } catch (err) { console.warn(err); } } } export function setAutoLockMinutes(value: AutoLockMinutes): void { try { window.localStorage.setItem(KEY, String(value)); } catch { /* quota */ } notifyAutoLockChanged(value); }