Dictionary delete improvements (#844)
* Change where clearDatabaseCaches occurs * Move dictionary deletion into the settings page * Remove api.deleteDictionary
This commit is contained in:
parent
1078ab99b7
commit
a2e6de84af
@ -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});
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user