Improve notification behavior

Only allow one notification at a time. Use a basic notification for
normal messages, and image notification for image messages, and a list
notification when there are multiple unread messages.

// FREEBIE
This commit is contained in:
lilia 2015-09-13 20:25:04 -07:00
parent 59313b5177
commit e8edbe53bc
4 changed files with 133 additions and 27 deletions

View file

@ -170,6 +170,49 @@
}
};
if (chrome) {
chrome.notifications.onClicked.addListener(function() {
chrome.notifications.clear('signal');
Whisper.Notifications.onclick();
});
chrome.notifications.onButtonClicked.addListener(function() {
chrome.notifications.clear('signal');
Whisper.Notifications.clear();
getInboxCollection().each(function(model) {
if (model.get('unreadCount') > 0) {
model.markRead();
}
});
});
chrome.notifications.onClosed.addListener(function(id, byUser) {
if (byUser) {
Whisper.Notifications.clear();
}
});
}
extension.notify = function(options) {
if (chrome) {
chrome.notifications.clear('signal');
chrome.notifications.create('signal', {
type : options.type,
title : options.title,
message : options.message || '', // required
iconUrl : options.iconUrl,
items : options.items,
buttons : options.buttons
});
} else {
var notification = new Notification(options.title, {
body : options.message,
icon : options.iconUrl,
tag : 'signal'
});
notification.onclick = function() {
Whisper.Notifications.onclick();
};
}
};
if (chrome.runtime.onInstalled) {
chrome.runtime.onInstalled.addListener(function(options) {
if (options.reason === 'install') {