6c6828006b
Adds opt-in (default OFF) auto-lock: after X minutes of no user input the app calls signOut() (full memory wipe + PIN re-entry on next open). Settings dropdown (Aus / 5 / 15 / 30 / 60 min) lives in SecurityCenter below the existing wipe-on-close toggle. The idle timer is mounted in AppShell via useIdleAutoLock; activity events are throttled to 1 Hz to avoid timer thrash on rapid mouse movement. The localStorage key is added to PRESERVE_LOCAL_STORAGE so a wipe never silently disables the feature. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
// 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<Listener>();
|
|
|
|
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);
|
|
}
|