Parents get a real push notification when a kid checks off a task (false->true transitions only, fire-and-forget, degrades gracefully with no VAPID keys configured). Dashboard is a fully installable iOS/Android PWA; each child's kiosk link gets its own dynamic per-token manifest so "Add to Home Screen" opens straight into their board in standalone mode. Kiosk view is reworked for tablets: safe-area-aware full-bleed layout, the whole task row is now tappable (previously only the 24px checkbox was, well under Apple's touch-target minimum), and app icons are generated by a small dependency-free PNG encoder (no image tooling available in this environment). Push requires real HTTPS (iOS Safari won't allow it otherwise) - README and UNRAID.md cover VAPID setup and the HTTPS prerequisite.
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
self.addEventListener('install', () => {
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener('activate', (event) => {
|
|
event.waitUntil(self.clients.claim());
|
|
});
|
|
|
|
self.addEventListener('push', (event) => {
|
|
if (!event.data) return;
|
|
const payload = event.data.json();
|
|
event.waitUntil(
|
|
self.registration.showNotification(payload.title, {
|
|
body: payload.body,
|
|
icon: '/icons/icon-192.png',
|
|
badge: '/icons/icon-192.png',
|
|
tag: 'kc-task-done',
|
|
data: { url: payload.url || '/dashboard.html' },
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener('notificationclick', (event) => {
|
|
event.notification.close();
|
|
const targetUrl = event.notification.data && event.notification.data.url;
|
|
if (!targetUrl) return;
|
|
|
|
event.waitUntil(
|
|
self.clients.matchAll({ type: 'window', includeUncontrolled: true }).then((clients) => {
|
|
const existing = clients.find((c) => {
|
|
try {
|
|
return new URL(c.url).pathname === new URL(targetUrl, self.location.origin).pathname;
|
|
} catch {
|
|
return false;
|
|
}
|
|
});
|
|
if (existing) return existing.focus();
|
|
return self.clients.openWindow(targetUrl);
|
|
})
|
|
);
|
|
});
|