Send notifications over the JS→C++ bridge if it exists.

When determining if desktop notifications are enabled, we can check whether
there is a "window.bridge" element.

Now when it comes time to actually send out notifications, we can just test
again for the existence of "window.bridge" and if so, shunt the data over
it.

(imported from commit 8104c91ea9da7bc485c86a3c21edc88905d2f47b)
This commit is contained in:
Luke Faraone 2013-05-31 13:25:39 -07:00
parent 3ee4161ace
commit c5d3ca0247
1 changed files with 23 additions and 16 deletions

View File

@ -13,7 +13,9 @@ function browser_desktop_notifications_on () {
// Firefox on Ubuntu claims to do webkitNotifications but its notifications are terrible
$.browser.webkit &&
// 0 is PERMISSION_ALLOWED
window.webkitNotifications.checkPermission() === 0);
window.webkitNotifications.checkPermission() === 0) ||
// window.bridge is the desktop client
(window.bridge !== undefined);
}
exports.initialize = function () {
@ -132,7 +134,7 @@ function process_desktop_notification(message) {
content += " [...]";
}
if (notice_memory[key] !== undefined) {
if (window.bridge === undefined && notice_memory[key] !== undefined) {
msg_count = notice_memory[key].msg_count + 1;
title = msg_count + " messages from " + title;
notification_object = notice_memory[key].obj;
@ -156,6 +158,7 @@ function process_desktop_notification(message) {
title += " (to " + message.stream + " > " + message.subject + ")";
}
if (window.bridge === undefined) {
notice_memory[key] = {
obj: window.webkitNotifications.createNotification(
gravatar_url(message), title, content),
@ -170,6 +173,10 @@ function process_desktop_notification(message) {
delete notice_memory[key];
};
notification_object.show();
} else {
// Shunt the message along to the desktop client
window.bridge.notify({title: title, content: content});
}
}
exports.speaking_at_me = function (message) {