mirror of
https://github.com/Ximi1970/systray-x.git
synced 2026-01-18 05:02:05 +01:00
use new poll timing
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
var SysTrayX = {
|
||||
debugAccounts: false,
|
||||
|
||||
pollTiming: {
|
||||
pollStartupDelay: "5",
|
||||
pollInterval: "5"
|
||||
},
|
||||
|
||||
platformInfo: undefined
|
||||
};
|
||||
|
||||
@@ -13,6 +18,8 @@ SysTrayX.Messaging = {
|
||||
init: function() {
|
||||
// Get the accounts from the storage
|
||||
SysTrayX.Messaging.getAccounts();
|
||||
|
||||
// Lookout for storage changes
|
||||
browser.storage.onChanged.addListener(SysTrayX.Messaging.storageChanged);
|
||||
|
||||
// Send the window title to app
|
||||
@@ -22,7 +29,11 @@ SysTrayX.Messaging = {
|
||||
SysTrayX.Messaging.sendPreferences();
|
||||
|
||||
// this.unReadMessages(this.unreadFiltersTest).then(this.unreadCb);
|
||||
window.setInterval(SysTrayX.Messaging.pollAccounts, 1000);
|
||||
// window.setInterval(SysTrayX.Messaging.pollAccounts, 1000);
|
||||
window.setTimeout(
|
||||
SysTrayX.Messaging.pollAccounts,
|
||||
SysTrayX.pollTiming.pollStartupDelay * 1000
|
||||
);
|
||||
|
||||
// Try to catch the window state
|
||||
browser.windows.onFocusChanged.addListener(SysTrayX.Window.focusChanged);
|
||||
@@ -35,6 +46,20 @@ SysTrayX.Messaging = {
|
||||
// Get the new preferences
|
||||
SysTrayX.Messaging.getAccounts();
|
||||
|
||||
if ("pollStartupDelay" in changes && changes["pollStartupDelay"].newValue) {
|
||||
SysTrayX.pollTiming = {
|
||||
...SysTrayX.pollTiming,
|
||||
pollStartupDelay: changes["pollStartupDelay"].newValue
|
||||
};
|
||||
}
|
||||
|
||||
if ("pollInterval" in changes && changes["pollInterval"].newValue) {
|
||||
SysTrayX.pollTiming = {
|
||||
...SysTrayX.pollTiming,
|
||||
pollInterval: changes["pollInterval"].newValue
|
||||
};
|
||||
}
|
||||
|
||||
if ("addonprefchanged" in changes && changes["addonprefchanged"].newValue) {
|
||||
//
|
||||
// Send new preferences to the app
|
||||
@@ -73,6 +98,12 @@ SysTrayX.Messaging = {
|
||||
SysTrayX.Messaging.unreadCb
|
||||
);
|
||||
}
|
||||
|
||||
// Next round...
|
||||
window.setTimeout(
|
||||
SysTrayX.Messaging.pollAccounts,
|
||||
SysTrayX.pollTiming.pollInterval * 1000
|
||||
);
|
||||
},
|
||||
|
||||
//
|
||||
@@ -315,6 +346,9 @@ async function start() {
|
||||
});
|
||||
}
|
||||
|
||||
// Get the poll timing
|
||||
SysTrayX.pollTiming = await getPollTiming();
|
||||
|
||||
// Set platform
|
||||
SysTrayX.platformInfo = await browser.runtime
|
||||
.getPlatformInfo()
|
||||
|
||||
@@ -67,3 +67,21 @@ async function getStartupState() {
|
||||
const getState = browser.storage.sync.get("startMinimized");
|
||||
return await getState.then(getStartupState, onStartupStateError);
|
||||
}
|
||||
|
||||
//
|
||||
// Get poll timing
|
||||
//
|
||||
async function getPollTiming() {
|
||||
function getDelayAndInterval(result) {
|
||||
return { pollStartupDelay: result.pollStartupDelay || "5", pollInterval: result.pollInterval || "5" };
|
||||
}
|
||||
|
||||
function onDelayAndIntervalError() {
|
||||
return { pollStartupDelay: "5", pollInterval: "5" };
|
||||
}
|
||||
|
||||
const getTiming = browser.storage.sync.get([
|
||||
"pollStartupDelay",
|
||||
"pollInterval"]);
|
||||
return await getTiming.then(getDelayAndInterval, onDelayAndIntervalError);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user