aboutsummaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-07 13:58:19 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-10 20:09:33 -0400
commitbc8793eb56b2ce985f2e5dc0a9fd270f98fbf17a (patch)
treeb390bf63356b1584ea6d9bb5ff98450d96fb0e04 /ext/bg
parent99ca60d4c1456f243d8142b4502db441e33340a4 (diff)
Add a context object for all calls to fetch options
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/api.js26
-rw-r--r--ext/bg/js/backend.js20
-rw-r--r--ext/bg/js/search-frontend.js3
-rw-r--r--ext/bg/js/search.js8
4 files changed, 32 insertions, 25 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js
index b56b3449..0b80f099 100644
--- a/ext/bg/js/api.js
+++ b/ext/bg/js/api.js
@@ -17,16 +17,16 @@
*/
-function apiOptionsGetSync() {
+function apiOptionsGetSync(optionsContext) {
return utilBackend().options;
}
-async function apiOptionsGet() {
- return apiOptionsGetSync();
+async function apiOptionsGet(optionsContext) {
+ return apiOptionsGetSync(optionsContext);
}
-async function apiTermsFind(text) {
- const options = apiOptionsGetSync();
+async function apiTermsFind(text, optionsContext) {
+ const options = apiOptionsGetSync(optionsContext);
const translator = utilBackend().translator;
const searcher = {
@@ -48,14 +48,14 @@ async function apiTermsFind(text) {
};
}
-async function apiKanjiFind(text) {
- const options = apiOptionsGetSync();
+async function apiKanjiFind(text, optionsContext) {
+ const options = apiOptionsGetSync(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 = apiOptionsGetSync(optionsContext);
if (mode !== 'kanji') {
await audioInject(
@@ -77,14 +77,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 = apiOptionsGetSync(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);
}
}
@@ -132,7 +133,8 @@ async function apiCommandExec(command) {
},
toggle: async () => {
- const options = apiOptionsGetSync();
+ const optionsContext = {depth: 0};
+ const options = apiOptionsGetSync(optionsContext);
options.general.enable = !options.general.enable;
await optionsSave(options);
}
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 0394c4ec..6afa9617 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -78,24 +78,24 @@ class Backend {
};
const handlers = {
- optionsGet: ({callback}) => {
- forward(apiOptionsGet(), callback);
+ optionsGet: ({optionsContext, callback}) => {
+ forward(apiOptionsGet(optionsContext), callback);
},
- kanjiFind: ({text, callback}) => {
- forward(apiKanjiFind(text), callback);
+ kanjiFind: ({text, optionsContext, callback}) => {
+ forward(apiKanjiFind(text, optionsContext), callback);
},
- termsFind: ({text, callback}) => {
- forward(apiTermsFind(text), callback);
+ termsFind: ({text, optionsContext, callback}) => {
+ forward(apiTermsFind(text, optionsContext), callback);
},
- definitionAdd: ({definition, mode, context, callback}) => {
- forward(apiDefinitionAdd(definition, mode, context), callback);
+ definitionAdd: ({definition, mode, context, optionsContext, callback}) => {
+ forward(apiDefinitionAdd(definition, mode, context, optionsContext), callback);
},
- definitionsAddable: ({definitions, modes, callback}) => {
- forward(apiDefinitionsAddable(definitions, modes), callback);
+ definitionsAddable: ({definitions, modes, optionsContext, callback}) => {
+ forward(apiDefinitionsAddable(definitions, modes, optionsContext), callback);
},
noteView: ({noteId}) => {
diff --git a/ext/bg/js/search-frontend.js b/ext/bg/js/search-frontend.js
index 840a1ea8..df5ccf81 100644
--- a/ext/bg/js/search-frontend.js
+++ b/ext/bg/js/search-frontend.js
@@ -18,7 +18,8 @@
async function searchFrontendSetup() {
- const options = await apiOptionsGet();
+ const optionsContext = {depth: 0};
+ const options = await apiOptionsGet(optionsContext);
if (!options.scanning.enableOnSearchPage) { return; }
const scriptSrcs = [
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js
index a3382398..6bdc47d8 100644
--- a/ext/bg/js/search.js
+++ b/ext/bg/js/search.js
@@ -21,6 +21,10 @@ class DisplaySearch extends Display {
constructor() {
super($('#spinner'), $('#content'));
+ this.optionsContext = {
+ depth: 0
+ };
+
this.search = $('#search').click(this.onSearch.bind(this));
this.query = $('#query').on('input', this.onSearchInput.bind(this));
this.intro = $('#intro');
@@ -46,8 +50,8 @@ class DisplaySearch extends Display {
try {
e.preventDefault();
this.intro.slideUp();
- const {length, definitions} = await apiTermsFind(this.query.val());
- super.termsShow(definitions, await apiOptionsGet());
+ const {length, definitions} = await apiTermsFind(this.query.val(), this.optionsContext);
+ super.termsShow(definitions, await apiOptionsGet(this.optionsContext));
} catch (e) {
this.onError(e);
}