authoravatarclover caruso<git@paperclover.net>2026-10-20 13:49:53-07:00
committeravatarclover caruso<git@paperclover.net>2026-10-21 02:52:29-07:00
loga59184893f02f890bfcc387205db09907351ee35
tree2f82c275aa679644c7231d6f01f20c815629adde
parentf8f091ba7269f62f2a325083a02ed25ef1de77f2
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

Keep VM consoles connected without stealing toolbar focus

Retry interrupted streams with bounded backoff and keep signaling alive. Preserve toolbar focus across connection changes, fit VM workspaces on narrow screens, and keep hardware navigation usable when optional credential loading fails. Validation: 57 Rust tests, TypeScript check/build, and preview browser checks at 390px including denied credential/history requests. Assisted-by: gpt-6-astra

4 files changed, 32 insertions(+), 15 deletions(-)

dashboard/src/vms.rs+12-6
...@@ -115,13 +115,19 @@ async fn bridge(socket: WebSocket, stream: tokio::net::UnixStream) {...@@ -115,13 +115,19 @@ async fn bridge(socket: WebSocket, stream: tokio::net::UnixStream) {
115 };115 };
116 let downstream = async {116 let downstream = async {
117 let mut buffer = vec![0; 65536];117 let mut buffer = vec![0; 65536];
118 let mut heartbeat = tokio::time::interval(Duration::from_secs(15));
119 heartbeat.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
118 loop {120 loop {
119 let count = read.read(&mut buffer).await?;121 let message = tokio::select! {
120 if count == 0 {122 result = read.read(&mut buffer) => {
121 break;123 let count = result?;
122 }124 if count == 0 { break; }
123 send.send(Message::Binary(Bytes::copy_from_slice(&buffer[..count])))125 Message::Binary(Bytes::copy_from_slice(&buffer[..count]))
124 .await126 }
127 _ = heartbeat.tick() => Message::Ping(Bytes::new()),
128 };
129 tokio::time::timeout(Duration::from_secs(5), send.send(message))
130 .await.map_err(std::io::Error::other)?
125 .map_err(std::io::Error::other)?;131 .map_err(std::io::Error::other)?;
126 }132 }
127 Ok::<_, std::io::Error>(())133 Ok::<_, std::io::Error>(())
dashboard/web/components/VMConsole.tsx+8-5
...@@ -21,6 +21,7 @@ export function VMConsole(props: { name: string; platform: Domain["platform"]; e...@@ -21,6 +21,7 @@ export function VMConsole(props: { name: string; platform: Domain["platform"]; e
21 const enabled = createMemo(() => props.enabled);21 const enabled = createMemo(() => props.enabled);
22 const preparing = () => !!props.setup && props.setup !== "ready";22 const preparing = () => !!props.setup && props.setup !== "ready";
23 let reconnectTimer: number | undefined;23 let reconnectTimer: number | undefined;
24 let retryDelay = 1000;
24 let attempt = 0;25 let attempt = 0;
25 let video!: HTMLVideoElement;26 let video!: HTMLVideoElement;
26 let canvas!: HTMLCanvasElement;27 let canvas!: HTMLCanvasElement;
...@@ -185,15 +186,17 @@ export function VMConsole(props: { name: string; platform: Domain["platform"]; e...@@ -185,15 +186,17 @@ export function VMConsole(props: { name: string; platform: Domain["platform"]; e
185 if (current !== attempt || disposed) return;186 if (current !== attempt || disposed) return;
186 setState("Disconnected");187 setState("Disconnected");
187 disconnect();188 disconnect();
188 if (preparing() && props.setup !== "failed") {189 setProblem(preparing() && props.setup !== "failed" ? "" : message);
189 setProblem("");190 if (enabled() && props.setup !== "failed") {
190 reconnectTimer = window.setTimeout(connect, 1000);191 reconnectTimer = window.setTimeout(connect, retryDelay);
191 } else setProblem(message);192 retryDelay = Math.min(retryDelay * 2, 30000);
193 }
192 };194 };
193 const timeout = window.setTimeout(() => fail("The screen couldn't connect. Reconnect to try again."), 20000);195 const timeout = window.setTimeout(() => fail("The screen couldn't connect. Reconnect to try again."), 20000);
194 const ready = () => {196 const ready = () => {
195 if (current !== attempt || disposed || video.readyState < 2 || input?.readyState !== "open") return;197 if (current !== attempt || disposed || video.readyState < 2 || input?.readyState !== "open") return;
196 clearTimeout(timeout);198 clearTimeout(timeout);
199 retryDelay = 1000;
197 setState("Connected");200 setState("Connected");
198 };201 };
199 disconnect = () => {202 disconnect = () => {
...@@ -352,7 +355,7 @@ export function VMConsole(props: { name: string; platform: Domain["platform"]; e...@@ -352,7 +355,7 @@ export function VMConsole(props: { name: string; platform: Domain["platform"]; e
352 setProblem("");355 setProblem("");
353 }356 }
354 });357 });
355 createEffect(() => { if (props.active && connected() && !preparing()) video.focus(); else release(); });358 createEffect(() => { if (!props.active || !connected() || preparing()) release(); });
356 createEffect(on(() => props.setup, setup => {359 createEffect(on(() => props.setup, setup => {
357 if (setup === "ready" && enabled() && state() === "Disconnected") void connect();360 if (setup === "ready" && enabled() && state() === "Disconnected") void connect();
358 }, { defer: true }));361 }, { defer: true }));
dashboard/web/pages/VMs.css+6
...@@ -132,6 +132,12 @@...@@ -132,6 +132,12 @@
132.vm-active .list-body.flush { margin: 0; padding: 0; overflow: hidden; }132.vm-active .list-body.flush { margin: 0; padding: 0; overflow: hidden; }
133.vm-active .list-body.flush > .vm-workspace { margin: 0; flex: 1; min-height: 0; }133.vm-active .list-body.flush > .vm-workspace { margin: 0; flex: 1; min-height: 0; }
134.vm-workspace { display: flex; flex-direction: column; }134.vm-workspace { display: flex; flex-direction: column; }
135.vm-home { display: none; }
136@media (max-width: 640px) {
137 .shell:has(.vm-active) { grid-template-columns: minmax(0, 1fr); }
138 .shell:has(.vm-active) > .sidebar { display: none; }
139 .vm-home { display: inline-flex; }
140}
135.vm-console-screen[hidden] { display: none; }141.vm-console-screen[hidden] { display: none; }
136.vm-workspace .vm-detail { padding: 20px var(--gutter); overflow: auto; flex: 1; min-height: 0; }142.vm-workspace .vm-detail { padding: 20px var(--gutter); overflow: auto; flex: 1; min-height: 0; }
137.vm-menu { position: relative; font-size: 12px; }143.vm-menu { position: relative; font-size: 12px; }
dashboard/web/pages/VMs.tsx+6-4
...@@ -633,6 +633,7 @@ export function VMs() {...@@ -633,6 +633,7 @@ export function VMs() {
633 </>633 </>
634 }>{(name) => {634 }>{(name) => {
635 const [access] = createResource(() => name, (name) => parseResponse(api.vms[":name"].access.$get({ param: { name } })));635 const [access] = createResource(() => name, (name) => parseResponse(api.vms[":name"].access.$get({ param: { name } })));
636 const login = lastGood(access);
636 const [consoleOpened, setConsoleOpened] = createSignal(false);637 const [consoleOpened, setConsoleOpened] = createSignal(false);
637 createEffect(() => { if (activeTab() === "console") setConsoleOpened(true); });638 createEffect(() => { if (activeTab() === "console") setConsoleOpened(true); });
638 return <Show when={latest().domains.find((vm) => vm.name === name)} fallback={639 return <Show when={latest().domains.find((vm) => vm.name === name)} fallback={
...@@ -644,9 +645,10 @@ export function VMs() {...@@ -644,9 +645,10 @@ export function VMs() {
644 clipboard={vm().capabilities.includes("clipboard") ? async (text) => { await parseResponse(api.vms[":name"].clipboard.$post({ param: { name }, json: { text } })); } : undefined}645 clipboard={vm().capabilities.includes("clipboard") ? async (text) => { await parseResponse(api.vms[":name"].clipboard.$post({ param: { name }, json: { text } })); } : undefined}
645 content={(toolbar) => <>646 content={(toolbar) => <>
646 <Show when={consoleOpened()}><VMSerial name={name} enabled={running(vm()) && vm().platform === "linux" && vm().serial} active={activeTab() === "console"} toolbar={toolbar} /></Show>647 <Show when={consoleOpened()}><VMSerial name={name} enabled={running(vm()) && vm().platform === "linux" && vm().serial} active={activeTab() === "console"} toolbar={toolbar} /></Show>
647 <Show when={activeTab() === "hardware"}><Hardware vm={vm()} refetch={refetch} username={access()?.username} hostname={access()?.hostname} /></Show>648 <Show when={activeTab() === "hardware"}><Hardware vm={vm()} refetch={refetch} username={login()?.username} hostname={login()?.hostname} /></Show>
648 </>}649 </>}
649 toolbar={<>650 toolbar={<>
651 <button class="button small vm-home" onClick={() => setParams({ vm: undefined, tab: undefined })}>VMs</button>
650 <TabBar label="VM workspace">652 <TabBar label="VM workspace">
651 <button aria-pressed={activeTab() === "screen"} onClick={() => setParams({ tab: undefined })}><Monitor size={13} />Screen</button>653 <button aria-pressed={activeTab() === "screen"} onClick={() => setParams({ tab: undefined })}><Monitor size={13} />Screen</button>
652 <Show when={vm().platform === "linux" && vm().serial}><button aria-pressed={activeTab() === "console"} onClick={() => setParams({ tab: "console" })}><SquareTerminal size={13} />Console</button></Show>654 <Show when={vm().platform === "linux" && vm().serial}><button aria-pressed={activeTab() === "console"} onClick={() => setParams({ tab: "console" })}><SquareTerminal size={13} />Console</button></Show>
...@@ -668,9 +670,9 @@ export function VMs() {...@@ -668,9 +670,9 @@ export function VMs() {
668 }}><Disc2 size={14} aria-hidden="true" />Eject ISO</button>670 }}><Disc2 size={14} aria-hidden="true" />Eject ISO</button>
669 <span class="muted vm-menu-info">{vm().media.find((item) => item.source)?.source ?? "No ISO attached"}</span>671 <span class="muted vm-menu-info">{vm().media.find((item) => item.source)?.source ?? "No ISO attached"}</span>
670 </VMMenu></Show>672 </VMMenu></Show>
671 <Show when={access()}>{(login) => <VMMenu label="Password">673 <Show when={login()}>{(credentials) => <VMMenu label="Password">
672 <label class="vm-password">Guest password<input aria-label="Guest password" value={login().password} readOnly spellcheck={false} /></label>674 <label class="vm-password">Guest password<input aria-label="Guest password" value={credentials().password} readOnly spellcheck={false} /></label>
673 <Copy value={login().password} label="guest password"><KeyRound size={14} aria-hidden="true" />Copy password</Copy>675 <Copy value={credentials().password} label="guest password"><KeyRound size={14} aria-hidden="true" />Copy password</Copy>
674 </VMMenu>}</Show>676 </VMMenu>}</Show>
675 </>} />677 </>} />
676 </section>}</Show>;678 </section>}</Show>;