@@ -3,11 +3,17 @@ import { defineStore } from 'pinia'
3
3
import { readonly , ref , watch } from 'vue'
4
4
import type { Thread } from '../api/notifications'
5
5
import { getNotifications } from '../api/notifications'
6
- import { Page } from '../constants'
6
+ import { InvokeCommand , Page } from '../constants'
7
7
import { AppStorage } from '../storage'
8
8
import type { NotificationListData , Option } from '../types'
9
9
import { notificationListFromThreads } from '../utils/notification'
10
10
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
+
11
17
export const useStore = defineStore ( 'store' , ( ) => {
12
18
const notifications = ref < NotificationListData [ ] > ( [ ] )
13
19
const loadingNotifications = ref ( false )
@@ -48,17 +54,23 @@ export const useStore = defineStore('store', () => {
48
54
notifications . value = [ ]
49
55
failedLoadingNotifications . value = true
50
56
}
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 )
55
66
}
56
67
57
68
const currentPage = ref ( Page . Landing )
58
69
const pageFrom = ref < Option < Page > > ( null )
59
70
60
71
function logout ( ) {
61
72
AppStorage . set ( 'accessToken' , null )
73
+ AppStorage . set ( 'user' , null )
62
74
notifications . value = [ ]
63
75
currentPage . value = Page . Landing
64
76
}
@@ -73,8 +85,7 @@ export const useStore = defineStore('store', () => {
73
85
74
86
watch ( notifications , ( ) => {
75
87
const hasUnread = notificationsRaw . some ( n => n . unread )
76
- console . log ( { hasUnread } )
77
- invoke ( 'set_icon_template' , { isTemplate : ! hasUnread } )
88
+ invoke ( InvokeCommand . SetIconTemplate , { isTemplate : ! hasUnread } )
78
89
} , { deep : true , immediate : true } )
79
90
80
91
return {
0 commit comments