From f0d0614c2a0b974236387ae6e64239b679ba866b Mon Sep 17 00:00:00 2001 From: Ari <149393150+A21-devs@users.noreply.github.com> Date: Thu, 3 Dec 2026 13:23:05 -0500 Subject: [PATCH 1/4] Send the profile's tag with launch and delete work vm:work only carried the kind of work, so after the Profiles tab was remounted it couldn't tell which profile was launching or being deleted. Profiles.exclusive now takes the tag for those two, vm:work sends it, and vmWork() answers { work, tags } so a reloaded window knows too. A save has no tag, its profile doesn't exist yet. --- src/main/ipc.ts | 8 ++++---- src/main/profiles.ts | 19 ++++++++++++++----- src/shared/ipc.ts | 14 +++++++++++--- tests/profileSave.test.ts | 27 ++++++++++++++++++++++++++- 4 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/main/ipc.ts b/src/main/ipc.ts index cc4e1d8..80b9427 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -3,7 +3,7 @@ import { existsSync, readFileSync } from 'node:fs' import { cpus, totalmem } from 'node:os' import { isAbsolute } from 'node:path' import { defaultConfig, validPort, type VmConfig } from '@shared/config' -import { workText, type AppSettings, type AutostartIssue, type DiskInfo, type DiskWork, type HostInfo, type PowerAction, type Profile, type SaveStateResult, type StartResult, type VmWork } from '@shared/ipc' +import { workText, type AppSettings, type AutostartIssue, type DiskInfo, type DiskWork, type HostInfo, type PowerAction, type Profile, type SaveStateResult, type StartResult, type VmWork, type VmWorkState } from '@shared/ipc' import { agentHibernate } from './agent' import { cloneVm, compactDisk, resizeDisk } from './disks' import { runAutostart } from './autostart' @@ -51,8 +51,8 @@ export function registerIpc(ctx: IpcContext): Backend { const send = (channel: string, payload?: unknown) => getWindow()?.webContents.send(channel, payload) // the renderer and the tray menu both follow which VMs have work running const workListeners = new Set<() => void>() - const announceWork = (name: string, work: VmWork | null) => { - send('vm:work', { name, work }) + const announceWork = (name: string, work: VmWork | null, tag?: string) => { + send('vm:work', { name, work, tag }) for (const cb of workListeners) cb() } const profiles = new Profiles(paths, runner, announceWork) @@ -308,7 +308,7 @@ export function registerIpc(ctx: IpcContext): Backend { ipcMain.handle('states', () => runner.allStates()) const vmWork = (): Record => ({ ...profiles.work(), ...Object.fromEntries(diskWork) }) - ipcMain.handle('vmWork', vmWork) + ipcMain.handle('vmWork', (): VmWorkState => ({ work: vmWork(), tags: profiles.workTags() })) // the Summary tab's live screen ipcMain.handle('preview', async (_e, name: string): Promise => { diff --git a/src/main/profiles.ts b/src/main/profiles.ts index 3c5918c..acc69e1 100644 --- a/src/main/profiles.ts +++ b/src/main/profiles.ts @@ -35,6 +35,8 @@ function cleanLabel(label: string): string { export class Profiles { /** VMs with a take/launch/remove in flight */ private busy = new Map() + /** the profile a launch or delete is working on, so the Profiles tab can mark its row */ + private tags = new Map() /** VMs with an edit in flight. Edits are quick, so a take/launch/remove waits for them instead of refusing */ private editing = new Map>() @@ -42,7 +44,7 @@ export class Profiles { private readonly paths: DataPaths, private readonly runner: VmRunner, /** told when a VM starts or finishes a profile operation, so the toolbar can show it */ - private readonly onWork: (vm: string, work: ProfileWork | null) => void = () => undefined + private readonly onWork: (vm: string, work: ProfileWork | null, tag?: string) => void = () => undefined ) {} private dir(vm: string): string { @@ -53,16 +55,18 @@ export class Profiles { * One profile operation per VM at a time. A take waits minutes for the guest to hibernate, * and a launch or a second take during that would kill it or ask it to hibernate twice. */ - private async exclusive(vm: string, work: ProfileWork, fn: () => Promise): Promise { + private async exclusive(vm: string, work: ProfileWork, fn: () => Promise, tag?: string): Promise { if (this.busy.has(vm)) throw new Error(`${vm} is still busy with another profile. Wait for it to finish.`) this.busy.set(vm, work) - this.onWork(vm, work) + if (tag) this.tags.set(vm, tag) + this.onWork(vm, work, tag) try { // an edit that checked the profile exists could otherwise write its meta entry back after a remove await this.editing.get(vm)?.catch(() => undefined) return await fn() } finally { this.busy.delete(vm) + this.tags.delete(vm) this.onWork(vm, null) } } @@ -82,6 +86,11 @@ export class Profiles { return Object.fromEntries(this.busy) } + /** for a running launch or delete, the profile it works on, by VM */ + workTags(): Record { + return Object.fromEntries(this.tags) + } + private shotFile(vm: string, tag: string): string { checkTag(tag) return join(this.dir(vm), `${tag}.png`) @@ -190,7 +199,7 @@ export class Profiles { /** Rolls back to the profile and boots it. A session profile resumes everything that was open. */ launch(cfg: VmConfig, tag: string, force: boolean): Promise { - return this.exclusive(cfg.name, 'launching', () => this.launchNow(cfg, tag, force)) + return this.exclusive(cfg.name, 'launching', () => this.launchNow(cfg, tag, force), tag) } private async launchNow(cfg: VmConfig, tag: string, force: boolean): Promise { @@ -219,7 +228,7 @@ export class Profiles { } remove(cfg: VmConfig, tag: string): Promise { - return this.exclusive(cfg.name, 'removing', () => this.removeNow(cfg, tag)) + return this.exclusive(cfg.name, 'removing', () => this.removeNow(cfg, tag), tag) } private async removeNow(cfg: VmConfig, tag: string): Promise { diff --git a/src/shared/ipc.ts b/src/shared/ipc.ts index 6af7c25..d5efe3f 100644 --- a/src/shared/ipc.ts +++ b/src/shared/ipc.ts @@ -16,6 +16,14 @@ export type DiskWork = 'cloning' | 'compacting' | 'growing' /** anything long running on a VM that the toolbar has to wait for */ export type VmWork = ProfileWork | DiskWork +/** what vmWork() answers */ +export interface VmWorkState { + /** VMs with a profile operation or disk work running, by name */ + work: Record + /** for a profile launch or delete, the tag of the profile it works on, by VM name */ + tags: Record +} + /** shown instead of the status while a profile operation or disk work runs (toolbar, library, tray) */ export const workLabel = { saving: 'Saving profile', @@ -133,8 +141,8 @@ export interface VmmApi { autostart(): Promise power(name: string, action: PowerAction): Promise states(): Promise - /** VMs with a profile operation or disk work running, by name */ - vmWork(): Promise> + /** VMs with a profile operation or disk work running, and for a launch or delete which profile */ + vmWork(): Promise saveState(name: string): Promise hasSaveState(name: string): Promise discardSaveState(name: string): Promise @@ -183,7 +191,7 @@ export interface VmmApi { onState(cb: (s: VmRuntimeState) => void): () => void onCrash(cb: (c: { name: string; message: string }) => void): () => void /** a VM started (work) or finished (null) a profile operation or disk work */ - onVmWork(cb: (w: { name: string; work: VmWork | null }) => void): () => void + onVmWork(cb: (w: { name: string; work: VmWork | null; tag?: string }) => void): () => void /** every 2 s while VMs run: CPU and memory of each running VM, by name */ onUsage(cb: (u: Record) => void): () => void /** something in host() changed, for now the list of ISOs */ diff --git a/tests/profileSave.test.ts b/tests/profileSave.test.ts index 654514f..c68cca6 100644 --- a/tests/profileSave.test.ts +++ b/tests/profileSave.test.ts @@ -63,10 +63,35 @@ describe('saving a session profile', () => { const take = profiles.take(cfg, 'work', '') expect(profiles.work()).toEqual({ [cfg.name]: 'saving' }) await take.catch(() => undefined) + // a save has no profile yet, so no tag goes with it expect(onWork.mock.calls).toEqual([ - [cfg.name, 'saving'], + [cfg.name, 'saving', undefined], [cfg.name, null] ]) expect(profiles.work()).toEqual({}) + expect(profiles.workTags()).toEqual({}) + }) +}) + +describe('profile work with a tag', () => { + it('says which profile a delete works on until it ends', async () => { + root = mkdtempSync(join(tmpdir(), 'vmm-prof-save-')) + const paths = dataPaths(root) + const cfg = defaultConfig('tag vm', paths.disks) + let release = () => undefined as void + const gate = new Promise((r) => (release = r)) + const runner = { + isRunning: () => false, + img: () => ({ snapshotDelete: async () => gate }) + } + const onWork = vi.fn() + const profiles = new Profiles(paths, runner as unknown as VmRunner, onWork) + const remove = profiles.remove(cfg, 'p1') + expect(profiles.workTags()).toEqual({ [cfg.name]: 'p1' }) + expect(onWork).toHaveBeenLastCalledWith(cfg.name, 'removing', 'p1') + release() + await remove + expect(profiles.workTags()).toEqual({}) + expect(onWork).toHaveBeenLastCalledWith(cfg.name, null) }) }) From a50c3aa00c03f6b62b8a184966260a5a40569b3f Mon Sep 17 00:00:00 2001 From: Ari <149393150+A21-devs@users.noreply.github.com> Date: Thu, 3 Dec 2026 13:23:05 -0500 Subject: [PATCH 2/4] Profiles tab: mark the launching or deleting profile after a remount App keeps the tag from vm:work next to the work and hands it to the Profiles tab. A row shows Launching... or Deleting... whether this tab started it or not, and the hint names the profile. Rows being worked on get aria-busy. --- src/renderer/src/App.tsx | 13 ++++++++++--- src/renderer/src/components/Profiles.tsx | 23 +++++++++++++++++------ src/renderer/src/components/VmDetail.tsx | 4 +++- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index de50fdf..31dcf16 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -30,6 +30,8 @@ export default function App() { const [hibernating, setHibernating] = useState>(new Set()) // profile saves, launches and deletes and disk work, also the ones started from another VM's tabs const [vmWork, setVmWork] = useState>({}) + // for a profile launch or delete, which profile, so the Profiles tab can mark its row + const [workTags, setWorkTags] = useState>({}) const [setupFor, setSetupFor] = useState<{ vm: VmConfig; reason: string } | null>(null) const [dragging, setDragging] = useState(false) const dragDepth = useRef(0) // dragenter/dragleave fire for every child, count them @@ -55,10 +57,14 @@ export default function App() { if (s.status === 'off') setUsage(({ [s.name]: _gone, ...rest }) => rest) if (s.status === 'off') setHibernating((cur) => (cur.has(s.name) ? new Set([...cur].filter((n) => n !== s.name)) : cur)) }) - window.vmm.vmWork().then(setVmWork) - const offWork = window.vmm.onVmWork(({ name, work }) => + window.vmm.vmWork().then((w) => { + setVmWork(w.work) + setWorkTags(w.tags) + }) + const offWork = window.vmm.onVmWork(({ name, work, tag }) => { setVmWork(({ [name]: _done, ...rest }) => (work ? { ...rest, [name]: work } : rest)) - ) + setWorkTags(({ [name]: _done, ...rest }) => (work && tag ? { ...rest, [name]: tag } : rest)) + }) const offCrash = window.vmm.onCrash((c) => toasts.push('error', `${c.name} failed to start`, c.message)) // an ISO was added to or removed from the ISOs folder const offUsage = window.vmm.onUsage((u) => @@ -326,6 +332,7 @@ export default function App() { vm={current} status={status} work={current ? vmWork[current.name] ?? null : null} + workTag={current ? workTags[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 a5db684..4796b6d 100644 --- a/src/renderer/src/components/Profiles.tsx +++ b/src/renderer/src/components/Profiles.tsx @@ -13,6 +13,8 @@ interface Props { * VM is selected and this one comes back, this isn't */ work: VmWork | null + /** for a launch or delete, which profile it is. Marks the right row after the tab was remounted */ + workTag: string | null toast: PushToast /** the guest agent didn't answer, show the one-time setup */ onNeedsSetup: (reason: string) => void @@ -24,7 +26,7 @@ const KIND: Record = { disk: 'disk only, boots fresh' } -export default function Profiles({ vm, status, work, toast, onNeedsSetup }: Props) { +export default function Profiles({ vm, status, work, workTag, toast, onNeedsSetup }: Props) { const [list, setList] = useState(null) const [label, setLabel] = useState('') const [note, setNote] = useState('') @@ -87,11 +89,19 @@ export default function Profiles({ vm, status, work, toast, onNeedsSetup }: Prop } const savingSession = busy === 'take' - // 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 + // work this tab didn't start, or started before it was last unmounted. For a launch or delete + // the backend says which profile, so its row can show it. Every button waits either way const otherWork = busy === null && work !== null + const workProfile = otherWork && workTag ? list?.find((p) => p.tag === workTag) : undefined + /** what is happening to this row's profile, whoever started it */ + const rowWork = (p: Profile): 'launching' | 'removing' | null => + busy === `l${p.tag}` || (otherWork && work === 'launching' && workTag === p.tag) + ? 'launching' + : busy === `d${p.tag}` || (otherWork && work === 'removing' && workTag === p.tag) + ? 'removing' + : null const hint = otherWork - ? `${workLabel[work]} on ${vm.name}. Wait for it to finish.` + ? `${workLabel[work]}${workProfile ? ` "${workProfile.label}"` : ''} 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' @@ -139,7 +149,7 @@ export default function Profiles({ vm, status, work, toast, onNeedsSetup }: Prop ) : (
    {list.map((p) => ( -
  • +
  • {editing === p.tag ? ( @@ -160,6 +170,7 @@ export default function Profiles({ vm, status, work, toast, onNeedsSetup }: Prop {when(p.created)} · {KIND[p.kind]} {p.note && {p.note}} + {rowWork(p) === 'removing' && Deleting…} )}
    @@ -172,7 +183,7 @@ export default function Profiles({ vm, status, work, toast, onNeedsSetup }: Prop onClick={() => launch(p)} title="Go back to this profile and start it" > - {busy === `l${p.tag}` ? 'Launching…' : 'Launch'} + {rowWork(p) === 'launching' ? 'Launching…' : 'Launch'}