var settings_fuse;
var Settings = {
default: {settings},
toggle: (state) => {
Settings.load();
options.scrollTo(0, 0);
popups.set("#options", state);
},
apply: () => {
settings = {...settings, ...Settings.get()};
ipcRenderer.send("save-settings", Settings.get());
},
get: () => {
let opts = {};
let options = document.querySelectorAll(".option");
for (let i = 0; i < options.length; i++) {
let optName = options[i].getAttribute("name");
if (options[i].querySelector(".actions input")) {
let input = options[i].querySelector(".actions input").value;
if (options[i].getAttribute("type")) {
opts[optName] = input.split(" ");
} else {
opts[optName] = input;
}
} else if (options[i].querySelector(".actions select")) {
opts[optName] = options[i].querySelector(".actions select").value;
} else if (options[i].querySelector(".actions .switch")) {
if (options[i].querySelector(".actions .switch.on")) {
opts[optName] = true;
} else {
opts[optName] = false;
}
}
}
return opts;
},
load: () => {
// re-opens any closed categories
let categories = document.querySelectorAll("#options details");
for (let i = 0; i < categories.length; i++) {
categories[i].setAttribute("open", true);
// hide categories that aren't for the current platform
let for_platform = categories[i].getAttribute("platform");
if (for_platform && process.platform != for_platform) {
categories[i].style.display = "none";
categories[i].setAttribute("perma-hidden", true);
}
}
let options = document.querySelectorAll(".option");
for (let i = 0; i < options.length; i++) {
// hide options that aren't for the current platform
let for_platform = options[i].getAttribute("platform");
if (for_platform && process.platform != for_platform) {
options[i].style.display = "none";
options[i].setAttribute("perma-hidden", true);
}
let optName = options[i].getAttribute("name");
if (optName == "forcedlang") {
let div = options[i].querySelector("select");
div.innerHTML = "";
let lang_dir = __dirname + "/../lang";
let langs = fs.readdirSync(lang_dir);
for (let i in langs) {
let lang_file = require(lang_dir + "/" + langs[i]);
let lang_no_extension = langs[i].replace(/\..*$/, "");
if (! lang_file.lang || ! lang_file.lang.title) {
continue;
}
let title = lang_file.lang.title;
if (title) {
div.innerHTML += ``
}
}
div.value = settings.forcedlang;
continue;
}
if (settings[optName] != undefined) {
// check if setting has a `