lots of changes leave me alone its better now

This commit is contained in:
2026-02-14 04:35:40 -06:00
parent 97a166f5aa
commit 4d3a9fbd54
13 changed files with 438 additions and 57 deletions

View File

@@ -28,3 +28,48 @@ self.addEventListener('fetch', (event) => {
.catch(() => caches.match(event.request))
);
});
// ── Web Push Notifications ──────────────────────────────────
self.addEventListener('push', (event) => {
let data = { title: 'Synculous', body: 'You have a notification' };
if (event.data) {
try {
data = event.data.json();
} catch {
data.body = event.data.text();
}
}
event.waitUntil(
self.registration.showNotification(data.title || 'Synculous', {
body: data.body,
icon: '/icon-192.png',
badge: '/icon-192.png',
data: { url: '/dashboard/medications' },
actions: [
{ action: 'open', title: 'Open' },
{ action: 'dismiss', title: 'Dismiss' },
],
})
);
});
self.addEventListener('notificationclick', (event) => {
event.notification.close();
if (event.action === 'dismiss') return;
const url = event.notification.data?.url || '/dashboard/medications';
event.waitUntil(
self.clients.matchAll({ type: 'window', includeUncontrolled: true }).then((clients) => {
for (const client of clients) {
if (client.url.includes('/dashboard') && 'focus' in client) {
return client.focus();
}
}
return self.clients.openWindow(url);
})
);
});