Fix dictionary settings not being deleted when deleting a single dictionary (#893)

This commit is contained in:
toasted-nutbread 2020-10-06 23:00:00 -04:00 committed by GitHub
parent 2f96218e33
commit 1a91935dd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -351,6 +351,7 @@ class DictionaryController {
}; };
await this._deleteDictionaryInternal(dictionaryTitle, onProgress); await this._deleteDictionaryInternal(dictionaryTitle, onProgress);
await this._deleteDictionarySettings(dictionaryTitle);
} catch (e) { } catch (e) {
yomichan.logError(e); yomichan.logError(e);
} finally { } finally {
@ -389,4 +390,18 @@ class DictionaryController {
await dictionaryDatabase.prepare(); await dictionaryDatabase.prepare();
return dictionaryDatabase; 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);
}
} }