Browse Source

Updates to additional scripts

web-push-permissions
Matthew Raymer 1 year ago
parent
commit
ccb6160bca
  1. 15
      additional-scripts.js
  2. 2
      src/App.vue
  3. 3
      vue.config.js

15
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));
});

2
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);
})

3
vue.config.js

@ -11,5 +11,8 @@ module.exports = defineConfig({
iconPaths: {
faviconSVG: "img/icons/safari-pinned-tab.svg",
},
workboxOptions: {
importScripts: ["additional-scripts.js"],
},
},
});

Loading…
Cancel
Save