diff options
author | Alex Yatskov <FooSoft@users.noreply.github.com> | 2019-09-12 19:47:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-12 19:47:37 -0700 |
commit | 1fea1184bd66ed250f8bed8218c08498a7ea81c0 (patch) | |
tree | 8374573a36784ce12abb7b490ccd9791aea3f2e3 /ext/bg/js/api.js | |
parent | cc53510883b5c5f75069655df6a6733ff1bd002a (diff) | |
parent | 84bd9ff93b15f419ce1076b7545aeb406917f9b5 (diff) |
Merge pull request #205 from toasted-nutbread/settings-improvements2
Settings improvements part 2
Diffstat (limited to 'ext/bg/js/api.js')
-rw-r--r-- | ext/bg/js/api.js | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js index 9839aef5..81772d08 100644 --- a/ext/bg/js/api.js +++ b/ext/bg/js/api.js @@ -17,16 +17,19 @@ */ -function apiOptionsGetSync() { - return utilBackend().options; +function apiOptionsGet(optionsContext) { + return utilBackend().getOptions(optionsContext); } -async function apiOptionsGet() { - return apiOptionsGetSync(); +async function apiOptionsSave(source) { + const backend = utilBackend(); + const options = await backend.getFullOptions(); + await optionsSave(options); + backend.onOptionsUpdated(source); } -async function apiTermsFind(text) { - const options = apiOptionsGetSync(); +async function apiTermsFind(text, optionsContext) { + const options = await apiOptionsGet(optionsContext); const translator = utilBackend().translator; const searcher = { @@ -38,7 +41,8 @@ async function apiTermsFind(text) { const {definitions, length} = await searcher( text, dictEnabledSet(options), - options.scanning.alphanumeric + options.scanning.alphanumeric, + options ); return { @@ -47,14 +51,14 @@ async function apiTermsFind(text) { }; } -async function apiKanjiFind(text) { - const options = apiOptionsGetSync(); +async function apiKanjiFind(text, optionsContext) { + const options = await apiOptionsGet(optionsContext); const definitions = await utilBackend().translator.findKanji(text, dictEnabledSet(options)); return definitions.slice(0, options.general.maxResults); } -async function apiDefinitionAdd(definition, mode, context) { - const options = apiOptionsGetSync(); +async function apiDefinitionAdd(definition, mode, context, optionsContext) { + const options = await apiOptionsGet(optionsContext); if (mode !== 'kanji') { await audioInject( @@ -76,14 +80,15 @@ async function apiDefinitionAdd(definition, mode, context) { return utilBackend().anki.addNote(note); } -async function apiDefinitionsAddable(definitions, modes) { +async function apiDefinitionsAddable(definitions, modes, optionsContext) { + const options = await apiOptionsGet(optionsContext); const states = []; try { const notes = []; for (const definition of definitions) { for (const mode of modes) { - const note = await dictNoteFormat(definition, mode, apiOptionsGetSync()); + const note = await dictNoteFormat(definition, mode, options); notes.push(note); } } @@ -131,9 +136,10 @@ async function apiCommandExec(command) { }, toggle: async () => { - const options = apiOptionsGetSync(); + const optionsContext = {depth: 0}; + const options = await apiOptionsGet(optionsContext); options.general.enable = !options.general.enable; - await optionsSave(options); + await apiOptionsSave('popup'); } }; |