@@ -124,31 +124,39 @@ export async function showNotifications(notifications) {
124
124
}
125
125
}
126
126
127
- export function playNotificationSound ( ) {
128
- const audio = new Audio ( ) ;
129
- audio . src = browser . runtime . getURL ( 'sounds/bell.ogg' ) ;
130
- audio . play ( ) ;
127
+ export async function playNotificationSound ( ) {
128
+ await browser . runtime . sendMessage ( {
129
+ action : 'play' ,
130
+ options : {
131
+ source : 'sounds/bell.ogg' ,
132
+ volume : 1
133
+ }
134
+ } ) ;
131
135
}
132
136
133
137
export async function checkNotifications ( lastModified ) {
134
- let notifications = await getNotifications ( { lastModified} ) ;
135
- const { showDesktopNotif, playNotifSound, filterNotifications} = await optionsStorage . getAll ( ) ;
136
-
137
- if ( filterNotifications ) {
138
- const repositories = await repositoriesStorage . getAll ( ) ;
139
- /* eslint-disable camelcase */
140
- notifications = notifications . filter ( ( { repository : { full_name} } ) => {
141
- const { owner, repository} = parseFullName ( full_name ) ;
142
- return Boolean ( repositories [ owner ] && repositories [ owner ] [ repository ] ) ;
143
- } ) ;
144
- /* eslint-enable camelcase */
145
- }
138
+ try {
139
+ let notifications = await getNotifications ( { lastModified} ) ;
140
+ const { showDesktopNotif, playNotifSound, filterNotifications} = await optionsStorage . getAll ( ) ;
141
+
142
+ if ( filterNotifications ) {
143
+ const repositories = await repositoriesStorage . getAll ( ) ;
144
+ /* eslint-disable camelcase */
145
+ notifications = notifications . filter ( ( { repository : { full_name} } ) => {
146
+ const { owner, repository} = parseFullName ( full_name ) ;
147
+ return Boolean ( repositories [ owner ] && repositories [ owner ] [ repository ] ) ;
148
+ } ) ;
149
+ /* eslint-enable camelcase */
150
+ }
146
151
147
- if ( playNotifSound && notifications . length > 0 ) {
148
- playNotificationSound ( ) ;
149
- }
152
+ if ( playNotifSound && notifications . length > 0 ) {
153
+ await playNotificationSound ( ) ;
154
+ }
150
155
151
- if ( showDesktopNotif ) {
152
- await showNotifications ( notifications ) ;
156
+ if ( showDesktopNotif ) {
157
+ await showNotifications ( notifications ) ;
158
+ }
159
+ } catch ( error ) {
160
+ console . error ( error ) ;
153
161
}
154
162
}
0 commit comments