From 1a91935dd75c59951369cdb7f48950124ad9bdee Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 6 Oct 2020 23:00:00 -0400 Subject: Fix dictionary settings not being deleted when deleting a single dictionary (#893) --- ext/bg/js/settings/dictionary-controller.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'ext/bg') diff --git a/ext/bg/js/settings/dictionary-controller.js b/ext/bg/js/settings/dictionary-controller.js index e5a07f9d..7a71a02a 100644 --- a/ext/bg/js/settings/dictionary-controller.js +++ b/ext/bg/js/settings/dictionary-controller.js @@ -351,6 +351,7 @@ class DictionaryController { }; await this._deleteDictionaryInternal(dictionaryTitle, onProgress); + await this._deleteDictionarySettings(dictionaryTitle); } catch (e) { yomichan.logError(e); } finally { @@ -389,4 +390,18 @@ class DictionaryController { await dictionaryDatabase.prepare(); return dictionaryDatabase; } + + async _deleteDictionarySettings(dictionaryTitle) { + const optionsFull = await this._settingsController.getOptionsFull(); + const {profiles} = optionsFull; + const targets = []; + for (let i = 0, ii = profiles.length; i < ii; ++i) { + const {options: {dictionaries}} = profiles[i]; + if (Object.prototype.hasOwnProperty.call(dictionaries, dictionaryTitle)) { + const path = ObjectPropertyAccessor.getPathString(['profiles', i, 'options', 'dictionaries', dictionaryTitle]); + targets.push({action: 'delete', path}); + } + } + await this._settingsController.modifyGlobalSettings(targets); + } } -- cgit v1.2.3