@@ -82,27 +82,33 @@ const DisplayTimer = ({
82
82
// window.focus();
83
83
// timerCompleteNotification.close();
84
84
// };
85
- if ( 'serviceWorker' in navigator && navigator . serviceWorker . controller ) {
85
+ if (
86
+ "serviceWorker" in navigator &&
87
+ navigator . serviceWorker . controller &&
88
+ Notification . permission === "granted"
89
+ ) {
86
90
// Send message to service worker
87
91
navigator . serviceWorker . controller . postMessage ( {
88
- type : ' SHOW_NOTIFICATION' ,
92
+ type : " SHOW_NOTIFICATION" ,
89
93
payload : {
90
- title : ' Timer Complete!' ,
94
+ title : " Timer Complete!" ,
91
95
options : {
92
- body : `Your ${ componentName } session of (${ timer . defaultDuration / 60 } minutes) has ended.\n${
96
+ body : `Your ${ componentName } session of (${
97
+ timer . defaultDuration / 60
98
+ } minutes) has ended.\n${
93
99
componentName === "Rest"
94
100
? "Ready to start working?"
95
101
: "Time for a break!"
96
102
} `,
97
- icon : ' /Icons/pwa/128x128.png' ,
98
- badge : ' /Icons/pwa/128x128.png' ,
103
+ icon : " /Icons/pwa/128x128.png" ,
104
+ badge : " /Icons/pwa/128x128.png" ,
99
105
silent : false ,
100
106
vibrate : [ 200 , 100 , 200 ] ,
101
- tag : ' timer-notification' ,
107
+ tag : " timer-notification" ,
102
108
renotify : true ,
103
109
requireInteraction : true ,
104
- }
105
- }
110
+ } ,
111
+ } ,
106
112
} ) ;
107
113
}
108
114
await addTime ( defaultTime * 60 ) ;
0 commit comments