Commit 51fc10ab authored by lilia's avatar lilia
Browse files

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
parent d201c65f
......@@ -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);
});
......
......@@ -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') {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment