parent
d149ab662c
commit
82b797738a
|
@ -23,6 +23,9 @@ global API_METHODS
|
||||||
ERROR_VERSION: 'error: version is older than installed style',
|
ERROR_VERSION: 'error: version is older than installed style',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ALARM_NAME = 'scheduledUpdate';
|
||||||
|
const MIN_INTERVAL_MS = 60e3;
|
||||||
|
|
||||||
let lastUpdateTime = parseInt(localStorage.lastUpdateTime) || Date.now();
|
let lastUpdateTime = parseInt(localStorage.lastUpdateTime) || Date.now();
|
||||||
let checkingAll = false;
|
let checkingAll = false;
|
||||||
let logQueue = [];
|
let logQueue = [];
|
||||||
|
@ -207,14 +210,22 @@ global API_METHODS
|
||||||
|
|
||||||
function schedule() {
|
function schedule() {
|
||||||
const interval = prefs.get('updateInterval') * 60 * 60 * 1000;
|
const interval = prefs.get('updateInterval') * 60 * 60 * 1000;
|
||||||
if (interval) {
|
if (interval > 0) {
|
||||||
const elapsed = Math.max(0, Date.now() - lastUpdateTime);
|
const elapsed = Math.max(0, Date.now() - lastUpdateTime);
|
||||||
debounce(checkAllStyles, Math.max(10e3, interval - elapsed));
|
chrome.alarms.create(ALARM_NAME, {
|
||||||
|
when: Date.now() + Math.max(MIN_INTERVAL_MS, interval - elapsed),
|
||||||
|
});
|
||||||
|
chrome.alarms.onAlarm.addListener(onAlarm);
|
||||||
} else {
|
} else {
|
||||||
debounce.unregister(checkAllStyles);
|
chrome.alarms.clear(ALARM_NAME, ignoreChromeError);
|
||||||
|
chrome.alarms.onAlarm.removeListener(onAlarm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onAlarm({name}) {
|
||||||
|
if (name === ALARM_NAME) checkAllStyles();
|
||||||
|
}
|
||||||
|
|
||||||
function resetInterval() {
|
function resetInterval() {
|
||||||
localStorage.lastUpdateTime = lastUpdateTime = Date.now();
|
localStorage.lastUpdateTime = lastUpdateTime = Date.now();
|
||||||
schedule();
|
schedule();
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
"webNavigation",
|
"webNavigation",
|
||||||
"contextMenus",
|
"contextMenus",
|
||||||
"storage",
|
"storage",
|
||||||
|
"alarms",
|
||||||
"<all_urls>"
|
"<all_urls>"
|
||||||
],
|
],
|
||||||
"background": {
|
"background": {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user