Skip to content

Commit

Permalink
use new poll timing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ximi1970 committed Apr 3, 2020
1 parent 7d43255 commit bfcd30e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
36 changes: 35 additions & 1 deletion webext/background.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
var SysTrayX = {
debugAccounts: false,

pollTiming: {
pollStartupDelay: "5",
pollInterval: "5"
},

platformInfo: undefined
};

Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -73,6 +98,12 @@ SysTrayX.Messaging = {
SysTrayX.Messaging.unreadCb
);
}

// Next round...
window.setTimeout(
SysTrayX.Messaging.pollAccounts,
SysTrayX.pollTiming.pollInterval * 1000
);
},

//
Expand Down Expand Up @@ -315,6 +346,9 @@ async function start() {
});
}

// Get the poll timing
SysTrayX.pollTiming = await getPollTiming();

// Set platform
SysTrayX.platformInfo = await browser.runtime
.getPlatformInfo()
Expand Down
18 changes: 18 additions & 0 deletions webext/js/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit bfcd30e

Please sign in to comment.