|
@ -5,7 +5,7 @@ importScripts( |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
self.addEventListener("install", (event) => { |
|
|
self.addEventListener("install", (event) => { |
|
|
console.error(event); |
|
|
console.error("Adding event listener for:", event); |
|
|
importScripts( |
|
|
importScripts( |
|
|
"safari-notifications.js", |
|
|
"safari-notifications.js", |
|
|
"nacl.js", |
|
|
"nacl.js", |
|
@ -23,16 +23,20 @@ self.addEventListener("push", function (event) { |
|
|
payload = JSON.parse(event.data.text()); |
|
|
payload = JSON.parse(event.data.text()); |
|
|
} |
|
|
} |
|
|
const message = await self.getNotificationCount(); |
|
|
const message = await self.getNotificationCount(); |
|
|
console.error(message); |
|
|
if (message) { |
|
|
const title = payload ? payload.title : "Custom Title"; |
|
|
console.log("Will notify user:", message); |
|
|
const options = { |
|
|
const title = payload ? payload.title : "Custom Title"; |
|
|
body: message, |
|
|
const options = { |
|
|
icon: payload ? payload.icon : "icon.png", |
|
|
body: message, |
|
|
badge: payload ? payload.badge : "badge.png", |
|
|
icon: payload ? payload.icon : "icon.png", |
|
|
}; |
|
|
badge: payload ? payload.badge : "badge.png", |
|
|
await self.registration.showNotification(title, options); |
|
|
}; |
|
|
|
|
|
await self.registration.showNotification(title, options); |
|
|
|
|
|
} else { |
|
|
|
|
|
console.log("No notification message, so will not tell the user."); |
|
|
|
|
|
} |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
console.error("Error in processing the push event:", error); |
|
|
console.error("Error processing the push event:", error); |
|
|
} |
|
|
} |
|
|
})(), |
|
|
})(), |
|
|
); |
|
|
); |
|
@ -51,7 +55,7 @@ self.addEventListener("activate", (event) => { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
self.addEventListener("fetch", (event) => { |
|
|
self.addEventListener("fetch", (event) => { |
|
|
console.log(event.request); |
|
|
console.log("Got fetch event", event.request); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
self.addEventListener("error", (event) => { |
|
|
self.addEventListener("error", (event) => { |
|
|