summaryrefslogtreecommitdiff
path: root/ext/js/pages/settings/dictionary-controller.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-03-31 18:32:17 -0400
committerGitHub <noreply@github.com>2021-03-31 18:32:17 -0400
commitbdec71976a9478beaf74d8299aa1ca6a95c2ce0c (patch)
tree49bfac05ddf45d73c1308fd4d5c5a5d802643ce2 /ext/js/pages/settings/dictionary-controller.js
parentbcbd413e571d772a4438f57138169ad1a6a3b5a8 (diff)
Fix dictionary settings being missing after importing settings (#1576)
Diffstat (limited to 'ext/js/pages/settings/dictionary-controller.js')
-rw-r--r--ext/js/pages/settings/dictionary-controller.js55
1 files changed, 31 insertions, 24 deletions
diff --git a/ext/js/pages/settings/dictionary-controller.js b/ext/js/pages/settings/dictionary-controller.js
index 65edcb67..7862b207 100644
--- a/ext/js/pages/settings/dictionary-controller.js
+++ b/ext/js/pages/settings/dictionary-controller.js
@@ -257,6 +257,36 @@ class DictionaryController {
};
}
+ static async ensureDictionarySettings(settingsController, dictionaries, optionsFull, modifyOptionsFull, newDictionariesEnabled) {
+ if (typeof dictionaries === 'undefined') {
+ dictionaries = await settingsController.getDictionaryInfo();
+ }
+ if (typeof optionsFull === 'undefined') {
+ optionsFull = await settingsController.getOptionsFull();
+ }
+
+ const targets = [];
+ const {profiles} = optionsFull;
+ for (const {title} of dictionaries) {
+ 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 value = DictionaryController.createDefaultDictionarySettings(newDictionariesEnabled);
+ if (modifyOptionsFull) {
+ dictionaryOptions[title] = value;
+ } else {
+ const path = ObjectPropertyAccessor.getPathString(['profiles', i, 'options', 'dictionaries', title]);
+ targets.push({action: 'set', path, value});
+ }
+ }
+ }
+
+ if (!modifyOptionsFull && targets.length > 0) {
+ await settingsController.modifyGlobalSettings(targets);
+ }
+ }
+
// Private
_onOptionsChanged({options}) {
@@ -290,7 +320,7 @@ class DictionaryController {
this._updateDictionariesEnabledWarnings(options);
- await this._ensureDictionarySettings(dictionaries);
+ await DictionaryController.ensureDictionarySettings(this._settingsController, dictionaries, void 0, false, false);
for (const dictionary of dictionaries) {
this._createDictionaryEntry(dictionary);
}
@@ -531,29 +561,6 @@ 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: DictionaryController.createDefaultDictionarySettings(false)
- });
- }
- }
-
- if (targets.length > 0) {
- await this._settingsController.modifyGlobalSettings(targets);
- }
- }
-
_triggerStorageChanged() {
yomichan.trigger('storageChanged');
}