Skip to content

Commit d6126c7

Browse files
committed
web: allow server-side configurable defaults for all UI switch settings
Apply the existing tools.config.getBool()/get() pattern to all remaining bindSimpleSwitch calls and storage.get() defaults across the Web UI, allowing admins to set defaults for every toggle via /etc/kvmd/web.css CSS custom properties. Previously only "Expand for the entire tab" supported this. Now all settings including confirmations, keyboard/mouse options, stream mode/orientation, mic/cam, and more can be configured server-side while still allowing per-user localStorage overrides.
1 parent 7cc9f9e commit d6126c7

8 files changed

Lines changed: 19 additions & 19 deletions

File tree

web/share/js/kvm/atx.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function Atx(__recorder) {
3939
$("atx-power-led").title = "Power Led";
4040
$("atx-hdd-led").title = "Disk Activity Led";
4141

42-
tools.storage.bindSimpleSwitch($("atx-ask-switch"), "atx.ask", true);
42+
tools.storage.bindSimpleSwitch($("atx-ask-switch"), "atx.ask", tools.config.getBool("kvm--atx-ask", true));
4343

4444
tools.el.setOnClick($("atx-power-button"), () => __clickAtx("power"));
4545
tools.el.setOnClick($("atx-power-button-long"), () => __clickAtx("power_long"));

web/share/js/kvm/hid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function Hid(__getGeometry, __recorder) {
7575
});
7676
}
7777

78-
tools.storage.bindSimpleSwitch($("hid-sysrq-ask-switch"), "hid.sysrq.ask", true);
78+
tools.storage.bindSimpleSwitch($("hid-sysrq-ask-switch"), "hid.sysrq.ask", tools.config.getBool("kvm--hid-sysrq-ask", true));
7979

8080
tools.el.setOnClick($("hid-jiggler-switch"), __clickJigglerSwitch);
8181
};

web/share/js/kvm/keyboard.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export function Keyboard(__recordWsEvent) {
5050
window.addEventListener("focusin", __updateOnlineLeds);
5151
window.addEventListener("focusout", __updateOnlineLeds);
5252

53-
tools.storage.bindSimpleSwitch($("hid-keyboard-bad-link-switch"), "hid.keyboard.bad_link", false);
54-
tools.storage.bindSimpleSwitch($("hid-keyboard-swap-cc-switch"), "hid.keyboard.swap_cc", false);
53+
tools.storage.bindSimpleSwitch($("hid-keyboard-bad-link-switch"), "hid.keyboard.bad_link", tools.config.getBool("kvm--hid-keyboard-bad-link", false));
54+
tools.storage.bindSimpleSwitch($("hid-keyboard-swap-cc-switch"), "hid.keyboard.swap_cc", tools.config.getBool("kvm--hid-keyboard-swap-cc", false));
5555

5656
__el_magic = $("hid-keyboard-magic-selector");
5757
let alt = (tools.browser.is_apple ? "Option" : "Alt");

web/share/js/kvm/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function main() {
4545
}
4646
}, false);
4747

