Browse Source
Reviewed-on: https://gitea.anomalistdesign.com/trent_larson/crowd-funder-for-time-pwa/pulls/87pull/92/head
anomalist
12 months ago
9 changed files with 10081 additions and 5225 deletions
@ -1,33 +1,65 @@ |
|||||
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) => { |
||||
|
console.error(event); |
||||
|
importScripts( |
||||
|
"safari-notifications.js", |
||||
|
"nacl.js", |
||||
|
"noble-curves.js", |
||||
|
"noble-hashes.js", |
||||
|
); |
||||
|
}); |
||||
|
|
||||
self.addEventListener("push", function (event) { |
self.addEventListener("push", function (event) { |
||||
let payload; |
event.waitUntil( |
||||
if (event.data) { |
(async () => { |
||||
payload = JSON.parse(event.data.text()); |
try { |
||||
} |
let payload; |
||||
|
if (event.data) { |
||||
const title = payload ? payload.title : "Custom Title"; |
payload = JSON.parse(event.data.text()); |
||||
const options = { |
} |
||||
body: payload ? payload.body : "Custom body text", |
const message = await self.getNotificationCount(); |
||||
icon: payload ? payload.icon : "icon.png", |
console.error(message); |
||||
badge: payload ? payload.badge : "badge.png", |
const title = payload ? payload.title : "Custom Title"; |
||||
}; |
const options = { |
||||
|
body: message, |
||||
event.waitUntil(self.registration.showNotification(title, options)); |
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) { |
self.addEventListener("activate", (event) => { |
||||
const data = event.data; |
event.waitUntil(clients.claim()); |
||||
|
console.log("Service worker activated", event); |
||||
const result = notifications.getNotificationCount() |
}); |
||||
|
|
||||
switch (data.command) { |
self.addEventListener("fetch", (event) => { |
||||
case "account": |
console.log(event.request); |
||||
break; |
}); |
||||
|
|
||||
default: |
self.addEventListener("error", (event) => { |
||||
console.log("Unknown command:", data.command); |
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