summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-10-27 19:26:30 -0400
committerGitHub <noreply@github.com>2020-10-27 19:26:30 -0400
commitdfdefc15d31b401092760926756150a839f52487 (patch)
treec64c857814d7502676d93c88188d9397fff283ce /ext/bg/js
parent45627bd6e69324eb5b4ca86041ad44046d22f7f4 (diff)
Options fixes (#962)
* Fix default options not having the correct versions * Move schema validation * Remove legacy version number * Add tests for OptionsUtil.getDefault() * Remove unused getValidValueOrDefault
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/options.js34
-rw-r--r--ext/bg/js/settings/backup-controller.js1
2 files changed, 26 insertions, 9 deletions
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 9e89e9bd..668be98e 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -82,7 +82,13 @@ class OptionsUtil {
}
// Generic updates
- return await this._applyUpdates(options, this._getVersionUpdates());
+ options = await this._applyUpdates(options, this._getVersionUpdates());
+
+ // Validation
+ options = this._schemaValidator.getValidValueOrDefault(this._optionsSchema, options);
+
+ // Result
+ return options;
}
async load() {
@@ -105,10 +111,10 @@ class OptionsUtil {
if (typeof options !== 'undefined') {
options = await this.update(options);
+ } else {
+ options = this.getDefault();
}
- options = this._schemaValidator.getValidValueOrDefault(this._optionsSchema, options);
-
return options;
}
@@ -126,11 +132,10 @@ class OptionsUtil {
}
getDefault() {
- return this._schemaValidator.getValidValueOrDefault(this._optionsSchema);
- }
-
- getValidValueOrDefault(options) {
- return this._schemaValidator.getValidValueOrDefault(this._optionsSchema, options);
+ const optionsVersion = this._getVersionUpdates().length;
+ const options = this._schemaValidator.getValidValueOrDefault(this._optionsSchema);
+ options.version = optionsVersion;
+ return options;
}
createValidatingProxy(options) {
@@ -468,6 +473,10 @@ class OptionsUtil {
{
async: true,
update: this._updateVersion4.bind(this)
+ },
+ {
+ async: false,
+ update: this._updateVersion5.bind(this)
}
];
}
@@ -586,4 +595,13 @@ class OptionsUtil {
await this._addFieldTemplatesToOptions(options, '/bg/data/anki-field-templates-upgrade-v4.handlebars');
return options;
}
+
+ _updateVersion5(options) {
+ // Version 5 changes:
+ // Removed legacy version number from profile options.
+ for (const profile of options.profiles) {
+ delete profile.options.version;
+ }
+ return options;
+ }
}
diff --git a/ext/bg/js/settings/backup-controller.js b/ext/bg/js/settings/backup-controller.js
index 454ede85..d5fa28bc 100644
--- a/ext/bg/js/settings/backup-controller.js
+++ b/ext/bg/js/settings/backup-controller.js
@@ -336,7 +336,6 @@ class BackupController {
// Upgrade options
optionsFull = await this._optionsUtil.update(optionsFull);
- optionsFull = this._optionsUtil.getValidValueOrDefault(optionsFull);
// Check for warnings
const sanitizationWarnings = this._settingsImportSanitizeOptions(optionsFull, true);