2025-06-30 18:58:24 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: © 2025 Hornwitser <code@hornwitser.no>
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
-->
|
2025-03-05 15:36:50 +01:00
|
|
|
<template>
|
|
|
|
<section>
|
2025-03-07 16:08:45 +01:00
|
|
|
Notifications are: <b>{{ subscribed ? "Enabled" : "Disabled" }}</b>
|
2025-03-05 15:36:50 +01:00
|
|
|
<br />
|
|
|
|
<button
|
2025-03-07 16:08:45 +01:00
|
|
|
:disabled="!supported"
|
2025-03-05 15:36:50 +01:00
|
|
|
@click="onClick"
|
|
|
|
>
|
2025-03-07 16:08:45 +01:00
|
|
|
{{ supported === undefined ? "Checking for support" : null }}
|
|
|
|
{{ supported === false ? "Notifications are not supported :(." : null }}
|
|
|
|
{{ supported === true ? (subscribed ? "Disable notifications" : "Enable notifications") : null }}
|
2025-03-05 15:36:50 +01:00
|
|
|
</button>
|
|
|
|
<details>
|
|
|
|
<summary>Debug</summary>
|
|
|
|
<pre><code>{{ JSON.stringify(subscription?.toJSON(), undefined, 4) ?? "No subscription set" }}</code></pre>
|
|
|
|
</details>
|
|
|
|
</section>
|
|
|
|
</template>
|
2025-02-28 15:32:03 +01:00
|
|
|
|
2025-03-05 15:36:50 +01:00
|
|
|
<script setup lang="ts">
|
2025-05-24 17:53:33 +02:00
|
|
|
const sessionStore = useSessionStore();
|
2025-03-07 16:08:45 +01:00
|
|
|
const { supported, subscription, getSubscription, subscribe, unsubscribe } = usePushNotification();
|
2025-05-24 17:53:33 +02:00
|
|
|
const subscribed = computed(() => Boolean(subscription.value && sessionStore.push));
|
2025-03-07 14:11:07 +01:00
|
|
|
async function onClick() {
|
2025-03-07 16:08:45 +01:00
|
|
|
if (!subscribed.value)
|
|
|
|
await subscribe();
|
2025-03-05 15:36:50 +01:00
|
|
|
else
|
2025-03-07 16:08:45 +01:00
|
|
|
await unsubscribe();
|
2025-05-24 17:53:33 +02:00
|
|
|
await sessionStore.fetch();
|
2025-02-28 15:32:03 +01:00
|
|
|
}
|
2025-03-05 15:36:50 +01:00
|
|
|
|
|
|
|
onMounted(() => {
|
2025-03-07 16:08:45 +01:00
|
|
|
getSubscription();
|
2025-03-05 15:36:50 +01:00
|
|
|
})
|
|
|
|
</script>
|