client: clicking the popup refocus browser window, switch to PM tab as necessary

This commit is contained in:
mappu 2017-02-08 18:33:17 +13:00
parent d862a3f703
commit af324441b7
1 changed files with 10 additions and 4 deletions

View File

@ -146,17 +146,23 @@ var date_format = function(d, format) {
/* */ /* */
var notify = function(title, body) { var notify = function(title, body, tab) {
if (!("Notification" in window)) { if (!("Notification" in window)) {
return; // not supported by browser return; // not supported by browser
} }
switch (window.Notification.permission) { switch (window.Notification.permission) {
case "granted": { case "granted": {
new Notification(title, { var n = new Notification(title, {
body: body, body: body,
icon: EXTERN_ROOT + "/favicon.ico" icon: EXTERN_ROOT + "/favicon.ico"
}); });
n.onclick = function() {
parent.focus(); // recent chrome
window.focus(); // older browsers
tab_set(tab);
this.close();
};
} break; } break;
case "denied": return; case "denied": return;
@ -857,7 +863,7 @@ var desktop_notifications_toggle = function(ev) {
}; };
var desktop_notifications_onEnable = function() { var desktop_notifications_onEnable = function() {
notify(hub_hubname, "Desktop popups enabled"); notify(hub_hubname, "Desktop popups enabled", "tab-main");
} }
var scrollback_move = function(delta) { var scrollback_move = function(delta) {
@ -1083,7 +1089,7 @@ window.onload = function() {
tab_mark_unread( pm_tabs[data.user] ); tab_mark_unread( pm_tabs[data.user] );
if (desktop_notifications_enabled) { if (desktop_notifications_enabled) {
notify("Message from " + data.user, data.message); notify("Message from " + data.user, data.message, pm_tabs[data.user]);
} }
} }
}); });