diff --git a/js/background.js b/js/background.js index 8a487093..637c99d6 100644 --- a/js/background.js +++ b/js/background.js @@ -9,29 +9,11 @@ }; console.log('background page reloaded'); - // register some chrome listeners - if (chrome.notifications) { - chrome.notifications.onClicked.addListener(function() { - extension.notification.clear(); - Whisper.Notifications.onclick(); - }); - chrome.notifications.onButtonClicked.addListener(function() { - extension.notification.clear(); - Whisper.Notifications.clear(); - getInboxCollection().each(function(model) { - model.markRead(); - }); - }); - chrome.notifications.onClosed.addListener(function(id, byUser) { - if (byUser) { - Whisper.Notifications.clear(); - } - }); - } + extension.notification.init(); // Close and reopen existing windows var open = false; - chrome.app.window.getAll().forEach(function(appWindow) { + extension.windows.getAll().forEach(function(appWindow) { open = true; appWindow.close(); }); diff --git a/js/chromium.js b/js/chromium.js index 39d7b5f3..0ed50dc5 100644 --- a/js/chromium.js +++ b/js/chromium.js @@ -105,6 +105,10 @@ } }, + getAll: function() { + return chrome.app.window.getAll(); + }, + getViews: function() { if (chrome.extension) { return chrome.extension.getViews(); @@ -214,6 +218,27 @@ var notification_pending = Promise.resolve(); extension.notification = { + init: function() { + // register some chrome listeners + if (chrome.notifications) { + chrome.notifications.onClicked.addListener(function() { + extension.notification.clear(); + Whisper.Notifications.onclick(); + }); + chrome.notifications.onButtonClicked.addListener(function() { + extension.notification.clear(); + Whisper.Notifications.clear(); + getInboxCollection().each(function(model) { + model.markRead(); + }); + }); + chrome.notifications.onClosed.addListener(function(id, byUser) { + if (byUser) { + Whisper.Notifications.clear(); + } + }); + } + }, clear: function() { notification_pending = notification_pending.then(function() { return new Promise(function(resolve) {