From 9d03e085ed71d8840d1f5a941d306f7214058633 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Wed, 4 May 2016 08:12:51 +0000 Subject: [PATCH] Ask for notification permission only when it gets called --- api/js/jsapi/egw_notification.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/api/js/jsapi/egw_notification.js b/api/js/jsapi/egw_notification.js index c5e86eb432..dcbc32bcab 100644 --- a/api/js/jsapi/egw_notification.js +++ b/api/js/jsapi/egw_notification.js @@ -27,9 +27,6 @@ egw.extend('notification', egw.MODULE_WND_LOCAL, function(_app, _wnd) // Notification permission, the default value is 'default' which is equivalent to 'denied' var permission = Notification.permission || 'default'; - if (Notification && Notification.requestPermission) Notification.requestPermission (function(_permission){ - permission = _permission; - }); return { @@ -48,9 +45,18 @@ egw.extend('notification', egw.MODULE_WND_LOCAL, function(_app, _wnd) * onclose: // Callback function dispateches on notification close * onerror: // Callback function dispatches on error, default is a egw.debug log * } + * @return {boolean} true if the permission is granted otherwise false */ notification: function (_title, _options) { + + var self = this; + // Check and ask for permission + if (Notification && Notification.requestPermission && permission === 'default') Notification.requestPermission (function(_permission){ + permission = _permission; + if (permission === 'granted') self.notification(_title,_options); + }); + // All options including callbacks var options = _options || {}; @@ -74,7 +80,7 @@ egw.extend('notification', egw.MODULE_WND_LOCAL, function(_app, _wnd) notification.onclose = options.onclose || ''; // Callback function dispatches on error notification.onerror = options.onerror || function (e) {egw.debug('Notification failed because of ' + e);}; - + } };