diff --git a/client/dcwebui.js b/client/dcwebui.js index 66a3387..8dd81db 100644 --- a/client/dcwebui.js +++ b/client/dcwebui.js @@ -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)) { return; // not supported by browser } switch (window.Notification.permission) { case "granted": { - new Notification(title, { + var n = new Notification(title, { body: body, icon: EXTERN_ROOT + "/favicon.ico" }); + n.onclick = function() { + parent.focus(); // recent chrome + window.focus(); // older browsers + tab_set(tab); + this.close(); + }; } break; case "denied": return; @@ -857,7 +863,7 @@ var desktop_notifications_toggle = function(ev) { }; var desktop_notifications_onEnable = function() { - notify(hub_hubname, "Desktop popups enabled"); + notify(hub_hubname, "Desktop popups enabled", "tab-main"); } var scrollback_move = function(delta) { @@ -1083,7 +1089,7 @@ window.onload = function() { tab_mark_unread( pm_tabs[data.user] ); if (desktop_notifications_enabled) { - notify("Message from " + data.user, data.message); + notify("Message from " + data.user, data.message, pm_tabs[data.user]); } } });