summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-09-19 17:17:33 -0400
committerGitHub <noreply@github.com>2020-09-19 17:17:33 -0400
commita2e6de84af6a304cf586759fe8a0d50d4d94785e (patch)
treebac23d15f0f048510b1cd67cd0331f4ffde15456 /ext
parent1078ab99b7a9d082ee36cbed69c8cb154db318b6 (diff)
Dictionary delete improvements (#844)
* Change where clearDatabaseCaches occurs * Move dictionary deletion into the settings page * Remove api.deleteDictionary
Diffstat (limited to 'ext')
-rw-r--r--ext/bg/js/backend.js9
-rw-r--r--ext/bg/js/settings/dictionary-controller.js19
-rw-r--r--ext/mixed/js/api.js6
3 files changed, 19 insertions, 15 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 54982098..f656adbd 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -118,7 +118,6 @@ class Backend {
['triggerDatabaseUpdated', {async: false, contentScript: true, handler: this._onApiTriggerDatabaseUpdated.bind(this)}]
]);
this._messageHandlersWithProgress = new Map([
- ['deleteDictionary', {async: true, contentScript: false, handler: this._onApiDeleteDictionary.bind(this)}]
]);
this._commandHandlers = new Map([
@@ -700,7 +699,6 @@ class Backend {
}
async _onApiPurgeDatabase() {
- this._translator.clearDatabaseCaches();
await this._dictionaryDatabase.purge();
this._triggerDatabaseUpdated('dictionary', 'purge');
}
@@ -742,12 +740,6 @@ class Backend {
return details;
}
- async _onApiDeleteDictionary({dictionaryName}, sender, onProgress) {
- this._translator.clearDatabaseCaches();
- await this._dictionaryDatabase.deleteDictionary(dictionaryName, {rate: 1000}, onProgress);
- this._triggerDatabaseUpdated('dictionary', 'delete');
- }
-
async _onApiModifySettings({targets, source}) {
const results = [];
for (const target of targets) {
@@ -1721,6 +1713,7 @@ class Backend {
}
_triggerDatabaseUpdated(type, cause) {
+ this._translator.clearDatabaseCaches();
this._sendMessageAllTabs('databaseUpdated', {type, cause});
}
diff --git a/ext/bg/js/settings/dictionary-controller.js b/ext/bg/js/settings/dictionary-controller.js
index afc198e2..e5a07f9d 100644
--- a/ext/bg/js/settings/dictionary-controller.js
+++ b/ext/bg/js/settings/dictionary-controller.js
@@ -16,6 +16,7 @@
*/
/* global
+ * DictionaryDatabase
* Modal
* ObjectPropertyAccessor
* api
@@ -349,7 +350,7 @@ class DictionaryController {
progressBar.style.width = `${percent}%`;
};
- await api.deleteDictionary(dictionaryTitle, onProgress);
+ await this._deleteDictionaryInternal(dictionaryTitle, onProgress);
} catch (e) {
yomichan.logError(e);
} finally {
@@ -372,4 +373,20 @@ class DictionaryController {
const content = document.importNode(template.content, true);
return content.firstChild;
}
+
+ async _deleteDictionaryInternal(dictionaryTitle, onProgress) {
+ const dictionaryDatabase = await this._getPreparedDictionaryDatabase();
+ try {
+ await dictionaryDatabase.deleteDictionary(dictionaryTitle, {rate: 1000}, onProgress);
+ api.triggerDatabaseUpdated('dictionary', 'delete');
+ } finally {
+ dictionaryDatabase.close();
+ }
+ }
+
+ async _getPreparedDictionaryDatabase() {
+ const dictionaryDatabase = new DictionaryDatabase();
+ await dictionaryDatabase.prepare();
+ return dictionaryDatabase;
+ }
}
diff --git a/ext/mixed/js/api.js b/ext/mixed/js/api.js
index ca4d5732..1973ca22 100644
--- a/ext/mixed/js/api.js
+++ b/ext/mixed/js/api.js
@@ -197,12 +197,6 @@ const api = (() => {
return this._invoke('triggerDatabaseUpdated', {type, cause});
}
- // Invoke functions with progress
-
- deleteDictionary(dictionaryName, onProgress) {
- return this._invokeWithProgress('deleteDictionary', {dictionaryName}, onProgress);
- }
-
// Utilities
_createActionPort(timeout=5000) {