aboutsummaryrefslogtreecommitdiff
path: root/ext/js/language/dictionary-worker.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/language/dictionary-worker.js')
-rw-r--r--ext/js/language/dictionary-worker.js22
1 files changed, 17 insertions, 5 deletions
diff --git a/ext/js/language/dictionary-worker.js b/ext/js/language/dictionary-worker.js
index 5c482178..dc546657 100644
--- a/ext/js/language/dictionary-worker.js
+++ b/ext/js/language/dictionary-worker.js
@@ -36,7 +36,10 @@ class DictionaryWorker {
const {action, params} = e.data;
switch (action) {
case 'importDictionary':
- this._onImportDictionary(params);
+ this._onMessageWithProgress(params, this._importDictionary.bind(this));
+ break;
+ case 'deleteDictionary':
+ this._onMessageWithProgress(params, this._deleteDictionary.bind(this));
break;
case 'getImageResolution.response':
this._mediaLoader.handleMessage(params);
@@ -44,7 +47,7 @@ class DictionaryWorker {
}
}
- async _onImportDictionary({details, archiveContent}) {
+ async _onMessageWithProgress(params, handler) {
const onProgress = (...args) => {
self.postMessage({
action: 'progress',
@@ -53,7 +56,7 @@ class DictionaryWorker {
};
let response;
try {
- const result = await this._importDictionary(archiveContent, details, onProgress);
+ const result = await handler(params, onProgress);
response = {result};
} catch (e) {
response = {error: serializeError(e)};
@@ -61,11 +64,11 @@ class DictionaryWorker {
self.postMessage({action: 'complete', params: response});
}
- async _importDictionary(archiveContent, importDetails, onProgress) {
+ async _importDictionary({details, archiveContent}, onProgress) {
const dictionaryDatabase = await this._getPreparedDictionaryDatabase();
try {
const dictionaryImporter = new DictionaryImporter(this._mediaLoader, onProgress);
- const {result, errors} = await dictionaryImporter.importDictionary(dictionaryDatabase, archiveContent, importDetails);
+ const {result, errors} = await dictionaryImporter.importDictionary(dictionaryDatabase, archiveContent, details);
return {
result,
errors: errors.map((error) => serializeError(error))
@@ -75,6 +78,15 @@ class DictionaryWorker {
}
}
+ async _deleteDictionary({dictionaryTitle}, onProgress) {
+ const dictionaryDatabase = await this._getPreparedDictionaryDatabase();
+ try {
+ return await dictionaryDatabase.deleteDictionary(dictionaryTitle, {rate: 1000}, onProgress);
+ } finally {
+ dictionaryDatabase.close();
+ }
+ }
+
async _getPreparedDictionaryDatabase() {
const dictionaryDatabase = new DictionaryDatabase();
await dictionaryDatabase.prepare();