|
|
@ -431,34 +431,38 @@ export default class App extends Vue { |
|
|
|
return outputArray; |
|
|
|
} |
|
|
|
|
|
|
|
// The subscribeToPush method |
|
|
|
private subscribeToPush(): Promise<void> { |
|
|
|
return new Promise<void>((resolve, reject) => { |
|
|
|
if ("serviceWorker" in navigator && "PushManager" in window) { |
|
|
|
const applicationServerKey = this.urlBase64ToUint8Array(this.b64); |
|
|
|
const options: PushSubscriptionOptions = { |
|
|
|
userVisibleOnly: true, |
|
|
|
applicationServerKey: applicationServerKey, |
|
|
|
}; |
|
|
|
console.log(options); |
|
|
|
|
|
|
|
navigator.serviceWorker.ready |
|
|
|
.then((registration) => { |
|
|
|
return registration.pushManager.subscribe(options); |
|
|
|
}) |
|
|
|
.then((subscription) => { |
|
|
|
console.log("Push subscription successful:", subscription); |
|
|
|
resolve(); |
|
|
|
}) |
|
|
|
.catch((error) => { |
|
|
|
console.error("Push subscription failed:", error, options); |
|
|
|
reject(error); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
if (!("serviceWorker" in navigator && "PushManager" in window)) { |
|
|
|
const errorMsg = "Push messaging is not supported"; |
|
|
|
console.warn(errorMsg); |
|
|
|
reject(new Error(errorMsg)); |
|
|
|
return reject(new Error(errorMsg)); |
|
|
|
} |
|
|
|
|
|
|
|
if (Notification.permission !== "granted") { |
|
|
|
const errorMsg = "Notification permission not granted"; |
|
|
|
console.warn(errorMsg); |
|
|
|
return reject(new Error(errorMsg)); |
|
|
|
} |
|
|
|
|
|
|
|
const applicationServerKey = this.urlBase64ToUint8Array(this.b64); |
|
|
|
const options: PushSubscriptionOptions = { |
|
|
|
userVisibleOnly: true, |
|
|
|
applicationServerKey: applicationServerKey, |
|
|
|
}; |
|
|
|
|
|
|
|
navigator.serviceWorker.ready |
|
|
|
.then((registration) => { |
|
|
|
return registration.pushManager.subscribe(options); |
|
|
|
}) |
|
|
|
.then((subscription) => { |
|
|
|
console.log("Push subscription successful:", subscription); |
|
|
|
resolve(); |
|
|
|
}) |
|
|
|
.catch((error) => { |
|
|
|
console.error("Push subscription failed:", error, options); |
|
|
|
reject(error); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|