From f14278fc99fe56a4e33d6af041b54211298d4ae2 Mon Sep 17 00:00:00 2001 From: Ari <149393150+A21-devs@users.noreply.github.com> Date: Wed, 2 Dec 2026 18:50:03 -0500 Subject: [PATCH] Profiles tab: follow the backend's work, not only its own busy state VmDetail is keyed by the VM name, so selecting another VM and coming back mounted a fresh Profiles tab with busy = null while a save was still running. Save, Launch, Edit and Delete were enabled again and the hint said the VM was off so it would save the disk only. VmDetail now gets the work kind instead of its label and hands it to the Profiles tab. Every button waits while there is work, the Save button says Saving... for a save started before the tab was shown, and the hint says what is running. The list also reloads when work ends, since a disk-only save doesn't change the status. --- src/renderer/src/App.tsx | 2 +- src/renderer/src/components/Profiles.tsx | 40 +++++++++++++++--------- src/renderer/src/components/VmDetail.tsx | 13 ++++---- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 16c9ce4..b03392d 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -326,7 +326,7 @@ export default function App() { vm={current} isDraft={false} status={status} - work={work} + work={current ? vmWork[current.name] ?? null : null} host={host} usage={usage[current.name] ?? []} onSave={onSave} diff --git a/src/renderer/src/components/Profiles.tsx b/src/renderer/src/components/Profiles.tsx index 43b6f69..a5db684 100644 --- a/src/renderer/src/components/Profiles.tsx +++ b/src/renderer/src/components/Profiles.tsx @@ -1,13 +1,18 @@ import { useCallback, useEffect, useState } from 'react' import { Camera, Pencil, Play, Trash2 } from 'lucide-react' import type { VmConfig } from '@shared/config' -import type { Profile, VmStatus } from '@shared/ipc' +import type { Profile, VmStatus, VmWork } from '@shared/ipc' import type { PushToast } from './Toasts' -import { errText, when } from '../util' +import { errText, when, workLabel } from '../util' interface Props { vm: VmConfig status: VmStatus + /** + * what the backend says is running on this VM. The tab's own busy state is lost when another + * VM is selected and this one comes back, this isn't + */ + work: VmWork | null toast: PushToast /** the guest agent didn't answer, show the one-time setup */ onNeedsSetup: (reason: string) => void @@ -19,15 +24,17 @@ const KIND: Record = { disk: 'disk only, boots fresh' } -export default function Profiles({ vm, status, toast, onNeedsSetup }: Props) { +export default function Profiles({ vm, status, work, toast, onNeedsSetup }: Props) { const [list, setList] = useState(null) const [label, setLabel] = useState('') const [note, setNote] = useState('') const [busy, setBusy] = useState(null) const [editing, setEditing] = useState(null) const off = status === 'off' + // started here, or still running from before this tab was last shown, or disk work + const held = busy !== null || work !== null // off saves the disk only. Starting or paused can't do either yet. - const canTake = (status === 'running' || off) && label.trim() !== '' && busy === null + const canTake = (status === 'running' || off) && label.trim() !== '' && !held const load = useCallback(async () => { try { @@ -38,10 +45,11 @@ export default function Profiles({ vm, status, toast, onNeedsSetup }: Props) { } }, [vm.name, toast]) - // saving and launching turn the VM off and on again, so reload on every status change + // saving and launching turn the VM off and on again, so reload on every status change. + // A disk-only save doesn't change the status, it shows up when its work ends useEffect(() => { load() - }, [load, status]) + }, [load, status, work]) async function act(key: string, fn: () => Promise, ok?: string) { setBusy(key) @@ -79,8 +87,12 @@ export default function Profiles({ vm, status, toast, onNeedsSetup }: Props) { } const savingSession = busy === 'take' - const hint = - status === 'running' || savingSession + // work this tab didn't start, or started before it was last unmounted. Which profile it is + // isn't known here, so the hint says what is going on and every button waits + const otherWork = busy === null && work !== null + const hint = otherWork + ? `${workLabel[work]} on ${vm.name}. Wait for it to finish.` + : status === 'running' || savingSession ? `Saves everything that's open in ${vm.name}. It closes for a moment while it saves, then comes right back. Launch the profile any time to return to exactly this point.` : status === 'paused' ? `${vm.name} is paused. Resume it to save a profile, a paused guest can't save itself.` @@ -99,7 +111,7 @@ export default function Profiles({ vm, status, toast, onNeedsSetup }: Props) { aria-label="Profile name" value={label} maxLength={80} - disabled={busy !== null} + disabled={held} onChange={(e) => setLabel(e.target.value)} onKeyDown={(e) => { if (e.key !== 'Enter' || !canTake) return @@ -108,9 +120,9 @@ export default function Profiles({ vm, status, toast, onNeedsSetup }: Props) { save() }} /> - setNote(e.target.value)} /> + setNote(e.target.value)} /> {savingSession &&

{vm.name} is writing everything to its disk. This can take a minute with a lot of RAM.

} @@ -156,20 +168,20 @@ export default function Profiles({ vm, status, toast, onNeedsSetup }: Props) { -