Prettified identifier and register notices up top #78
Open
jose
wants to merge 21 commits from home-view-notification-improvements
into master
13 changed files with 10188 additions and 5269 deletions
@ -1,33 +1,63 @@ |
|||
const notifications = require("./safari-notifications.js"); |
|||
|
|||
/* eslint-env serviceworker */ |
|||
/* global workbox */ |
|||
importScripts( |
|||
"https://storage.googleapis.com/workbox-cdn/releases/6.4.1/workbox-sw.js", |
|||
); |
|||
|
|||
self.addEventListener("install", (event) => { |
|||
importScripts( |
|||
"safari-notifications.js", |
|||
"nacl.js", |
|||
"noble-curves.js", |
|||
"noble-hashes.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)); |
|||
event.waitUntil( |
|||
(async () => { |
|||
try { |
|||
let payload; |
|||
if (event.data) { |
|||
payload = JSON.parse(event.data.text()); |
|||
} |
|||
const message = await self.getNotificationCount(); |
|||
const title = payload ? payload.title : "Custom Title"; |
|||
const options = { |
|||
body: message, |
|||
icon: payload ? payload.icon : "icon.png", |
|||
badge: payload ? payload.badge : "badge.png", |
|||
}; |
|||
await self.registration.showNotification(title, options); |
|||
} catch (error) { |
|||
console.error("Error in processing the push event:", error); |
|||
} |
|||
})(), |
|||
); |
|||
}); |
|||
|
|||
self.addEventListener("message", (event) => { |
|||
if (event.data && event.data.type === "SEND_LOCAL_DATA") { |
|||
self.secret = event.data.data; |
|||
event.ports[0].postMessage({ success: true }); |
|||
} |
|||
}); |
|||
|
|||
self.addEventListener("message", function (event) { |
|||
const data = event.data; |
|||
|
|||
const result = notifications.getNotificationCount() |
|||
self.addEventListener("activate", (event) => { |
|||
event.waitUntil(clients.claim()); |
|||
console.log("Service worker activated", event); |
|||
}); |
|||
|
|||
switch (data.command) { |
|||
case "account": |
|||
break; |
|||
self.addEventListener("fetch", (event) => { |
|||
console.log(event.request); |
|||
}); |
|||
|
|||
default: |
|||
console.log("Unknown command:", data.command); |
|||
} |
|||
self.addEventListener("error", (event) => { |
|||
console.error("Error in Service Worker:", event.message); |
|||
console.error("File:", event.filename); |
|||
console.error("Line:", event.lineno); |
|||
console.error("Column:", event.colno); |
|||
console.error("Error Object:", event.error); |
|||
}); |
|||
|
|||
workbox.precaching.precacheAndRoute(self.__WB_MANIFEST); |
|||
|
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
Loading…
Reference in new issue