aboutsummaryrefslogtreecommitdiff
path: root/src/app
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2024-04-29 17:55:06 +0200
committer0neGal <mail@0negal.com>2024-04-29 17:55:06 +0200
commit82ab89b7509f81066eea40d00dc7d7addf90be77 (patch)
tree5c1b1095ccc3c6251eb8e62e8b6015a35a8d78ba /src/app
parent61e9d38f3c5b07010326c7a8fae7cc0fc334791f (diff)
downloadViper-82ab89b7509f81066eea40d00dc7d7addf90be77.tar.gz
Viper-82ab89b7509f81066eea40d00dc7d7addf90be77.zip
fixed app/js/settings.js to for custom <select>'s
Previously, settings using `<select>`'s for their value only worked on the `forcedlang` setting, now it just works overall, this wasn't an issue before, as we had no need for it. More importantly `forcedlang` is special in that it dynamically loads the list of languages available, so it was and still is handled separately, to support that behavior.
Diffstat (limited to 'src/app')
-rw-r--r--src/app/js/settings.js35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/app/js/settings.js b/src/app/js/settings.js
index 2d68c13..9eb6c76 100644
--- a/src/app/js/settings.js
+++ b/src/app/js/settings.js
@@ -1,6 +1,7 @@
var settings_fuse;
var Settings = {
+ default: {settings},
toggle: (state) => {
Settings.load();
options.scrollTo(0, 0);
@@ -42,11 +43,25 @@ var Settings = {
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");
@@ -75,6 +90,25 @@ var Settings = {
}
if (settings[optName] != undefined) {
+ // check if setting has a `<select>`
+ let select_el = options[i].querySelector(".actions select");
+ if (select_el) {
+ // get `<option>` for settings value, if it exists
+ let option = select_el.querySelector(
+ `option[value="${settings[optName]}"]`
+ )
+
+ // check if it exists
+ if (option) {
+ // set the `<select>` to the settings value
+ select_el.value = settings[optName];
+ } else { // use the default value
+ select_el.value = Settings.default[optName];
+ }
+
+ continue;
+ }
+
switch(typeof settings[optName]) {
case "string":
options[i].querySelector(".actions input").value = settings[optName];
@@ -92,7 +126,6 @@ var Settings = {
switchDiv.classList.remove("on");
}
break
-
}
}
}