@@ -3,11 +3,17 @@ import { defineStore } from 'pinia'
33import { readonly , ref , watch } from 'vue'
44import type { Thread } from '../api/notifications'
55import { getNotifications } from '../api/notifications'
6- import { Page } from '../constants'
6+ import { InvokeCommand , Page } from '../constants'
77import { AppStorage } from '../storage'
88import type { NotificationListData , Option } from '../types'
99import { notificationListFromThreads } from '../utils/notification'
1010
11+ function hasNewNotification ( newThreads : Thread [ ] , previousThreads : Thread [ ] ) {
12+ const newThreadsFiltered = newThreads . filter ( t => t . unread )
13+ const previousThreadsFiltered = previousThreads . filter ( t => t . unread )
14+ return ! newThreadsFiltered . every ( newT => previousThreadsFiltered . some ( prevT => prevT . id === newT . id ) )
15+ }
16+
1117export const useStore = defineStore ( 'store' , ( ) => {
1218 const notifications = ref < NotificationListData [ ] > ( [ ] )
1319 const loadingNotifications = ref ( false )
@@ -48,17 +54,23 @@ export const useStore = defineStore('store', () => {
4854 notifications . value = [ ]
4955 failedLoadingNotifications . value = true
5056 }
51- finally {
52- loadingNotifications . value = false
53- skeletonVisible . value = false
54- }
57+
58+ loadingNotifications . value = false
59+ skeletonVisible . value = false
60+
61+ if (
62+ AppStorage . get ( 'soundsEnabled' )
63+ && hasNewNotification ( notificationsRaw , notificationsRawPrevious )
64+ )
65+ invoke ( InvokeCommand . PlayNotificationSound )
5566 }
5667
5768 const currentPage = ref ( Page . Landing )
5869 const pageFrom = ref < Option < Page > > ( null )
5970
6071 function logout ( ) {
6172 AppStorage . set ( 'accessToken' , null )
73+ AppStorage . set ( 'user' , null )
6274 notifications . value = [ ]
6375 currentPage . value = Page . Landing
6476 }
@@ -73,8 +85,7 @@ export const useStore = defineStore('store', () => {
7385
7486 watch ( notifications , ( ) => {
7587 const hasUnread = notificationsRaw . some ( n => n . unread )
76- console . log ( { hasUnread } )
77- invoke ( 'set_icon_template' , { isTemplate : ! hasUnread } )
88+ invoke ( InvokeCommand . SetIconTemplate , { isTemplate : ! hasUnread } )
7889 } , { deep : true , immediate : true } )
7990
8091 return {
0 commit comments