groupe-meditation/frontend/public/push-sw.js
2026-05-25 17:39:38 -04:00

24 lines
694 B
JavaScript

self.addEventListener('push', (event) => {
let data = {};
if (event.data) {
try {
data = event.data.json();
} catch {
data = { title: 'Groupe Méditation', body: event.data.text() };
}
}
const title = data.title || 'Groupe Méditation';
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));
});