Switching to Chrome Rich Notifications when available

This commit is contained in:
Rodolphe Breard 2013-05-26 16:52:40 +02:00
parent 6e756f89be
commit e6e0ec2d76

View file

@ -117,21 +117,44 @@ Nsui.prototype.sendNotification = function(image, title, message) {
message = message.substr(0, 32) + "…"; message = message.substr(0, 32) + "…";
} }
notif = webkitNotifications.createNotification( if (typeof chrome.notifications !== "undefined") {
image, chrome.notifications.create(
title, '',
message {
); type: 'basic',
iconUrl: image,
title: title,
message: message,
priority: 0
},
function(id) {
setTimeout(function() {
chrome.notifications.clear(id, function() {});
}, 5000);
}
);
notif.onclick = function() { chrome.notifications.onClicked.addListener(function(id) {
window.focus(); window.focus();
this.cancel(); chrome.notifications.clear(id, function() {});
}; });
} else {
notif = webkitNotifications.createNotification(
image,
title,
message
);
notif.show(); notif.onclick = function() {
setTimeout(function() { window.focus();
notif.cancel(); this.cancel();
}, 5000); };
notif.show();
setTimeout(function() {
notif.cancel();
}, 5000);
}
} }
Nsui.prototype.addContentToTab = function(tab_name, content) { Nsui.prototype.addContentToTab = function(tab_name, content) {