fix: request push notifications on mobile (#553)

zio/stable
Joaquín Sánchez 2022-12-26 10:13:59 +01:00 committed by GitHub
parent 613c5315b3
commit f28923f86f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 10 deletions

View File

@ -36,7 +36,7 @@ const isLegacyAccount = computed(() => !currentUser.value?.vapidKey)
<button <button
btn-outline rounded-full font-bold py4 flex="~ gap2 center" m5 btn-outline rounded-full font-bold py4 flex="~ gap2 center" m5
type="button" type="button"
:class="busy ? 'border-transparent' : null" :class="busy || isLegacyAccount ? 'border-transparent' : null"
:disabled="busy || isLegacyAccount" :disabled="busy || isLegacyAccount"
@click="$emit('subscribe')" @click="$emit('subscribe')"
> >

View File

@ -74,14 +74,14 @@ export const usePushManager = () => {
if (!notificationPermission.value || (notificationPermission.value === 'prompt' && !hiddenNotification.value[acct])) { if (!notificationPermission.value || (notificationPermission.value === 'prompt' && !hiddenNotification.value[acct])) {
// safari 16 does not support navigator.permissions.query for notifications // safari 16 does not support navigator.permissions.query for notifications
try { // try {
permission = (await navigator.permissions?.query({ name: 'notifications' }))?.state // permission = (await navigator.permissions?.query({ name: 'notifications' }))?.state
} // }
catch { // catch {
permission = await Promise.resolve(Notification.requestPermission()).then((p: NotificationPermission) => { permission = await Promise.resolve(Notification.requestPermission()).then((p: NotificationPermission) => {
return p === 'default' ? 'prompt' : p return p === 'default' ? 'prompt' : p
}) })
} // }
} }
else { else {
permission = notificationPermission.value permission = notificationPermission.value

View File

@ -43,7 +43,7 @@ export const onPush = (event: PushEvent) => {
icon, icon,
lang: preferred_locale, lang: preferred_locale,
tag: notification_id, tag: notification_id,
timestamp: new Date().getUTCDate(), timestamp: new Date().getTime(),
} }
return self.registration.showNotification(options.title, notificationOptions) return self.registration.showNotification(options.title, notificationOptions)
}) })