fix: Fixes to the console focus
Server Deploy / deploy (push) Successful in 43s

This commit is contained in:
2026-07-28 12:02:48 +01:00
parent c9dab99271
commit 766dcabfde
2 changed files with 39 additions and 6 deletions
+33 -5
View File
@@ -6,7 +6,12 @@ export function openConsole(
container: HTMLElement,
wsUrl: string,
connectData = ""
): { disconnect: () => void; setScale: (scale: number) => void; resize: (width: number, height: number) => void } {
): {
disconnect: () => void;
setScale: (scale: number) => void;
resize: (width: number, height: number) => void;
focus: () => void;
} {
const tunnel = new Guacamole.WebSocketTunnel(wsUrl);
@@ -16,6 +21,7 @@ export function openConsole(
container.appendChild(client.getDisplay().getElement());
container.tabIndex = 0;
container.style.outline = "none";
client.connect(connectData);
@@ -48,18 +54,40 @@ export function openConsole(
keyboard.onkeyup = (k: number) => client.sendKeyEvent(0, k);
const refocus = () => container.focus();
container.addEventListener("mousedown", refocus);
container.focus();
const refocus = () => {
if (document.activeElement !== container) container.focus({ preventScroll: true });
};
container.addEventListener("pointerdown", refocus, true);
container.addEventListener("mousedown", refocus, true);
container.addEventListener("touchstart", refocus, true);
const onBlur = () => {
if (typeof keyboard.reset === "function") keyboard.reset();
};
container.addEventListener("blur", onBlur);
window.addEventListener("blur", onBlur);
container.focus({ preventScroll: true });
return {
disconnect() {
container.removeEventListener("mousedown", refocus);
container.removeEventListener("pointerdown", refocus, true);
container.removeEventListener("mousedown", refocus, true);
container.removeEventListener("touchstart", refocus, true);
container.removeEventListener("blur", onBlur);
window.removeEventListener("blur", onBlur);
keyboard.onkeydown = null;
keyboard.onkeyup = null;
if (typeof keyboard.reset === "function") keyboard.reset();
client.disconnect();
},
focus: refocus,
setScale(s: number) {
scale = s;
display.scale(s);