aboutsummaryrefslogtreecommitdiff
path: root/ext/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js')
-rw-r--r--ext/js/background/backend.js5
-rw-r--r--ext/js/comm/api.js4
-rw-r--r--ext/js/language/dictionary-worker-handler.js12
-rw-r--r--ext/js/language/dictionary-worker.js4
-rw-r--r--ext/js/pages/settings/dictionary-controller.js2
5 files changed, 17 insertions, 10 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index e293a3a7..dea67091 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -111,7 +111,6 @@ class Backend {
['getZoom', {async: true, contentScript: true, handler: this._onApiGetZoom.bind(this)}],
['getDefaultAnkiFieldTemplates', {async: false, contentScript: true, handler: this._onApiGetDefaultAnkiFieldTemplates.bind(this)}],
['getDictionaryInfo', {async: true, contentScript: true, handler: this._onApiGetDictionaryInfo.bind(this)}],
- ['getDictionaryCounts', {async: true, contentScript: false, handler: this._onApiGetDictionaryCounts.bind(this)}],
['purgeDatabase', {async: true, contentScript: false, handler: this._onApiPurgeDatabase.bind(this)}],
['getMedia', {async: true, contentScript: true, handler: this._onApiGetMedia.bind(this)}],
['log', {async: false, contentScript: true, handler: this._onApiLog.bind(this)}],
@@ -616,10 +615,6 @@ class Backend {
return await this._dictionaryDatabase.getDictionaryInfo();
}
- async _onApiGetDictionaryCounts({dictionaryNames, getTotal}) {
- return await this._dictionaryDatabase.getDictionaryCounts(dictionaryNames, getTotal);
- }
-
async _onApiPurgeDatabase() {
await this._dictionaryDatabase.purge();
this._triggerDatabaseUpdated('dictionary', 'purge');
diff --git a/ext/js/comm/api.js b/ext/js/comm/api.js
index 3ac1d3f7..3fa7c92b 100644
--- a/ext/js/comm/api.js
+++ b/ext/js/comm/api.js
@@ -120,10 +120,6 @@ class API {
return this._invoke('getDictionaryInfo');
}
- getDictionaryCounts(dictionaryNames, getTotal) {
- return this._invoke('getDictionaryCounts', {dictionaryNames, getTotal});
- }
-
purgeDatabase() {
return this._invoke('purgeDatabase');
}
diff --git a/ext/js/language/dictionary-worker-handler.js b/ext/js/language/dictionary-worker-handler.js
index 88150f50..1d6b4aab 100644
--- a/ext/js/language/dictionary-worker-handler.js
+++ b/ext/js/language/dictionary-worker-handler.js
@@ -41,6 +41,9 @@ class DictionaryWorkerHandler {
case 'deleteDictionary':
this._onMessageWithProgress(params, this._deleteDictionary.bind(this));
break;
+ case 'getDictionaryCounts':
+ this._onMessageWithProgress(params, this._getDictionaryCounts.bind(this));
+ break;
case 'getImageResolution.response':
this._mediaLoader.handleMessage(params);
break;
@@ -87,6 +90,15 @@ class DictionaryWorkerHandler {
}
}
+ async _getDictionaryCounts({dictionaryNames, getTotal}) {
+ const dictionaryDatabase = await this._getPreparedDictionaryDatabase();
+ try {
+ return await dictionaryDatabase.getDictionaryCounts(dictionaryNames, getTotal);
+ } finally {
+ dictionaryDatabase.close();
+ }
+ }
+
async _getPreparedDictionaryDatabase() {
const dictionaryDatabase = new DictionaryDatabase();
await dictionaryDatabase.prepare();
diff --git a/ext/js/language/dictionary-worker.js b/ext/js/language/dictionary-worker.js
index 4adfdaec..92faa3dc 100644
--- a/ext/js/language/dictionary-worker.js
+++ b/ext/js/language/dictionary-worker.js
@@ -38,6 +38,10 @@ class DictionaryWorker {
return this._invoke('deleteDictionary', {dictionaryTitle}, [], onProgress);
}
+ getDictionaryCounts(dictionaryNames, getTotal) {
+ return this._invoke('getDictionaryCounts', {dictionaryNames, getTotal}, [], null);
+ }
+
// Private
_invoke(action, params, transfer, onProgress, formatResult) {
diff --git a/ext/js/pages/settings/dictionary-controller.js b/ext/js/pages/settings/dictionary-controller.js
index 2a44f9ad..21bf7d5f 100644
--- a/ext/js/pages/settings/dictionary-controller.js
+++ b/ext/js/pages/settings/dictionary-controller.js
@@ -567,7 +567,7 @@ class DictionaryController {
const token = this._databaseStateToken;
const dictionaryTitles = this._dictionaryEntries.map(({dictionaryTitle}) => dictionaryTitle);
- const {counts, total} = await yomichan.api.getDictionaryCounts(dictionaryTitles, true);
+ const {counts, total} = await new DictionaryWorker().getDictionaryCounts(dictionaryTitles, true);
if (this._databaseStateToken !== token) { return; }
for (let i = 0, ii = Math.min(counts.length, this._dictionaryEntries.length); i < ii; ++i) {