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) {
115115 };
116116 let downstream = async {
117117 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);
118120 loop {
119 let count = read.read(&mut buffer).await?;
120 if count == 0 {
121 break;
122 }
123 send.send(Message::Binary(Bytes::copy_from_slice(&buffer[..count])))
124 .await
121 let message = tokio::select! {
122 result = read.read(&mut buffer) => {
123 let count = result?;
124 if count == 0 { break; }
125 Message::Binary(Bytes::copy_from_slice(&buffer[..count]))
126 }
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)?
125131 .map_err(std::io::Error::other)?;
126132 }
127133 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
2121 const enabled = createMemo(() => props.enabled);
2222 const preparing = () => !!props.setup && props.setup !== "ready";
2323 let reconnectTimer: number | undefined;
24 let retryDelay = 1000;
2425 let attempt = 0;
2526 let video!: HTMLVideoElement;
2627 let canvas!: HTMLCanvasElement;
......@@ -185,15 +186,17 @@ export function VMConsole(props: { name: string; platform: Domain["platform"]; e
185186 if (current !== attempt || disposed) return;
186187 setState("Disconnected");
187188 disconnect();
188 if (preparing() && props.setup !== "failed") {
189 setProblem("");
190 reconnectTimer = window.setTimeout(connect, 1000);
191 } else setProblem(message);
189 setProblem(preparing() && props.setup !== "failed" ? "" : message);
190 if (enabled() && props.setup !== "failed") {
191 reconnectTimer = window.setTimeout(connect, retryDelay);
192 retryDelay = Math.min(retryDelay * 2, 30000);
193 }
192194 };
193195 const timeout = window.setTimeout(() => fail("The screen couldn't connect. Reconnect to try again."), 20000);
194196 const ready = () => {
195197 if (current !== attempt || disposed || video.readyState < 2 || input?.readyState !== "open") return;
196198 clearTimeout(timeout);
199 retryDelay = 1000;
197200 setState("Connected");
198201 };
199202 disconnect = () => {
......@@ -352,7 +355,7 @@ export function VMConsole(props: { name: string; platform: Domain["platform"]; e
352355 setProblem("");
353356 }
354357 });
355 createEffect(() => { if (props.active && connected() && !preparing()) video.focus(); else release(); });
358 createEffect(() => { if (!props.active || !connected() || preparing()) release(); });
356359 createEffect(on(() => props.setup, setup => {
357360 if (setup === "ready" && enabled() && state() === "Disconnected") void connect();
358361 }, { defer: true }));
dashboard/web/pages/VMs.css+6
......@@ -132,6 +132,12 @@
132132.vm-active .list-body.flush { margin: 0; padding: 0; overflow: hidden; }
133133.vm-active .list-body.flush > .vm-workspace { margin: 0; flex: 1; min-height: 0; }
134134.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}
135141.vm-console-screen[hidden] { display: none; }
136142.vm-workspace .vm-detail { padding: 20px var(--gutter); overflow: auto; flex: 1; min-height: 0; }
137143.vm-menu { position: relative; font-size: 12px; }
dashboard/web/pages/VMs.tsx+6-4
......@@ -633,6 +633,7 @@ export function VMs() {
633633 </>
634634 }>{(name) => {
635635 const [access] = createResource(() => name, (name) => parseResponse(api.vms[":name"].access.$get({ param: { name } })));
636 const login = lastGood(access);
636637 const [consoleOpened, setConsoleOpened] = createSignal(false);
637638 createEffect(() => { if (activeTab() === "console") setConsoleOpened(true); });
638639 return <Show when={latest().domains.find((vm) => vm.name === name)} fallback={
......@@ -644,9 +645,10 @@ export function VMs() {
644645 clipboard={vm().capabilities.includes("clipboard") ? async (text) => { await parseResponse(api.vms[":name"].clipboard.$post({ param: { name }, json: { text } })); } : undefined}
645646 content={(toolbar) => <>
646647 <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>
648649 </>}
649650 toolbar={<>
651 <button class="button small vm-home" onClick={() => setParams({ vm: undefined, tab: undefined })}>VMs</button>
650652 <TabBar label="VM workspace">
651653 <button aria-pressed={activeTab() === "screen"} onClick={() => setParams({ tab: undefined })}><Monitor size={13} />Screen</button>
652654 <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() {
668670 }}><Disc2 size={14} aria-hidden="true" />Eject ISO</button>
669671 <span class="muted vm-menu-info">{vm().media.find((item) => item.source)?.source ?? "No ISO attached"}</span>
670672 </VMMenu></Show>
671 <Show when={access()}>{(login) => <VMMenu label="Password">
672 <label class="vm-password">Guest password<input aria-label="Guest password" value={login().password} readOnly spellcheck={false} /></label>
673 <Copy value={login().password} label="guest password"><KeyRound size={14} aria-hidden="true" />Copy password</Copy>
673 <Show when={login()}>{(credentials) => <VMMenu label="Password">
674 <label class="vm-password">Guest password<input aria-label="Guest password" value={credentials().password} readOnly spellcheck={false} /></label>
675 <Copy value={credentials().password} label="guest password"><KeyRound size={14} aria-hidden="true" />Copy password</Copy>
674676 </VMMenu>}</Show>
675677 </>} />
676678 </section>}</Show>;