Skip to content

web: allow server-side defaults for page-close and stream-suspend settings#209

Open
nullstacked wants to merge 1 commit intopikvm:masterfrom
nullstacked:web-ui-server-side-defaults
Open

web: allow server-side defaults for page-close and stream-suspend settings#209
nullstacked wants to merge 1 commit intopikvm:masterfrom
nullstacked:web-ui-server-side-defaults

Conversation

@nullstacked
Copy link
Copy Markdown

@nullstacked nullstacked commented Apr 9, 2026

Summary

The Web UI has ~18 client-side settings with defaults hardcoded in JavaScript. Only one of them (Expand for the entire tab by default) uses the existing tools.config.getBool() mechanism to allow server-side configuration via CSS custom properties in /etc/kvmd/web.css.

This PR extends that same pattern to all remaining settings, so admins can configure defaults for every UI toggle server-side.

What changed

Every tools.storage.bindSimpleSwitch() call with a hardcoded default now reads from tools.config.getBool() (or tools.config.get() for non-boolean values) first, falling back to the original default. No behavior changes when no CSS properties are set.

Files changed:

  • web/share/js/kvm/main.js — page close confirmation
  • web/share/js/kvm/stream.js — stream suspend, mic, cam, mode, orientation
  • web/share/js/kvm/atx.js — ATX confirmation dialog
  • web/share/js/kvm/switch.js — switch ATX/MSD confirmations
  • web/share/js/kvm/hid.js — SysRq confirmation
  • web/share/js/kvm/keyboard.js — bad link, swap Ctrl/CapsLock
  • web/share/js/kvm/mouse.js — squash, reverse scroll X/Y, cumulative scroll, dot cursor
  • web/share/js/kvm/paste.js — paste confirmation, secure mode

Example usage

Admins can now set defaults in /etc/kvmd/web.css:

:root {
    /* Interface settings */
    --config-ui--kvm--page-close-ask: 0;
    --config-ui--kvm--full-tab-stream: 1;      /* already worked before */
    --config-ui--kvm--stream-suspend: 1;

    /* Stream settings */
    --config-ui--kvm--stream-mode: mjpeg;       /* janus, media, or mjpeg */
    --config-ui--kvm--stream-orient: 0;         /* 0, 90, 180, 270 */
    --config-ui--kvm--stream-mic: 0;
    --config-ui--kvm--stream-cam: 0;

    /* Confirmation dialogs */
    --config-ui--kvm--atx-ask: 0;
    --config-ui--kvm--switch-atx-ask: 0;
    --config-ui--kvm--switch-msd-ask: 0;
    --config-ui--kvm--hid-sysrq-ask: 0;
    --config-ui--kvm--hid-pak-ask: 0;
    --config-ui--kvm--hid-pak-secure: 1;

    /* Keyboard */
    --config-ui--kvm--hid-keyboard-bad-link: 0;
    --config-ui--kvm--hid-keyboard-swap-cc: 0;

    /* Mouse */
    --config-ui--kvm--hid-mouse-squash: 1;
    --config-ui--kvm--hid-mouse-reverse-scrolling: 0;
    --config-ui--kvm--hid-mouse-reverse-panning: 0;
    --config-ui--kvm--hid-mouse-cumulative-scrolling: 1;
    --config-ui--kvm--hid-mouse-dot: 1;
}

These set the initial default for new users or cleared browsers. Users can still override via the UI, and their preference is saved in localStorage as before.

Notes

  • Zero behavior change when no CSS custom properties are set — all original hardcoded values are preserved as fallbacks
  • The tools.config.getBool() / tools.config.get() infrastructure and the CSS injection pipeline (/etc/kvmd/web.css → nginx user.css alias → :root properties) already exist
  • This is particularly useful for kiosk deployments or multi-user setups where admins want consistent defaults

@nullstacked nullstacked force-pushed the web-ui-server-side-defaults branch 2 times, most recently from 7952b54 to c069113 Compare April 9, 2026 21:06
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.
@nullstacked nullstacked force-pushed the web-ui-server-side-defaults branch from c069113 to d6126c7 Compare April 9, 2026 21:07
@mdevaev
Copy link
Copy Markdown
Member

mdevaev commented Apr 12, 2026

Hello. I like the idea but I need to think a bit about implementation.

@nullstacked
Copy link
Copy Markdown
Author

nullstacked commented Apr 16, 2026

Hello. I like the idea but I need to think a bit about implementation.

Thank you for taking a look. Reason I went with this approach is because I saw you had code already using this already for one of the ui settings so I thought that was the established pattern:

tools.storage.bindSimpleSwitch( $("page-full-tab-stream-switch"), "page.full_tab_stream", tools.config.getBool("kvm--full-tab-stream", false));

Either way would be great to get a solution as the use case for this request is because I have multiple users across many browsers and we have to constantly reapply the settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants