notification issue fixed

Signed-off-by: Minhaz A V <minhazav@gmail.com>
This commit is contained in:
Minhaz A V 2016-03-22 03:49:46 +05:30
parent 4e97fe982d
commit 98343a065c

View file

@ -123,6 +123,26 @@ var Notifier = {
return global.Notification.permission == 'granted'; return global.Notification.permission == 'granted';
}, },
isPermissionDefault: function() {
if (!this.supportsDesktopNotifications()) return false;
return global.Notification.permission == 'default';
},
showToolbar: function() {
// Check localStorage for any such meta data
if (global.localStorage) {
if (global.localStorage.getItem('notifications_hidden') === 'true')
return false;
}
// Check if permission is granted by any chance.
if (this.havePermission()) return false;
// means the permission is blocked
if (!this.isPermissionDefault()) return false;
return true;
},
setEnabled: function(enable, callback) { setEnabled: function(enable, callback) {
// make sure that we persist the current setting audio_enabled setting // make sure that we persist the current setting audio_enabled setting
// before changing anything // before changing anything
@ -133,29 +153,35 @@ var Notifier = {
} }
if(enable) { if(enable) {
if (!this.havePermission()) { // Case when we do not have the permission as 'granted'
global.Notification.requestPermission(function() { if (this.isPermissionDefault()) {
if (callback) { // Attempt to get permission from user
callback(); var _this = this;
global.Notification.requestPermission().then(function(result) {
if (result === 'denied') {
dis.dispatch({
action: "notifier_enabled",
value: false
});
_this.setToolbarHidden(true);
return;
}
if (result === 'default') {
// The permission request was dismissed
return;
}
if (callback) callback();
dis.dispatch({ dis.dispatch({
action: "notifier_enabled", action: "notifier_enabled",
value: true value: true
}); });
}
});
}
if (!global.localStorage) return; if (!global.localStorage) return;
global.localStorage.setItem('notifications_enabled', 'true'); global.localStorage.setItem('notifications_enabled', 'true');
if (this.havePermission) {
dis.dispatch({
action: "notifier_enabled",
value: true
}); });
} }
} } else {
else {
if (!global.localStorage) return; if (!global.localStorage) return;
global.localStorage.setItem('notifications_enabled', 'false'); global.localStorage.setItem('notifications_enabled', 'false');
dis.dispatch({ dis.dispatch({
@ -163,8 +189,6 @@ var Notifier = {
value: false value: false
}); });
} }
this.setToolbarHidden(false);
}, },
isEnabled: function() { isEnabled: function() {
@ -192,12 +216,22 @@ var Notifier = {
return enabled === 'true'; return enabled === 'true';
}, },
setToolbarHidden: function(hidden) { setToolbarHidden: function(hidden, persistent) {
this.toolbarHidden = hidden; this.toolbarHidden = hidden;
dis.dispatch({ dis.dispatch({
action: "notifier_enabled", action: "notifier_enabled",
value: this.isEnabled() value: this.isEnabled()
}); });
if (persistent === true)
this.setToolbarPersistantHidden();
},
setToolbarPersistantHidden: function() {
// update the info to localStorage
if (global.localStorage) {
global.localStorage.setItem('notifications_hidden', 'true');
}
}, },
isToolbarHidden: function() { isToolbarHidden: function() {