mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
33 lines
775 B
JavaScript
33 lines
775 B
JavaScript
|
self.addEventListener('push', function(event) {
|
||
|
if (!(self.Notification && self.Notification.permission === 'granted')) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var data = {};
|
||
|
if (event.data) {
|
||
|
data = event.data.json();
|
||
|
}
|
||
|
var title = data.title;
|
||
|
var message = data.message;
|
||
|
var icon = "favicon.ico";
|
||
|
|
||
|
self.clickTarget = self.location.origin;
|
||
|
|
||
|
event.waitUntil(self.registration.showNotification(title, {
|
||
|
body: message,
|
||
|
tag: 'Databag',
|
||
|
icon: icon,
|
||
|
}));
|
||
|
});
|
||
|
|
||
|
self.addEventListener('notificationclick', function(event) {
|
||
|
console.log('[Service Worker] Notification click Received.');
|
||
|
|
||
|
event.notification.close();
|
||
|
|
||
|
if(clients.openWindow){
|
||
|
event.waitUntil(clients.openWindow(self.clickTarget));
|
||
|
}
|
||
|
});
|
||
|
|