From 4e2723a7511bd6e96c667a009abb62b42495f35d Mon Sep 17 00:00:00 2001 From: lilia Date: Sun, 1 Nov 2015 23:44:15 -0800 Subject: [PATCH] Create notifications if window is not focused Track focus using focus and blur events. // FREEBIE --- js/panel_controller.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/js/panel_controller.js b/js/panel_controller.js index aa5145c82..4c6a15951 100644 --- a/js/panel_controller.js +++ b/js/panel_controller.js @@ -27,10 +27,12 @@ if (inboxOpened) { conversation.trigger('newmessages'); - extension.windows.drawAttention(inboxWindowId); - if (!appWindow.isMinimized()) { + if (inboxFocused) { return; } + if (inboxOpened) { + extension.windows.drawAttention(inboxWindowId); + } } if (Whisper.Notifications.isEnabled()) { @@ -54,6 +56,7 @@ }; /* Inbox window controller */ + var inboxFocused = false; var inboxOpened = false; var inboxWindowId = 'inbox'; var appWindow = null; @@ -77,6 +80,13 @@ appWindow = null; }); + appWindow.contentWindow.addEventListener('blur', function() { + inboxFocused = false; + }); + appWindow.contentWindow.addEventListener('focus', function() { + inboxFocused = true; + }); + // close the panel if background.html is refreshed extension.windows.beforeUnload(function() { // TODO: reattach after reload instead of closing.