lots of changes leave me alone its better now
This commit is contained in:
@@ -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);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user