summaryrefslogtreecommitdiff
path: root/packages/frontend/src/components/MkPushNotificationAllowButton.vue
diff options
context:
space:
mode:
Diffstat (limited to 'packages/frontend/src/components/MkPushNotificationAllowButton.vue')
-rw-r--r--packages/frontend/src/components/MkPushNotificationAllowButton.vue14
1 files changed, 10 insertions, 4 deletions
diff --git a/packages/frontend/src/components/MkPushNotificationAllowButton.vue b/packages/frontend/src/components/MkPushNotificationAllowButton.vue
index c651d3a3f5..9c37eb5e72 100644
--- a/packages/frontend/src/components/MkPushNotificationAllowButton.vue
+++ b/packages/frontend/src/components/MkPushNotificationAllowButton.vue
@@ -78,7 +78,7 @@ function subscribe() {
// SEE: https://developer.mozilla.org/en-US/docs/Web/API/PushManager/subscribe#Parameters
return promiseDialog(registration.value.pushManager.subscribe({
userVisibleOnly: true,
- applicationServerKey: urlBase64ToBase64(instance.swPublickey),
+ applicationServerKey: urlBase64ToUint8Array(instance.swPublickey),
})
.then(async subscription => {
pushSubscription.value = subscription;
@@ -131,16 +131,22 @@ function encode(buffer: ArrayBuffer | null) {
}
/**
- * Convert the URL safe base64 string to a base64 string
+ * Convert the URL safe base64 string to a Uint8Array
* @param base64String base64 string
*/
-function urlBase64ToBase64(base64String: string): string {
+function urlBase64ToUint8Array(base64String: string): Uint8Array {
const padding = '='.repeat((4 - base64String.length % 4) % 4);
const base64 = (base64String + padding)
.replace(/-/g, '+')
.replace(/_/g, '/');
- return base64;
+ const rawData = window.atob(base64);
+ const outputArray = new Uint8Array(rawData.length);
+
+ for (let i = 0; i < rawData.length; ++i) {
+ outputArray[i] = rawData.charCodeAt(i);
+ }
+ return outputArray;
}
if (navigator.serviceWorker == null) {