Use apiOptionsSave instead of optionsSave
This commit is contained in:
parent
4686a31a0a
commit
05ce350792
@ -21,6 +21,13 @@ function apiOptionsGet(optionsContext) {
|
||||
return utilBackend().getOptions(optionsContext);
|
||||
}
|
||||
|
||||
async function apiOptionsSave() {
|
||||
const backend = utilBackend();
|
||||
const options = await backend.getFullOptions();
|
||||
await optionsSave(options);
|
||||
backend.onOptionsUpdated(options);
|
||||
}
|
||||
|
||||
async function apiTermsFind(text, optionsContext) {
|
||||
const options = await apiOptionsGet(optionsContext);
|
||||
const translator = utilBackend().translator;
|
||||
@ -132,7 +139,7 @@ async function apiCommandExec(command) {
|
||||
const optionsContext = {depth: 0};
|
||||
const options = await apiOptionsGet(optionsContext);
|
||||
options.general.enable = !options.general.enable;
|
||||
await optionsSave(options);
|
||||
await apiOptionsSave();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -150,6 +150,13 @@ class Backend {
|
||||
this.anki = options.anki.enable ? new AnkiConnect(options.anki.server) : new AnkiNull();
|
||||
}
|
||||
|
||||
async getFullOptions() {
|
||||
if (this.isPreparedPromise !== null) {
|
||||
await this.isPreparedPromise;
|
||||
}
|
||||
return this.options;
|
||||
}
|
||||
|
||||
async getOptions(optionsContext) {
|
||||
if (this.isPreparedPromise !== null) {
|
||||
await this.isPreparedPromise;
|
||||
|
@ -343,9 +343,14 @@ function optionsLoad() {
|
||||
}
|
||||
|
||||
function optionsSave(options) {
|
||||
return new Promise((resolve) => {
|
||||
chrome.storage.local.set({options: JSON.stringify(options)}, resolve);
|
||||
}).then(() => {
|
||||
utilBackend().onOptionsUpdated(options);
|
||||
return new Promise((resolve, reject) => {
|
||||
chrome.storage.local.set({options: JSON.stringify(options)}, () => {
|
||||
const error = chrome.runtime.lastError;
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ async function onFormOptionsChanged(e) {
|
||||
const optionsAnkiServerOld = options.anki.server;
|
||||
|
||||
await formRead(options);
|
||||
await optionsSave(options);
|
||||
await apiOptionsSave();
|
||||
formUpdateVisibility(options);
|
||||
|
||||
try {
|
||||
@ -385,7 +385,7 @@ async function onDictionaryPurge(e) {
|
||||
const options = await apiOptionsGet(optionsContext);
|
||||
options.dictionaries = {};
|
||||
options.general.mainDictionary = '';
|
||||
await optionsSave(options);
|
||||
await apiOptionsSave();
|
||||
|
||||
await dictionaryGroupsPopulate(options);
|
||||
await formMainDictionaryOptionsPopulate(options);
|
||||
@ -435,7 +435,7 @@ async function onDictionaryImport(e) {
|
||||
dictionaryErrorsShow(exceptions);
|
||||
}
|
||||
|
||||
await optionsSave(options);
|
||||
await apiOptionsSave();
|
||||
|
||||
await dictionaryGroupsPopulate(options);
|
||||
await formMainDictionaryOptionsPopulate(options);
|
||||
@ -579,7 +579,7 @@ async function onAnkiModelChanged(e) {
|
||||
const options = await apiOptionsGet(optionsContext);
|
||||
await formRead(options);
|
||||
options.anki[tabId].fields = {};
|
||||
await optionsSave(options);
|
||||
await apiOptionsSave();
|
||||
|
||||
ankiSpinnerShow(true);
|
||||
await ankiFieldsPopulate(element, options);
|
||||
@ -599,7 +599,7 @@ async function onAnkiFieldTemplatesReset(e) {
|
||||
const fieldTemplates = optionsFieldTemplates();
|
||||
options.anki.fieldTemplates = fieldTemplates;
|
||||
$('#field-templates').val(fieldTemplates);
|
||||
await optionsSave(options);
|
||||
await apiOptionsSave();
|
||||
} catch (e) {
|
||||
ankiErrorShow(e);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user