| author | |
| committer | |
| log | a59184893f02f890bfcc387205db09907351ee35 |
| tree | 2f82c275aa679644c7231d6f01f20c815629adde |
| parent | f8f091ba7269f62f2a325083a02ed25ef1de77f2 |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
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-astra4 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 | 115 | }; |
| 116 | 116 | let downstream = async { |
| 117 | 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 | 120 | 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)? | |
| 125 | 131 | .map_err(std::io::Error::other)?; |
| 126 | 132 | } |
| 127 | 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 | 21 | const enabled = createMemo(() => props.enabled); |
| 22 | 22 | const preparing = () => !!props.setup && props.setup !== "ready"; |
| 23 | 23 | let reconnectTimer: number | undefined; |
| 24 | let retryDelay = 1000; | |
| 24 | 25 | let attempt = 0; |
| 25 | 26 | let video!: HTMLVideoElement; |
| 26 | 27 | let canvas!: HTMLCanvasElement; |
| ... | ... | @@ -185,15 +186,17 @@ export function VMConsole(props: { name: string; platform: Domain["platform"]; e |
| 185 | 186 | if (current !== attempt || disposed) return; |
| 186 | 187 | setState("Disconnected"); |
| 187 | 188 | 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 | } | |
| 192 | 194 | }; |
| 193 | 195 | const timeout = window.setTimeout(() => fail("The screen couldn't connect. Reconnect to try again."), 20000); |
| 194 | 196 | const ready = () => { |
| 195 | 197 | if (current !== attempt || disposed || video.readyState < 2 || input?.readyState !== "open") return; |
| 196 | 198 | clearTimeout(timeout); |
| 199 | retryDelay = 1000; | |
| 197 | 200 | setState("Connected"); |
| 198 | 201 | }; |
| 199 | 202 | disconnect = () => { |
| ... | ... | @@ -352,7 +355,7 @@ export function VMConsole(props: { name: string; platform: Domain["platform"]; e |
| 352 | 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 | 359 | createEffect(on(() => props.setup, setup => { |
| 357 | 360 | if (setup === "ready" && enabled() && state() === "Disconnected") void connect(); |
| 358 | 361 | }, { defer: true })); |
dashboard/web/pages/VMs.css+6| ... | ... | @@ -132,6 +132,12 @@ |
| 132 | 132 | .vm-active .list-body.flush { margin: 0; padding: 0; overflow: hidden; } |
| 133 | 133 | .vm-active .list-body.flush > .vm-workspace { margin: 0; flex: 1; min-height: 0; } |
| 134 | 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 | 141 | .vm-console-screen[hidden] { display: none; } |
| 136 | 142 | .vm-workspace .vm-detail { padding: 20px var(--gutter); overflow: auto; flex: 1; min-height: 0; } |
| 137 | 143 | .vm-menu { position: relative; font-size: 12px; } |
dashboard/web/pages/VMs.tsx+6-4| ... | ... | @@ -633,6 +633,7 @@ export function VMs() { |
| 633 | 633 | </> |
| 634 | 634 | }>{(name) => { |
| 635 | 635 | const [access] = createResource(() => name, (name) => parseResponse(api.vms[":name"].access.$get({ param: { name } }))); |
| 636 | const login = lastGood(access); | |
| 636 | 637 | const [consoleOpened, setConsoleOpened] = createSignal(false); |
| 637 | 638 | createEffect(() => { if (activeTab() === "console") setConsoleOpened(true); }); |
| 638 | 639 | return <Show when={latest().domains.find((vm) => vm.name === name)} fallback={ |
| ... | ... | @@ -644,9 +645,10 @@ export function VMs() { |
| 644 | 645 | clipboard={vm().capabilities.includes("clipboard") ? async (text) => { await parseResponse(api.vms[":name"].clipboard.$post({ param: { name }, json: { text } })); } : undefined} |
| 645 | 646 | content={(toolbar) => <> |
| 646 | 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 | 650 | toolbar={<> |
| 651 | <button class="button small vm-home" onClick={() => setParams({ vm: undefined, tab: undefined })}>VMs</button> | |
| 650 | 652 | <TabBar label="VM workspace"> |
| 651 | 653 | <button aria-pressed={activeTab() === "screen"} onClick={() => setParams({ tab: undefined })}><Monitor size={13} />Screen</button> |
| 652 | 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 | 670 | }}><Disc2 size={14} aria-hidden="true" />Eject ISO</button> |
| 669 | 671 | <span class="muted vm-menu-info">{vm().media.find((item) => item.source)?.source ?? "No ISO attached"}</span> |
| 670 | 672 | </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> | |
| 674 | 676 | </VMMenu>}</Show> |
| 675 | 677 | </>} /> |
| 676 | 678 | </section>}</Show>; |