aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages
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
parentbcbd413e571d772a4438f57138169ad1a6a3b5a8 (diff)
Fix dictionary settings being missing after importing settings (#1576)
Diffstat (limited to 'ext/js/pages')
-rw-r--r--ext/js/pages/settings/backup-controller.js10
-rw-r--r--ext/js/pages/settings/dictionary-controller.js55
2 files changed, 35 insertions, 30 deletions
diff --git a/ext/js/pages/settings/backup-controller.js b/ext/js/pages/settings/backup-controller.js
index 933f0e2a..9b80f0b4 100644
--- a/ext/js/pages/settings/backup-controller.js
+++ b/ext/js/pages/settings/backup-controller.js
@@ -367,6 +367,9 @@ class BackupController {
}
}
+ // Update dictionaries
+ await DictionaryController.ensureDictionarySettings(this._settingsController, void 0, optionsFull, true, false);
+
// Assign options
await this._settingsImportSetOptionsFull(optionsFull);
}
@@ -401,12 +404,7 @@ class BackupController {
const optionsFull = this._optionsUtil.getDefault();
// Update dictionaries
- const dictionaries = await this._settingsController.getDictionaryInfo();
- for (const {options: {dictionaries: optionsDictionaries}} of optionsFull.profiles) {
- for (const {title} of dictionaries) {
- optionsDictionaries[title] = DictionaryController.createDefaultDictionarySettings(false);
- }
- }
+ await DictionaryController.ensureDictionarySettings(this._settingsController, void 0, optionsFull, true, false);
// Assign options
try {
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');
}