Skip to content

Commit

Permalink
Merge pull request #356 from alexanderlz/master
Browse files Browse the repository at this point in the history
Bug #307 Fix: Notifications stopped working
  • Loading branch information
arikfr committed Jan 22, 2015
2 parents 88abbc7 + 0b0b88a commit 83727ae
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions rd_ui/app/scripts/services/notifications.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
(function () {
var notifications = function (Events) {
var notificationService = {};
var lastNotification = null;

notificationService.isSupported = function () {
if (window.webkitNotifications) {
if ("Notification" in window) {
return true;
} else {
console.log("HTML5 notifications are not supported.");
Expand All @@ -17,8 +16,12 @@
return;
}

if (!window.webkitNotifications.checkPermission() == 0) { // 0 is PERMISSION_ALLOWED
window.webkitNotifications.requestPermission();
if (Notification.permission !== "granted") {
Notification.requestPermission(function (status) {
if (Notification.permission !== status) {
Notification.permission = status;
}
});
}
}

Expand All @@ -27,23 +30,13 @@
return;
}

if (document.webkitVisibilityState && document.webkitVisibilityState == 'visible') {
return;
}

if (lastNotification) {
lastNotification.cancel();
}

var notification = window.webkitNotifications.createNotification('', title, content);
lastNotification = notification;
//using the 'tag' to avoid showing duplicate notifications
var notification = new Notification(title, {'tag': title+content, 'body': content});
notification.onclick = function () {
window.focus();
this.cancel();
Events.record(currentUser, 'click', 'notification');
};

notification.show()
}

return notificationService;
Expand Down

0 comments on commit 83727ae

Please sign in to comment.