Task 5.24: PWA — vite-plugin-pwa with autoUpdate, manifest, workbox caching, PWAInstallPrompt component, notification helper, SVG icons, 6 tests

This commit is contained in:
Agent Zero
2026-07-24 00:01:53 +02:00
parent d54a87cf84
commit 96e183bab2
11 changed files with 4034 additions and 3 deletions
+41
View File
@@ -0,0 +1,41 @@
/**
* Notification permission helper — request and check notification permissions (Task 5.24).
*/
export type NotificationPermissionState = 'default' | 'granted' | 'denied' | 'unsupported';
export function getNotificationPermission(): NotificationPermissionState {
if (!('Notification' in window)) return 'unsupported';
return Notification.permission as NotificationPermissionState;
}
export async function requestNotificationPermission(): Promise<NotificationPermissionState> {
if (!('Notification' in window)) return 'unsupported';
if (Notification.permission === 'granted') return 'granted';
if (Notification.permission === 'denied') return 'denied';
try {
const result = await Notification.requestPermission();
return result as NotificationPermissionState;
} catch {
return 'denied';
}
}
export function showNotification(title: string, options?: NotificationOptions): void {
if (!('Notification' in window) || Notification.permission !== 'granted') return;
try {
new Notification(title, options);
} catch {
// Notification creation can fail in some browsers
}
}
export function isPWAInstalled(): boolean {
try {
return window.matchMedia('(display-mode: standalone)').matches ||
(window.navigator as unknown as { standalone?: boolean }).standalone === true;
} catch {
return false;
}
}