mirror of
https://github.com/ElppaDev/snStatus.git
synced 2026-01-29 09:35:36 +00:00
최초 배포
This commit is contained in:
50
frontend/public/sw-custom.js
Normal file
50
frontend/public/sw-custom.js
Normal file
@@ -0,0 +1,50 @@
|
||||
// Custom Service Worker for Push Notifications
|
||||
self.addEventListener('push', function (event) {
|
||||
console.log('[SW] Push event received:', event);
|
||||
|
||||
let notificationData = {
|
||||
title: 'snStatus Alert',
|
||||
body: 'System alert triggered',
|
||||
icon: '/pwa-192x192.png',
|
||||
badge: '/pwa-192x192.png',
|
||||
vibrate: [200, 100, 200],
|
||||
requireInteraction: true,
|
||||
tag: 'snstatus-alert'
|
||||
};
|
||||
|
||||
if (event.data) {
|
||||
try {
|
||||
const data = event.data.json();
|
||||
console.log('[SW] Push data:', data);
|
||||
notificationData.title = data.title || notificationData.title;
|
||||
notificationData.body = data.body || notificationData.body;
|
||||
notificationData.icon = data.icon || notificationData.icon;
|
||||
} catch (e) {
|
||||
console.error('[SW] Error parsing push data:', e);
|
||||
notificationData.body = event.data.text();
|
||||
}
|
||||
}
|
||||
|
||||
const promiseChain = self.registration.showNotification(
|
||||
notificationData.title,
|
||||
{
|
||||
body: notificationData.body,
|
||||
icon: notificationData.icon,
|
||||
badge: notificationData.badge,
|
||||
vibrate: notificationData.vibrate,
|
||||
requireInteraction: notificationData.requireInteraction,
|
||||
tag: notificationData.tag
|
||||
}
|
||||
);
|
||||
|
||||
event.waitUntil(promiseChain);
|
||||
});
|
||||
|
||||
self.addEventListener('notificationclick', function (event) {
|
||||
console.log('[SW] Notification clicked');
|
||||
event.notification.close();
|
||||
|
||||
event.waitUntil(
|
||||
clients.openWindow('/')
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user