From 977febababc7d4c078f97735dab0480fdac0a53f Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 14 Oct 2020 19:38:50 -0400 Subject: Ensure settings exist for all installed dictionaries (#922) --- ext/bg/js/settings/dictionary-controller.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/ext/bg/js/settings/dictionary-controller.js b/ext/bg/js/settings/dictionary-controller.js index 7a71a02a..474f2e92 100644 --- a/ext/bg/js/settings/dictionary-controller.js +++ b/ext/bg/js/settings/dictionary-controller.js @@ -202,6 +202,7 @@ class DictionaryController { } this._dictionaryEntries = []; + await this._ensureDictionarySettings(dictionaries); for (const dictionary of dictionaries) { this._createDictionaryEntry(dictionary); } @@ -404,4 +405,32 @@ class DictionaryController { } await this._settingsController.modifyGlobalSettings(targets); } + + async _ensureDictionarySettings(dictionaries2) { + const optionsFull = await this._settingsController.getOptionsFull(); + const {profiles} = optionsFull; + const targets = []; + for (const {title} of dictionaries2) { + for (let i = 0, ii = profiles.length; i < ii; ++i) { + const {options: {dictionaries: dictionaryOptions}} = profiles[i]; + if (Object.prototype.hasOwnProperty.call(dictionaryOptions, title)) { continue; } + + const path = ObjectPropertyAccessor.getPathString(['profiles', i, 'options', 'dictionaries', title]); + targets.push({ + action: 'set', + path, + value: { + enabled: false, + allowSecondarySearches: false, + priority: 0 + } + }); + } + } + + if (targets.length > 0) { + const r = await this._settingsController.modifyGlobalSettings(targets); + console.log(r); + } + } } -- cgit v1.2.3