Skip to content

Commit aa510ca

Browse files
committedDec 9, 2024
notification permission request fix
1 parent cef34af commit aa510ca

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed
 

‎src/Components/timers/DisplayTimer.jsx

+15-9
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,33 @@ const DisplayTimer = ({
8282
// window.focus();
8383
// timerCompleteNotification.close();
8484
// };
85-
if ('serviceWorker' in navigator && navigator.serviceWorker.controller) {
85+
if (
86+
"serviceWorker" in navigator &&
87+
navigator.serviceWorker.controller &&
88+
Notification.permission === "granted"
89+
) {
8690
// Send message to service worker
8791
navigator.serviceWorker.controller.postMessage({
88-
type: 'SHOW_NOTIFICATION',
92+
type: "SHOW_NOTIFICATION",
8993
payload: {
90-
title: 'Timer Complete!',
94+
title: "Timer Complete!",
9195
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${
9399
componentName === "Rest"
94100
? "Ready to start working?"
95101
: "Time for a break!"
96102
}`,
97-
icon: '/Icons/pwa/128x128.png',
98-
badge: '/Icons/pwa/128x128.png',
103+
icon: "/Icons/pwa/128x128.png",
104+
badge: "/Icons/pwa/128x128.png",
99105
silent: false,
100106
vibrate: [200, 100, 200],
101-
tag: 'timer-notification',
107+
tag: "timer-notification",
102108
renotify: true,
103109
requireInteraction: true,
104-
}
105-
}
110+
},
111+
},
106112
});
107113
}
108114
await addTime(defaultTime * 60);

0 commit comments

Comments
 (0)