feat: do not load notifications while in the background

This commit is contained in:
kolaente 2024-09-23 10:31:09 +02:00
parent dea123dbea
commit c35c70e71f
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
1 changed files with 5 additions and 0 deletions

View File

@ -124,15 +124,20 @@ let interval: ReturnType<typeof setInterval>
onMounted(() => {
loadNotifications()
document.addEventListener('click', hidePopup)
document.addEventListener('visibilitychange', loadNotifications)
interval = setInterval(loadNotifications, LOAD_NOTIFICATIONS_INTERVAL)
})
onUnmounted(() => {
document.removeEventListener('click', hidePopup)
document.removeEventListener('visibilitychange', loadNotifications)
clearInterval(interval)
})
async function loadNotifications() {
if (document.visibilityState !== 'visible') {
return
}
// We're recreating the notification service here to make sure it uses the latest api user token
const notificationService = new NotificationService()
allNotifications.value = await notificationService.getAll()