From a2e6de84af6a304cf586759fe8a0d50d4d94785e Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 19 Sep 2020 17:17:33 -0400 Subject: Dictionary delete improvements (#844) * Change where clearDatabaseCaches occurs * Move dictionary deletion into the settings page * Remove api.deleteDictionary --- ext/bg/js/settings/dictionary-controller.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'ext/bg/js/settings') 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; + } } -- cgit v1.2.3