47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
const START_URL = './index.php';
|
|
|
|
self.addEventListener('install', (event) => {
|
|
event.waitUntil(self.skipWaiting());
|
|
});
|
|
|
|
self.addEventListener('activate', (event) => {
|
|
event.waitUntil(self.clients.claim());
|
|
});
|
|
|
|
self.addEventListener('fetch', (event) => {
|
|
event.respondWith(fetch(event.request));
|
|
});
|
|
|
|
self.addEventListener('notificationclick', (event) => {
|
|
event.notification.close();
|
|
event.waitUntil(
|
|
clients.matchAll({ type: 'window', includeUncontrolled: true }).then((list) => {
|
|
for (const client of list) {
|
|
if ('focus' in client) {
|
|
return client.focus();
|
|
}
|
|
}
|
|
if (clients.openWindow) {
|
|
return clients.openWindow(START_URL);
|
|
}
|
|
return undefined;
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener('message', (event) => {
|
|
const data = event.data;
|
|
if (!data || data.type !== 'notify') {
|
|
return;
|
|
}
|
|
|
|
event.waitUntil(
|
|
self.registration.showNotification(data.title || 'Panel kelnera', {
|
|
body: data.body || '',
|
|
tag: data.tag || 'waiter-alert',
|
|
renotify: true,
|
|
requireInteraction: true,
|
|
})
|
|
);
|
|
});
|