2020-08-10 12:35:19 +00:00
|
|
|
// workbox.setConfig({
|
|
|
|
// debug: true
|
|
|
|
// });
|
|
|
|
|
2020-09-06 10:39:02 +00:00
|
|
|
self.addEventListener("push", function(event) {
|
2020-08-28 16:10:04 +00:00
|
|
|
if (event.data) {
|
|
|
|
var data = event.data.json();
|
|
|
|
var notOptions = {
|
|
|
|
body: data.notification.body,
|
|
|
|
icon: data.notification.image || null
|
|
|
|
};
|
|
|
|
if (data.data) {
|
|
|
|
console.log("dataFound");
|
|
|
|
console.log(data.data.data);
|
|
|
|
notOptions.actions = JSON.parse(data.data.actions);
|
|
|
|
notOptions.data = JSON.parse(data.data.data);
|
2020-08-10 12:35:19 +00:00
|
|
|
}
|
2020-08-28 16:10:04 +00:00
|
|
|
event.waitUntil(
|
|
|
|
self.registration.showNotification(data.notification.title, notOptions)
|
|
|
|
);
|
|
|
|
}
|
2020-08-10 12:35:19 +00:00
|
|
|
});
|
|
|
|
|
2020-09-06 10:39:02 +00:00
|
|
|
self.addEventListener("notificationclick", function(event) {
|
2020-08-28 16:10:04 +00:00
|
|
|
if (event.notification) {
|
2020-09-06 18:54:44 +00:00
|
|
|
if (event.notification.data) {
|
2020-09-06 10:38:26 +00:00
|
|
|
var data = JSON.parse(event.notification.data.data);
|
|
|
|
if (data[event.action]) {
|
|
|
|
console.log(data);
|
2020-09-06 18:54:44 +00:00
|
|
|
console.log(data);
|
|
|
|
|
|
|
|
|
2020-09-06 10:38:26 +00:00
|
|
|
console.log(data[event.action]);
|
|
|
|
clients.openWindow("" + data[event.action]);
|
|
|
|
}
|
2020-08-28 16:10:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
clients.openWindow("/");
|
2020-08-10 12:35:19 +00:00
|
|
|
});
|
2020-08-28 16:10:04 +00:00
|
|
|
|
2020-09-06 10:39:02 +00:00
|
|
|
self.addEventListener("message", event => {
|
|
|
|
if (event.data && event.data.type === "SKIP_WAITING") {
|
|
|
|
self.skipWaiting();
|
2020-09-06 10:38:26 +00:00
|
|
|
}
|
2020-09-06 10:39:02 +00:00
|
|
|
});
|
2020-09-06 10:38:26 +00:00
|
|
|
|
2020-08-28 16:10:04 +00:00
|
|
|
self.__precacheManifest = [].concat(self.__precacheManifest || []);
|
|
|
|
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
|