From 6aff2657e9ecc0997a222123ba5016c209cc1cab Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Fri, 1 Dec 2017 22:27:36 +0200 Subject: [PATCH] Ask for notification permission on page load if setting is enabled --- client/js/options.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/client/js/options.js b/client/js/options.js index 4faca65e..0c62bee1 100644 --- a/client/js/options.js +++ b/client/js/options.js @@ -132,11 +132,21 @@ module.exports.initialize = () => { .trigger("change"); $("#desktopNotifications").on("change", function() { - if ($(this).prop("checked") && Notification.permission !== "granted") { - Notification.requestPermission(updateDesktopNotificationStatus); + if ($(this).prop("checked")) { + requestPermissionIfNeeded(); } }); + var requestPermissionIfNeeded = function() { + if (Notification.permission !== "granted") { + Notification.requestPermission(updateDesktopNotificationStatus); + } + }; + + if (options.desktopNotifications) { + requestPermissionIfNeeded(); + } + // Updates the checkbox and warning in settings when the Settings page is // opened or when the checkbox state is changed. // When notifications are not supported, this is never called (because