edtech / apps /admin /public /sw.js
CognxSafeTrack
feat: push notifications, CRM analytics, Fastify v5 upgrades, schema updates
b43e552
/*
* Service Worker for Push Notifications
*/
self.addEventListener('push', function(event) {
if (event.data) {
const data = event.data.json();
const options = {
body: data.body,
icon: data.icon || '/logo.png',
badge: '/badge.png',
vibrate: [100, 50, 100],
data: {
dateOfArrival: Date.now(),
primaryKey: '1'
},
actions: [
{ action: 'explore', title: 'Ouvrir le Dashboard', icon: '/check-mark.png' },
{ action: 'close', title: 'Fermer', icon: '/x-mark.png' },
]
};
event.waitUntil(
self.registration.showNotification(data.title, options)
);
}
});
self.addEventListener('notificationclick', function(event) {
event.notification.close();
if (event.action === 'explore' || !event.action) {
// Open the dashboard
event.waitUntil(
clients.openWindow('/')
);
}
});