From 9882190bde94641eb6ac92e46e3af52b046d08aa Mon Sep 17 00:00:00 2001 From: lilia Date: Fri, 22 May 2015 17:06:49 -0700 Subject: [PATCH] Wake up once a minute to check for messages If all the application windows are closed (and not merely hidden), the background page will go inactive and there's nothing we can do to stop it. However, we can ask chrome to trigger an alarm once per minute, which will spin up the background page and check for new messages. This will effectively keep us alive as long as chrome has open windows or is running in the background, subject to chrome settings' Advanced -> System -> Continue running background apps --- js/background.js | 7 +++++++ manifest.json | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/js/background.js b/js/background.js index 6382f37d1..8d45ee3de 100644 --- a/js/background.js +++ b/js/background.js @@ -16,6 +16,13 @@ ;(function() { 'use strict'; + if (chrome && chrome.alarms) { + chrome.alarms.onAlarm.addListener(function() { + // nothing to do. + }); + chrome.alarms.create('awake', {periodInMinutes: 1}); + } + storage.fetch(); storage.onready(function() { var messageReceiver; diff --git a/manifest.json b/manifest.json index af8f0098f..90e98afa6 100644 --- a/manifest.json +++ b/manifest.json @@ -9,7 +9,8 @@ "permissions": [ "unlimitedStorage", "notifications", - "fileSystem" + "fileSystem", + "alarms" ], "icons": {