Load defaults when LocalStorage is outdated

This commit is contained in:
2020-05-03 08:13:25 -04:00
parent 5fa343d40f
commit e6fde38c24
4 changed files with 12 additions and 7 deletions

View File

@@ -73,18 +73,23 @@ function Settings() {
this._onUpdate = function () {
$("#fuzzyToggle").prop("checked", this.options.fuzzy);
}
};
this.load = function () {
const raw = window.localStorage.getItem("options");
if (raw === null) {
this.options = _defaults;
} else {
this.options = JSON.parse(raw);
const j = JSON.parse(raw);
if (!j || Object.keys(_defaults).some(k => !j.hasOwnProperty(k))) {
this.options = _defaults;
} else {
this.options = j;
}
}
this._onUpdate();
}
};
this.save = function () {
window.localStorage.setItem("options", JSON.stringify(this.options));