Change how options updates are handled on the frontend

Only an 'optionsUpdate' signal is now sent to the frontend with empty data. The frontend then responds by performing apiOptionsGet to update the options. This makes it so that there is only a single function which is responsible for requesting options from the backend.
This commit is contained in:
toasted-nutbread 2019-09-07 11:21:06 -04:00
parent cc53510883
commit 91bc31d758
2 changed files with 10 additions and 6 deletions

View File

@ -59,7 +59,7 @@ class Backend {
const callback = () => this.checkLastError(chrome.runtime.lastError);
chrome.tabs.query({}, tabs => {
for (const tab of tabs) {
chrome.tabs.sendMessage(tab.id, {action: 'optionsSet', params: {options}}, callback);
chrome.tabs.sendMessage(tab.id, {action: 'optionsUpdate', params: {}}, callback);
}
});
}

View File

@ -261,11 +261,8 @@ class Frontend {
onBgMessage({action, params}, sender, callback) {
const handlers = {
optionsSet: ({options}) => {
this.options = options;
if (!this.options.enable) {
this.searchClear();
}
optionsUpdate: () => {
this.updateOptions();
},
popupSetVisible: ({visible}) => {
@ -284,6 +281,13 @@ class Frontend {
console.log(error);
}
async updateOptions() {
this.options = await apiOptionsGet();
if (!this.options.enable) {
this.searchClear();
}
}
popupTimerSet(callback) {
this.popupTimerClear();
this.popupTimer = window.setTimeout(callback, this.options.scanning.delay);