Remove calls to apiOptionsGetSync
Use apiOptionsGet everywhere to ensure options is initialized.
This commit is contained in:
parent
1b2a1e50eb
commit
8175f80183
@ -17,16 +17,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
function apiOptionsGetSync(optionsContext) {
|
function apiOptionsGet(optionsContext) {
|
||||||
return utilBackend().getOptions(optionsContext);
|
return utilBackend().getOptions(optionsContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function apiOptionsGet(optionsContext) {
|
|
||||||
return apiOptionsGetSync(optionsContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function apiTermsFind(text, optionsContext) {
|
async function apiTermsFind(text, optionsContext) {
|
||||||
const options = apiOptionsGetSync(optionsContext);
|
const options = await apiOptionsGet(optionsContext);
|
||||||
const translator = utilBackend().translator;
|
const translator = utilBackend().translator;
|
||||||
|
|
||||||
const searcher = {
|
const searcher = {
|
||||||
@ -49,13 +45,13 @@ async function apiTermsFind(text, optionsContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function apiKanjiFind(text, optionsContext) {
|
async function apiKanjiFind(text, optionsContext) {
|
||||||
const options = apiOptionsGetSync(optionsContext);
|
const options = await apiOptionsGet(optionsContext);
|
||||||
const definitions = await utilBackend().translator.findKanji(text, dictEnabledSet(options));
|
const definitions = await utilBackend().translator.findKanji(text, dictEnabledSet(options));
|
||||||
return definitions.slice(0, options.general.maxResults);
|
return definitions.slice(0, options.general.maxResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function apiDefinitionAdd(definition, mode, context, optionsContext) {
|
async function apiDefinitionAdd(definition, mode, context, optionsContext) {
|
||||||
const options = apiOptionsGetSync(optionsContext);
|
const options = await apiOptionsGet(optionsContext);
|
||||||
|
|
||||||
if (mode !== 'kanji') {
|
if (mode !== 'kanji') {
|
||||||
await audioInject(
|
await audioInject(
|
||||||
@ -78,7 +74,7 @@ async function apiDefinitionAdd(definition, mode, context, optionsContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function apiDefinitionsAddable(definitions, modes, optionsContext) {
|
async function apiDefinitionsAddable(definitions, modes, optionsContext) {
|
||||||
const options = apiOptionsGetSync(optionsContext);
|
const options = await apiOptionsGet(optionsContext);
|
||||||
const states = [];
|
const states = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -134,7 +130,7 @@ async function apiCommandExec(command) {
|
|||||||
|
|
||||||
toggle: async () => {
|
toggle: async () => {
|
||||||
const optionsContext = {depth: 0};
|
const optionsContext = {depth: 0};
|
||||||
const options = apiOptionsGetSync(optionsContext);
|
const options = await apiOptionsGet(optionsContext);
|
||||||
options.general.enable = !options.general.enable;
|
options.general.enable = !options.general.enable;
|
||||||
await optionsSave(options);
|
await optionsSave(options);
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,9 @@ class Backend {
|
|||||||
depth: 0
|
depth: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.isPreparedResolve = null;
|
||||||
|
this.isPreparedPromise = new Promise((resolve) => (this.isPreparedResolve = resolve));
|
||||||
|
|
||||||
this.apiForwarder = new BackendApiForwarder();
|
this.apiForwarder = new BackendApiForwarder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,10 +41,14 @@ class Backend {
|
|||||||
}
|
}
|
||||||
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
|
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
|
||||||
|
|
||||||
const options = this.getOptions(this.optionsContext);
|
const options = this.getOptionsSync(this.optionsContext);
|
||||||
if (options.general.showGuide) {
|
if (options.general.showGuide) {
|
||||||
chrome.tabs.create({url: chrome.extension.getURL('/bg/guide.html')});
|
chrome.tabs.create({url: chrome.extension.getURL('/bg/guide.html')});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.isPreparedResolve();
|
||||||
|
this.isPreparedResolve = null;
|
||||||
|
this.isPreparedPromise = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
onOptionsUpdated(options) {
|
onOptionsUpdated(options) {
|
||||||
@ -129,7 +136,7 @@ class Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
applyOptions() {
|
applyOptions() {
|
||||||
const options = this.getOptions(this.optionsContext);
|
const options = this.getOptionsSync(this.optionsContext);
|
||||||
if (!options.general.enable) {
|
if (!options.general.enable) {
|
||||||
this.setExtensionBadgeBackgroundColor('#555555');
|
this.setExtensionBadgeBackgroundColor('#555555');
|
||||||
this.setExtensionBadgeText('off');
|
this.setExtensionBadgeText('off');
|
||||||
@ -143,7 +150,14 @@ class Backend {
|
|||||||
this.anki = options.anki.enable ? new AnkiConnect(options.anki.server) : new AnkiNull();
|
this.anki = options.anki.enable ? new AnkiConnect(options.anki.server) : new AnkiNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
getOptions(optionsContext) {
|
async getOptions(optionsContext) {
|
||||||
|
if (this.isPreparedPromise !== null) {
|
||||||
|
await this.isPreparedPromise;
|
||||||
|
}
|
||||||
|
return this.getOptionsSync(optionsContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
getOptionsSync(optionsContext) {
|
||||||
return this.options;
|
return this.options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user