-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.js
37 lines (32 loc) · 1.08 KB
/
settings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const invoke = window.__TAURI__.invoke;
async function apply_settings() {
invoke("get_settings").then(x => {
for (let key in x) {
let input = document.getElementById(key);
if (input === null) {
console.error("Unknown settings key: " + key);
continue;
}
if (input.getAttribute("type") === "checkbox") {
input.checked = x[key];
} else {
input.value = x[key];
}
}
})
}
(function() {
let ranges = document.querySelectorAll("input, select");
for (let i = 0; i < ranges.length; i++) {
if (ranges[i].getAttribute("type") === "checkbox") {
ranges[i].addEventListener("input", function (e) {
invoke("set_setting", {"id": ranges[i].id, "value": e.target.checked})
});
} else {
ranges[i].addEventListener("input", function (e) {
invoke("set_setting", {"id": ranges[i].id, "value": e.target.value})
});
}
}
apply_settings();
})();