From ccb6160bca9124911ffd4866b21fa98ef864a15f Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Mon, 2 Oct 2023 04:41:50 -0400 Subject: [PATCH] Updates to additional scripts --- additional-scripts.js | 15 +++++++++++++++ src/App.vue | 2 -- vue.config.js | 3 +++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 additional-scripts.js diff --git a/additional-scripts.js b/additional-scripts.js new file mode 100644 index 000000000..35b87c5c5 --- /dev/null +++ b/additional-scripts.js @@ -0,0 +1,15 @@ +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)); +}); diff --git a/src/App.vue b/src/App.vue index 9abe7748f..143e7ae7e 100644 --- a/src/App.vue +++ b/src/App.vue @@ -371,14 +371,12 @@ export default class App extends Vue { if ("serviceWorker" in navigator && "PushManager" in window) { navigator.serviceWorker.ready .then((registration) => { - console.log(this.b64); const applicationServerKey = this.urlBase64ToUint8Array(this.b64); const options: PushSubscriptionOptions = { userVisibleOnly: true, applicationServerKey: applicationServerKey, }; - console.log(options); return registration.pushManager.subscribe(options); }) diff --git a/vue.config.js b/vue.config.js index c0b7cf290..ecc2551c4 100644 --- a/vue.config.js +++ b/vue.config.js @@ -11,5 +11,8 @@ module.exports = defineConfig({ iconPaths: { faviconSVG: "img/icons/safari-pinned-tab.svg", }, + workboxOptions: { + importScripts: ["additional-scripts.js"], + }, }, });