forked from trent_larson/crowd-funder-for-time-pwa
Two static scripts for push notifications
This commit is contained in:
33
sw_scripts/additional-scripts.js
Normal file
33
sw_scripts/additional-scripts.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const notifications = require("./safari-notifications.js");
|
||||
|
||||
|
||||
self.addEventListener("push", function (event) {
|
||||
let payload;
|
||||
if (event.data) {
|
||||
payload = JSON.parse(event.data.text());
|
||||
}
|
||||
|
||||
const title = payload ? payload.title : "Custom Title";
|
||||
const options = {
|
||||
body: payload ? payload.body : "Custom body text",
|
||||
icon: payload ? payload.icon : "icon.png",
|
||||
badge: payload ? payload.badge : "badge.png",
|
||||
};
|
||||
|
||||
event.waitUntil(self.registration.showNotification(title, options));
|
||||
});
|
||||
|
||||
|
||||
self.addEventListener("message", function (event) {
|
||||
const data = event.data;
|
||||
|
||||
const result = notifications.getNotificationCount()
|
||||
|
||||
switch (data.command) {
|
||||
case "account":
|
||||
break;
|
||||
|
||||
default:
|
||||
console.log("Unknown command:", data.command);
|
||||
}
|
||||
});
|
||||
5157
sw_scripts/safari-notifications.js
Normal file
5157
sw_scripts/safari-notifications.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user