diff --git a/js/background.js b/js/background.js index c2e19d8a..19ea1f5e 100644 --- a/js/background.js +++ b/js/background.js @@ -23,12 +23,6 @@ } }); } - if (chrome && chrome.alarms) { - chrome.alarms.onAlarm.addListener(function() { - // nothing to do. - }); - chrome.alarms.create('awake', {periodInMinutes: 1}); - } // Close and reopen existing windows var open = false; @@ -74,10 +68,12 @@ setUnreadCount(storage.get("unreadCount", 0)); if (textsecure.registration.isDone()) { + extension.keepAwake(); init(); } extension.on('registration_done', function() { + extension.keepAwake(); init(true); }); diff --git a/js/chromium.js b/js/chromium.js index 42384e40..3e3a17be 100644 --- a/js/chromium.js +++ b/js/chromium.js @@ -231,6 +231,15 @@ } }; + extension.keepAwake = function() { + if (chrome && chrome.alarms) { + chrome.alarms.onAlarm.addListener(function() { + // nothing to do. + }); + chrome.alarms.create('awake', {periodInMinutes: 1}); + } + }; + if (chrome.runtime.onInstalled) { chrome.runtime.onInstalled.addListener(function(options) { if (options.reason === 'install') {