48-
tools.storage.bindSimpleSwitch($("page-close-ask-switch"), "page.close.ask", true, function(value) {
48+
tools.storage.bindSimpleSwitch($("page-close-ask-switch"), "page.close.ask", tools.config.getBool("kvm--page-close-ask", true), function(value) {
4949
if (value) {
5050
window.onbeforeunload = function(ev) {
5151
let text = "Are you sure you want to close PiKVM session?";

web/share/js/kvm/mouse.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ export function Mouse(__getGeometry, __recordWsEvent) {
8585
$("stream-box").addEventListener("touchmove", __streamTouchMoveHandler);
8686
$("stream-box").addEventListener("touchend", __streamTouchEndHandler);
8787

88-
tools.storage.bindSimpleSwitch($("hid-mouse-squash-switch"), "hid.mouse.squash", true);
89-
tools.storage.bindSimpleSwitch($("hid-mouse-reverse-scrolling-y-switch"), "hid.mouse.reverse_scrolling", false);
90-
tools.storage.bindSimpleSwitch($("hid-mouse-reverse-scrolling-x-switch"), "hid.mouse.reverse_panning", false);
88+
tools.storage.bindSimpleSwitch($("hid-mouse-squash-switch"), "hid.mouse.squash", tools.config.getBool("kvm--hid-mouse-squash", true));
89+
tools.storage.bindSimpleSwitch($("hid-mouse-reverse-scrolling-y-switch"), "hid.mouse.reverse_scrolling", tools.config.getBool("kvm--hid-mouse-reverse-scrolling", false));
90+
tools.storage.bindSimpleSwitch($("hid-mouse-reverse-scrolling-x-switch"), "hid.mouse.reverse_panning", tools.config.getBool("kvm--hid-mouse-reverse-panning", false));
9191
let cumulative_scrolling = !(tools.browser.is_firefox && !tools.browser.is_mac);
92-
tools.storage.bindSimpleSwitch($("hid-mouse-cumulative-scrolling-switch"), "hid.mouse.cumulative_scrolling", cumulative_scrolling);
93-
tools.storage.bindSimpleSwitch($("hid-mouse-dot-switch"), "hid.mouse.dot", true, __updateOnlineLeds);
92+
tools.storage.bindSimpleSwitch($("hid-mouse-cumulative-scrolling-switch"), "hid.mouse.cumulative_scrolling", tools.config.getBool("kvm--hid-mouse-cumulative-scrolling", cumulative_scrolling));
93+
tools.storage.bindSimpleSwitch($("hid-mouse-dot-switch"), "hid.mouse.dot", tools.config.getBool("kvm--hid-mouse-dot", true), __updateOnlineLeds);
9494

9595
__updateOnlineLeds();
9696
};

web/share/js/kvm/paste.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ export function Paste(__recorder) {
3939
}
4040
});
4141

42-
tools.storage.bindSimpleSwitch($("hid-pak-ask-switch"), "hid.pak.ask", true);
42+
tools.storage.bindSimpleSwitch($("hid-pak-ask-switch"), "hid.pak.ask", tools.config.getBool("kvm--hid-pak-ask", true));
4343

44-
tools.storage.bindSimpleSwitch($("hid-pak-secure-switch"), "hid.pak.secure", false, function(value) {
44+
tools.storage.bindSimpleSwitch($("hid-pak-secure-switch"), "hid.pak.secure", tools.config.getBool("kvm--hid-pak-secure", false), function(value) {
4545
$("hid-pak-text").style.setProperty("-webkit-text-security", (value ? "disc" : "none"));
4646
});
4747

web/share/js/kvm/stream.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function Streamer() {
7373

7474
// Not getInt() because of radio is a string container.
7575
// Also don't reset Streamer at class init.
76-
tools.radio.clickValue("stream-orient-radio", tools.storage.get("stream.orient", 0));
76+
tools.radio.clickValue("stream-orient-radio", tools.storage.get("stream.orient", tools.config.get("kvm--stream-orient", 0)));
7777
tools.radio.setOnClick("stream-orient-radio", function() {
7878
if (["janus", "media"].includes(__streamer.getMode())) {
7979
let orient = parseInt(tools.radio.getValue("stream-orient-radio"));
@@ -98,15 +98,15 @@ export function Streamer() {
9898
tools.el.setEnabled($("stream-cam-switch"), !!value);
9999
});
100100

101-
tools.storage.bindSimpleSwitch($("stream-mic-switch"), "stream.mic", false, function(allow_mic) {
101+
tools.storage.bindSimpleSwitch($("stream-mic-switch"), "stream.mic", tools.config.getBool("kvm--stream-mic", false), function(allow_mic) {
102102
if (__streamer.getMode() === "janus") {
103103
if (__streamer.isMicAllowed() !== allow_mic) {
104104
__resetStream();
105105
}
106106
}
107107
});
108108

109-
tools.storage.bindSimpleSwitch($("stream-cam-switch"), "stream.cam", false, function(allow_cam) {
109+
tools.storage.bindSimpleSwitch($("stream-cam-switch"), "stream.cam", tools.config.getBool("kvm--stream-cam", false), function(allow_cam) {
110110
if (__streamer.getMode() === "janus") {
111111
if (__streamer.isCamAllowed() !== allow_cam) {
112112
__resetStream();
@@ -117,7 +117,7 @@ export function Streamer() {
117117
tools.el.setOnClick($("stream-screenshot-button"), __clickScreenshotButton);
118118
tools.el.setOnClick($("stream-reset-button"), __clickResetButton);
119119

120-
tools.storage.bindSimpleSwitch($("stream-suspend-switch"), "stream.suspend", false, __visibilityHook);
120+
tools.storage.bindSimpleSwitch($("stream-suspend-switch"), "stream.suspend", tools.config.getBool("kvm--stream-suspend", false), __visibilityHook);
121121

122122
$("stream-window").show_hook = __visibilityHook;
123123
$("stream-window").close_hook = __visibilityHook;
@@ -253,7 +253,7 @@ export function Streamer() {
253253
tools.feature.setEnabled($("stream-cam"), false);
254254
}
255255

256-
let mode = tools.storage.get("stream.mode", "janus");
256+
let mode = tools.storage.get("stream.mode", tools.config.get("kvm--stream-mode", "janus"));
257257
if (mode === "janus" && !has_janus) {
258258
mode = "media";
259259
}

web/share/js/kvm/switch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export function Switch() {
4545
tools.el.setOnClick($("switch-edid-remove-button"), __clickRemoveEdidButton);
4646
tools.el.setOnClick($("switch-edid-copy-data-button"), __clickCopyEdidDataButton);
4747

48-
tools.storage.bindSimpleSwitch($("switch-atx-ask-switch"), "switch.atx.ask", true);
49-
tools.storage.bindSimpleSwitch($("switch-msd-ask-switch"), "switch.msd.ask", true);
48+
tools.storage.bindSimpleSwitch($("switch-atx-ask-switch"), "switch.atx.ask", tools.config.getBool("kvm--switch-atx-ask", true));
49+
tools.storage.bindSimpleSwitch($("switch-msd-ask-switch"), "switch.msd.ask", tools.config.getBool("kvm--switch-msd-ask", true));
5050

5151
for (let role of ["inactive", "active", "flashing", "beacon", "bootloader"]) {
5252
let el_brightness = $(`switch-color-${role}-brightness-slider`);

0 commit comments

Comments
 (0)