Force declaring the setting types and stop storing them in localStorage
This commit is contained in:
parent
930fc12939
commit
c5ccb93eef
|
@ -107,7 +107,9 @@
|
|||
let type;
|
||||
|
||||
/* try to retrieve type from configuration */
|
||||
if (Object.prototype.hasOwnProperty.call(Conf, key)) {
|
||||
if (Object.prototype.hasOwnProperty.call(SettingsTypes, key)) {
|
||||
type = SettingsTypes[key];
|
||||
} else if (Object.prototype.hasOwnProperty.call(Conf, key)) {
|
||||
type = typeof Conf[key];
|
||||
}
|
||||
|
||||
|
@ -118,11 +120,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
/* if not set type is defined from value */
|
||||
if (typeof type === "undefined") {
|
||||
type = typeof value;
|
||||
}
|
||||
|
||||
/* storage value in localstorage */
|
||||
if (type === typeof value) {
|
||||
if (type === "object") {
|
||||
|
@ -133,32 +130,22 @@
|
|||
(type === "object") ||
|
||||
(type === "string")) {
|
||||
localStorage.setItem("trivabble" + key, value);
|
||||
|
||||
/* store type into localstorage if no default value in configuration */
|
||||
if (!Object.prototype.hasOwnProperty.call(Conf, key)) {
|
||||
localStorage.setItem("trivabble" + key + "_type", type);
|
||||
}
|
||||
} else {
|
||||
console.error("Unsupported type");
|
||||
}
|
||||
} else {
|
||||
console.error("incoherent type");
|
||||
console.error("Incoherent or missing type. See the SettingsTypes object.");
|
||||
}
|
||||
}
|
||||
|
||||
function migrateSetting(key, type) {
|
||||
if (Object.prototype.hasOwnProperty.call(localStorage, "trivabble" + key)) {
|
||||
localStorage.setItem("trivabble" + key + "_type", type);
|
||||
}
|
||||
}
|
||||
|
||||
migrateSetting("SpellCheckerEnabledOnce", "boolean");
|
||||
migrateSetting("DisableSpellChecker", "boolean");
|
||||
migrateSetting("GameNumber", "number");
|
||||
migrateSetting("BoardLang", "string");
|
||||
migrateSetting("GameNumber", "number");
|
||||
migrateSetting("Lang", "string");
|
||||
migrateSetting("PlayerName", "string");
|
||||
const SettingsTypes = {
|
||||
SpellCheckerEnabledOnce: "boolean",
|
||||
DisableSpellChecker: "boolean",
|
||||
GameNumber: "number",
|
||||
BoardLang: "string",
|
||||
Lang: "string",
|
||||
PlayerName: "string"
|
||||
};
|
||||
|
||||
const _ = (window.libD && libD.l10n) ? libD.l10n() : function (s) {
|
||||
return s;
|
||||
|
|
Loading…
Reference in New Issue