Skip to content

Commit 96ef02e

Browse files
committed
fix: prevent the checkbox from flashing back off on mobile
1 parent 64d2b41 commit 96ef02e

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

js/app.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,15 @@ if ("serviceWorker" in navigator) {
275275
});
276276
}
277277

278+
// when notification permission is denied (toggle stays on; notify user)
279+
window.addEventListener("notificationPermissionDenied", () => {
280+
showToast(
281+
"Notifications are blocked. Enable them in your browser or device settings to get reminders.",
282+
"info",
283+
5000,
284+
);
285+
});
286+
278287
/* ====================== Main Functions ===================== */
279288
// Switch Tabs
280289
function switchTabs(e, btn) {

js/pushNotificationsHandler.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ document.addEventListener("DOMContentLoaded", () => {
3737
if (isEnabled) {
3838
const permission = await requestNotificationPermission();
3939
if (!permission) {
40-
e.target.removeAttribute("checked");
41-
e.target.checked = false;
40+
// Keep toggle checked so the checkbox doesn't "flash" back off on mobile.
41+
// Notifications will only fire when permission is granted; tell the user.
42+
window.dispatchEvent(new CustomEvent("notificationPermissionDenied"));
4243
}
4344
}
4445
});

0 commit comments

Comments
 (0)