From e6112506df73a8a38bb8b5a1fee5dd3149e989aa Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 29 Dec 2022 17:20:24 +0900 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E7=9F=A5=E8=A8=AD=E5=AE=9A=E3=81=8C?= =?UTF-8?q?=E9=96=8B=E3=81=91=E3=81=AA=E3=81=84=E3=81=AE=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MkPushNotificationAllowButton.vue | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/frontend/src/components/MkPushNotificationAllowButton.vue b/packages/frontend/src/components/MkPushNotificationAllowButton.vue index b356fd3b8..b98c814f2 100644 --- a/packages/frontend/src/components/MkPushNotificationAllowButton.vue +++ b/packages/frontend/src/components/MkPushNotificationAllowButton.vue @@ -126,7 +126,7 @@ function encode(buffer: ArrayBuffer | null) { * Convert the URL safe base64 string to a Uint8Array * @param base64String base64 string */ - function urlBase64ToUint8Array(base64String: string): Uint8Array { +function urlBase64ToUint8Array(base64String: string): Uint8Array { const padding = '='.repeat((4 - base64String.length % 4) % 4); const base64 = (base64String + padding) .replace(/-/g, '+') @@ -141,25 +141,29 @@ function encode(buffer: ArrayBuffer | null) { return outputArray; } -navigator.serviceWorker.ready.then(async swr => { - registration = swr; +if (navigator.serviceWorker == null) { + // TODO: よしなに? +} else { + navigator.serviceWorker.ready.then(async swr => { + registration = swr; - pushSubscription = await registration.pushManager.getSubscription(); + pushSubscription = await registration.pushManager.getSubscription(); - if (instance.swPublickey && ('PushManager' in window) && $i && $i.token) { - supported = true; + if (instance.swPublickey && ('PushManager' in window) && $i && $i.token) { + supported = true; - if (pushSubscription) { - const res = await api('sw/show-registration', { - endpoint: pushSubscription.endpoint, - }); + if (pushSubscription) { + const res = await api('sw/show-registration', { + endpoint: pushSubscription.endpoint, + }); - if (res) { - pushRegistrationInServer = res; + if (res) { + pushRegistrationInServer = res; + } } } - } -}); + }); +} defineExpose({ pushRegistrationInServer: $$(pushRegistrationInServer),