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) { -