2017-11-14 01:07:27 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
(function(){
|
|
|
|
"use strict";
|
|
|
|
|
2019-04-08 00:02:29 +02:00
|
|
|
const settings = require("../lib/settings");
|
|
|
|
const logging = require("../lib/logging");
|
|
|
|
const settingsMigration = require("../lib/settingsMigration");
|
2019-05-02 00:30:30 +02:00
|
|
|
require("../lib/theme").init();
|
2017-11-14 01:07:27 +01:00
|
|
|
const input = document.getElementById("settings");
|
|
|
|
settings.onloaded(function(){
|
|
|
|
var data = {};
|
|
|
|
settings.forEach(function(def){
|
|
|
|
data[def.name] = def.get();
|
|
|
|
});
|
|
|
|
input.value = JSON.stringify(data, null, "\t");
|
|
|
|
|
|
|
|
input.addEventListener("input", function(){
|
|
|
|
try {
|
|
|
|
var newSettings = JSON.parse(this.value);
|
|
|
|
var isValid = true;
|
2019-03-11 22:10:34 +01:00
|
|
|
|
|
|
|
while (settingsMigration.transitions.hasOwnProperty(newSettings.storageVersion)){
|
|
|
|
let oldVersion = newSettings.storageVersion;
|
|
|
|
newSettings = settingsMigration.transitions[newSettings.storageVersion](newSettings);
|
|
|
|
if (oldVersion === newSettings.storageVersion){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-11-14 01:07:27 +01:00
|
|
|
|
|
|
|
Object.entries(newSettings).forEach(function(entry){
|
|
|
|
const [name, value] = entry;
|
|
|
|
const def = settings.getDefinition(name);
|
|
|
|
if (!def){
|
|
|
|
logging.warning("Setting %s not known.");
|
|
|
|
isValid = false;
|
|
|
|
}
|
|
|
|
else if (def.get() !== value){
|
|
|
|
const invalid = def.invalid(value);
|
|
|
|
if (invalid){
|
|
|
|
isValid = false;
|
|
|
|
logging.warning("Invalid setting for %s:", name, value, invalid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (isValid){
|
|
|
|
this.classList.remove("invalid");
|
|
|
|
Object.entries(newSettings).forEach(function(entry){
|
|
|
|
const [name, value] = entry;
|
|
|
|
if (settings[name] !== value){
|
|
|
|
settings[name] = value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.classList.add("invalid");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e){
|
|
|
|
logging.warning("Invalid JSON:", e);
|
|
|
|
this.classList.add("invalid");
|
|
|
|
}
|
|
|
|
});
|
2019-03-11 22:10:34 +01:00
|
|
|
input.addEventListener("blur", function(){
|
|
|
|
if (!this.classList.contains("invalid")){
|
|
|
|
var data = {};
|
|
|
|
settings.forEach(function(def){
|
|
|
|
data[def.name] = def.get();
|
|
|
|
});
|
|
|
|
input.value = JSON.stringify(data, null, "\t");
|
|
|
|
}
|
|
|
|
});
|
2017-11-14 01:07:27 +01:00
|
|
|
});
|
|
|
|
}());
|