From 51fc10abb6737a981e83b053fb20864e696e44a2 Mon Sep 17 00:00:00 2001 From: lilia Date: Wed, 16 Dec 2015 14:59:41 -0800 Subject: [PATCH] Don't wake up to check messages if not registered This chrome alarm business is in place to help us wake up and check for messages when running in the background. Without it, chrome will suspend our app after a short period of inactivity. Upon waking, if the app discovers it is not linked, it prompts you to link it. However, if you've declined registration (i.e., because you already maxed out your linked device limit, but chrome auto-added the app to another machine), we should just wait until explicitly launched again. Fixes #519 // FREEBIE --- js/background.js | 8 ++------ js/chromium.js | 9 +++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) 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') {