Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #240 from mebjas/develop-notif
Browse files Browse the repository at this point in the history
Save a preference in local settings to record when the user has hidden the notifications warning bar.
  • Loading branch information
richvdh committed Mar 29, 2016
2 parents e068a92 + 6fc0aae commit d7f8017
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions src/Notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,39 +132,33 @@ var Notifier = {
}
}

if(enable) {
if (!this.havePermission()) {
global.Notification.requestPermission(function() {
if (callback) {
callback();
dis.dispatch({
action: "notifier_enabled",
value: true
});
}
});
}

if (!global.localStorage) return;
global.localStorage.setItem('notifications_enabled', 'true');

if (this.havePermission) {
if (enable) {
// Attempt to get permission from user
global.Notification.requestPermission(function(result) {
if (result !== 'granted') {
// The permission request was dismissed or denied
return;
}

if (global.localStorage) {
global.localStorage.setItem('notifications_enabled', 'true');
}

if (callback) callback();
dis.dispatch({
action: "notifier_enabled",
value: true
});
}
}
else {
});
this.setToolbarHidden(false);
} else {
if (!global.localStorage) return;
global.localStorage.setItem('notifications_enabled', 'false');
dis.dispatch({
action: "notifier_enabled",
value: false
});
}

this.setToolbarHidden(false);
},

isEnabled: function() {
Expand Down Expand Up @@ -192,15 +186,27 @@ var Notifier = {
return enabled === 'true';
},

setToolbarHidden: function(hidden) {
setToolbarHidden: function(hidden, persistent = true) {
this.toolbarHidden = hidden;
dis.dispatch({
action: "notifier_enabled",
value: this.isEnabled()
});

// update the info to localStorage for persistent settings
if (persistent && global.localStorage) {
global.localStorage.setItem('notifications_hidden', hidden);
}
},

isToolbarHidden: function() {
// Check localStorage for any such meta data
if (global.localStorage) {
if (global.localStorage.getItem('notifications_hidden') === 'true') {
return true;
}
}

return this.toolbarHidden;
},

Expand Down

0 comments on commit d7f8017

Please sign in to comment.