groupe-meditation/frontend/public/push-sw.js

25 lines
664 B
JavaScript
Raw Normal View History

2026-05-25 17:39:38 -04:00
self.addEventListener('push', (event) => {
let data = {};
if (event.data) {
try {
data = event.data.json();
} catch {
2026-06-01 09:16:37 -04:00
data = { title: 'App', body: event.data.text() };
2026-05-25 17:39:38 -04:00
}
}
2026-06-01 09:16:37 -04:00
const title = data.title || 'App';
2026-05-25 17:39:38 -04:00
const options = {
body: data.body || 'Nouvelle notification',
icon: '/icon-192.png',
badge: '/icon-192.png',
data: { url: data.url || '/' },
};
event.waitUntil(self.registration.showNotification(title, options));
});
self.addEventListener('notificationclick', (event) => {
event.notification.close();
const url = event.notification.data?.url || '/';
event.waitUntil(clients.openWindow(url));
});