Fix dictionary settings being missing after importing settings (#1576)
This commit is contained in:
parent
bcbd413e57
commit
bdec71976a
@ -367,6 +367,9 @@ class BackupController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update dictionaries
|
||||||
|
await DictionaryController.ensureDictionarySettings(this._settingsController, void 0, optionsFull, true, false);
|
||||||
|
|
||||||
// Assign options
|
// Assign options
|
||||||
await this._settingsImportSetOptionsFull(optionsFull);
|
await this._settingsImportSetOptionsFull(optionsFull);
|
||||||
}
|
}
|
||||||
@ -401,12 +404,7 @@ class BackupController {
|
|||||||
const optionsFull = this._optionsUtil.getDefault();
|
const optionsFull = this._optionsUtil.getDefault();
|
||||||
|
|
||||||
// Update dictionaries
|
// Update dictionaries
|
||||||
const dictionaries = await this._settingsController.getDictionaryInfo();
|
await DictionaryController.ensureDictionarySettings(this._settingsController, void 0, optionsFull, true, false);
|
||||||
for (const {options: {dictionaries: optionsDictionaries}} of optionsFull.profiles) {
|
|
||||||
for (const {title} of dictionaries) {
|
|
||||||
optionsDictionaries[title] = DictionaryController.createDefaultDictionarySettings(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assign options
|
// Assign options
|
||||||
try {
|
try {
|
||||||
|
@ -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
|
// Private
|
||||||
|
|
||||||
_onOptionsChanged({options}) {
|
_onOptionsChanged({options}) {
|
||||||
@ -290,7 +320,7 @@ class DictionaryController {
|
|||||||
|
|
||||||
this._updateDictionariesEnabledWarnings(options);
|
this._updateDictionariesEnabledWarnings(options);
|
||||||
|
|
||||||
await this._ensureDictionarySettings(dictionaries);
|
await DictionaryController.ensureDictionarySettings(this._settingsController, dictionaries, void 0, false, false);
|
||||||
for (const dictionary of dictionaries) {
|
for (const dictionary of dictionaries) {
|
||||||
this._createDictionaryEntry(dictionary);
|
this._createDictionaryEntry(dictionary);
|
||||||
}
|
}
|
||||||
@ -531,29 +561,6 @@ class DictionaryController {
|
|||||||
await this._settingsController.modifyGlobalSettings(targets);
|
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() {
|
_triggerStorageChanged() {
|
||||||
yomichan.trigger('storageChanged');
|
yomichan.trigger('storageChanged');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user