Skip to content

Commit 36184e4

Browse files
committed
chore: better toggling of current device
1 parent e301aa2 commit 36184e4

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

ui/src/components/register-device.vue

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
<v-btn
2121
variant="text"
2222
class="ml-1"
23-
@click="register"
23+
:disabled="register.loading.value"
24+
@click="register.execute()"
2425
>
2526
{{ t('ok') }}
2627
</v-btn>
@@ -75,7 +76,7 @@ const prepareServiceWorker = async () => {
7576
const registration = registrations.find(r => equalDeviceRegistrations(r.id, pushManagerSubscription.value))
7677
if (!registration) {
7778
debug('local subscription is not matched by remote, unsubscribe')
78-
await $fetch('ui-logs', { method: 'POST', body: 'webpush - service worker subscription was not matched by remote info and was unsubscribed. This means that either the user manually deleted the remote registration or something changed.', headers: { 'content-type': 'text/plain' } })
79+
await $fetch('ui-logs', { method: 'POST', body: 'webpush - service worker subscription was not matched by remote info and was unsubscribed.', headers: { 'content-type': 'text/plain' } })
7980
await pushManagerSubscription.value.unsubscribe()
8081
pushManagerSubscription.value = null
8182
} else {
@@ -97,7 +98,18 @@ const prepareServiceWorker = async () => {
9798
}
9899
prepareServiceWorker()
99100
100-
const register = async () => {
101+
watch(() => registrations, async () => {
102+
if (pushManagerSubscription.value) {
103+
const registration = registrations.find(r => equalDeviceRegistrations(r.id, pushManagerSubscription.value))
104+
if (!registration) {
105+
debug('local subscription was deleted, unsubscribe')
106+
await pushManagerSubscription.value.unsubscribe()
107+
pushManagerSubscription.value = null
108+
}
109+
}
110+
})
111+
112+
const register = useAsyncAction(async () => {
101113
try {
102114
debug('register current device')
103115
const serviceWorkerRegistration = await navigator.serviceWorker.ready
@@ -120,7 +132,7 @@ const register = async () => {
120132
error.value = 'Échec lors de l\'envoi d\'une notification à cet appareil. Votre navigateur n\'est peut-être pas compatible avec la fonctionnalité "push messaging".'
121133
}
122134
}
123-
}
135+
})
124136
</script>
125137

126138
<style lang="css" scoped>

0 commit comments

Comments
 (0)