Ask for notification permission only when it gets called

This commit is contained in:
Hadi Nategh 2016-05-04 08:12:51 +00:00
parent d9f99b9fe4
commit 9d03e085ed

View File

@ -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 || {};