diff --git a/src/layouts/MainLayout.vue b/src/layouts/MainLayout.vue index d32876e..bd703c2 100644 --- a/src/layouts/MainLayout.vue +++ b/src/layouts/MainLayout.vue @@ -135,7 +135,10 @@ export default defineComponent({ const useNative = 'Notification' in window && window.Notification !== undefined; const noPermission = ref(!useNative || window.Notification.permission !== 'granted'); - onBeforeMount(() => pollNotification()); + onBeforeMount(() => { + polling.value = window.setInterval(() => pollNotification(), config.pollingInterval); + pollNotification(); + }); onBeforeUnmount(() => window.clearInterval(polling.value)); const leftDrawerOpen = computed({ @@ -170,19 +173,17 @@ export default defineComponent({ } function pollNotification() { - polling.value = window.setInterval(() => { - void mainStore - .loadNotifications(flaschengeist) - .then((notifications) => { - if (useNative && !noPermission.value) - notifications.forEach( - (notif) => - new window.Notification(notif.text, { - timestamp: notif.time.getTime(), - }) - ); - }); - }, config.pollingInterval); + void mainStore + .loadNotifications(flaschengeist) + .then((notifications) => { + if (useNative && !noPermission.value) + notifications.forEach( + (notif) => + new window.Notification(notif.text, { + timestamp: notif.time.getTime(), + }) + ); + }); } return {