Matthew Raymer
1 year ago
3 changed files with 55 additions and 5179 deletions
@ -1,33 +1,31 @@ |
|||||
const notifications = require("./safari-notifications.js"); |
importScripts("./safari-notifications.js"); |
||||
|
|
||||
|
|
||||
self.addEventListener("push", function (event) { |
self.addEventListener("push", function (event) { |
||||
|
event.waitUntil((async () => { |
||||
|
try { |
||||
let payload; |
let payload; |
||||
if (event.data) { |
if (event.data) { |
||||
payload = JSON.parse(event.data.text()); |
payload = JSON.parse(event.data.text()); |
||||
} |
} |
||||
|
let value = await self.getNotificationCount(); |
||||
const title = payload ? payload.title : "Custom Title"; |
const title = payload ? payload.title : "Custom Title"; |
||||
const options = { |
const options = { |
||||
body: payload ? payload.body : "Custom body text", |
body: payload ? value : "SAMPLE", |
||||
icon: payload ? payload.icon : "icon.png", |
icon: payload ? payload.icon : "icon.png", |
||||
badge: payload ? payload.badge : "badge.png", |
badge: payload ? payload.badge : "badge.png", |
||||
}; |
}; |
||||
|
await self.registration.showNotification(title, options); |
||||
event.waitUntil(self.registration.showNotification(title, options)); |
} catch (error) { |
||||
|
console.error('Error in processing the push event:', error); |
||||
|
} |
||||
|
})()); |
||||
}); |
}); |
||||
|
|
||||
|
|
||||
self.addEventListener("message", function (event) { |
self.addEventListener('message', event => { |
||||
const data = event.data; |
if (event.data && event.data.type === 'SEND_LOCAL_DATA') { |
||||
|
self.secret = event.data.data; |
||||
const result = notifications.getNotificationCount() |
console.log('Data stored in service worker:', self.secret); |
||||
|
|
||||
switch (data.command) { |
|
||||
case "account": |
|
||||
break; |
|
||||
|
|
||||
default: |
|
||||
console.log("Unknown command:", data.command); |
|
||||
} |
} |
||||
}); |
}); |
||||
|
File diff suppressed because it is too large
Loading…
Reference in new issue