notification issue fixed
Signed-off-by: Minhaz A V <minhazav@gmail.com>
This commit is contained in:
parent
4e97fe982d
commit
98343a065c
1 changed files with 54 additions and 20 deletions
|
@ -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() {
|
||||||
|
|
Loading…
Reference in a new issue