From e6e0ec2d76497b9a9924e380c5a0e903d170dbe5 Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Sun, 26 May 2013 16:52:40 +0200 Subject: [PATCH] Switching to Chrome Rich Notifications when available --- lib/nsui.js | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/lib/nsui.js b/lib/nsui.js index d710de5..b21779b 100644 --- a/lib/nsui.js +++ b/lib/nsui.js @@ -117,21 +117,44 @@ Nsui.prototype.sendNotification = function(image, title, message) { message = message.substr(0, 32) + "…"; } - notif = webkitNotifications.createNotification( - image, - title, - message - ); + if (typeof chrome.notifications !== "undefined") { + chrome.notifications.create( + '', + { + type: 'basic', + iconUrl: image, + title: title, + message: message, + priority: 0 + }, + function(id) { + setTimeout(function() { + chrome.notifications.clear(id, function() {}); + }, 5000); + } + ); - notif.onclick = function() { - window.focus(); - this.cancel(); - }; + chrome.notifications.onClicked.addListener(function(id) { + window.focus(); + chrome.notifications.clear(id, function() {}); + }); + } else { + notif = webkitNotifications.createNotification( + image, + title, + message + ); - notif.show(); - setTimeout(function() { - notif.cancel(); - }, 5000); + notif.onclick = function() { + window.focus(); + this.cancel(); + }; + + notif.show(); + setTimeout(function() { + notif.cancel(); + }, 5000); + } } Nsui.prototype.addContentToTab = function(tab_name, content) {