Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/renderer/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
40 changes: 26 additions & 14 deletions src/renderer/src/components/Profiles.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,15 +24,17 @@ const KIND: Record<Profile['kind'], string> = {
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<Profile[] | null>(null)
const [label, setLabel] = useState('')
const [note, setNote] = useState('')
const [busy, setBusy] = useState<string | null>(null)
const [editing, setEditing] = useState<string | null>(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 {
Expand All @@ -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<unknown>, ok?: string) {
setBusy(key)
Expand Down Expand Up @@ -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.`
Expand All @@ -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
Expand All @@ -108,9 +120,9 @@ export default function Profiles({ vm, status, toast, onNeedsSetup }: Props) {
save()
}}
/>
<input placeholder="Note (optional)" aria-label="Profile note" value={note} disabled={busy !== null} onChange={(e) => setNote(e.target.value)} />
<input placeholder="Note (optional)" aria-label="Profile note" value={note} disabled={held} onChange={(e) => setNote(e.target.value)} />
<button className="btn primary" disabled={!canTake} onClick={save}>
<Camera size={14} /> {busy === 'take' || busy === 'take-disk' ? 'Saving…' : 'Save profile'}
<Camera size={14} /> {busy === 'take' || busy === 'take-disk' || (otherWork && work === 'saving') ? 'Saving…' : 'Save profile'}
</button>
</div>
{savingSession && <p className="muted saving-note">{vm.name} is writing everything to its disk. This can take a minute with a lot of RAM.</p>}
Expand Down Expand Up @@ -156,20 +168,20 @@ export default function Profiles({ vm, status, toast, onNeedsSetup }: Props) {
<button
className="btn small primary"
aria-label={`Launch ${p.label}`}
disabled={busy !== null || status === 'starting'}
disabled={held || status === 'starting'}
onClick={() => launch(p)}
title="Go back to this profile and start it"
>
<Play size={13} /> {busy === `l${p.tag}` ? 'Launching…' : 'Launch'}
</button>
<button className="icon-btn" aria-label={`Edit ${p.label}`} title="Rename or change the note" disabled={busy !== null} onClick={() => setEditing(p.tag)}>
<button className="icon-btn" aria-label={`Edit ${p.label}`} title="Rename or change the note" disabled={held} onClick={() => setEditing(p.tag)}>
<Pencil size={14} />
</button>
<button
className="icon-btn danger"
aria-label={`Delete ${p.label}`}
title="Delete"
disabled={busy !== null}
disabled={held}
onClick={() => confirm(`Delete the profile "${p.label}"?`) && act(`d${p.tag}`, () => window.vmm.deleteProfile(vm.name, p.tag), 'Profile deleted')}
>
<Trash2 size={14} />
Expand Down
13 changes: 7 additions & 6 deletions src/renderer/src/components/VmDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useRef, useState } from 'react'
import { validateVmName, type VmConfig } from '@shared/config'
import type { HostInfo, VmStatus, VmUsage } from '@shared/ipc'
import type { HostInfo, VmStatus, VmUsage, VmWork } from '@shared/ipc'
import OsMark from './OsMark'
import Hardware from './Hardware'
import LogView from './LogView'
Expand All @@ -9,7 +9,7 @@ import { forwardError } from './PortForwards'
import Profiles from './Profiles'
import Sparkline from './Sparkline'
import type { PushToast } from './Toasts'
import { errText, fileName, gb, statusLabel } from '../util'
import { errText, fileName, gb, statusLabel, workLabel } from '../util'

interface Props {
vm: VmConfig
Expand All @@ -21,8 +21,8 @@ interface Props {
onSave: (cfg: VmConfig, previousName?: string) => void
onCancelDraft: () => void
onDelete: (name: string) => void
/** a profile operation running on this VM, shown instead of the status */
work: string | null
/** a profile operation or disk work running on this VM, shown instead of the status */
work: VmWork | null
onDirtyChange: (dirty: boolean) => void
toast: PushToast
onNeedsSetup: (reason: string) => void
Expand All @@ -39,7 +39,8 @@ const TABS: { id: Tab; label: string }[] = [
]

export default function VmDetail(props: Props) {
const { vm, isDraft, status, work, host, onSave, onCancelDraft, onDelete, onDirtyChange } = props
const { vm, isDraft, status, host, onSave, onCancelDraft, onDelete, onDirtyChange } = props
const work = props.work ? workLabel[props.work] : null
const [tab, setTab] = useState<Tab>(isDraft ? 'hardware' : 'summary')
const [form, setForm] = useState<VmConfig>(vm)
useEffect(() => setForm(vm), [vm])
Expand Down Expand Up @@ -124,7 +125,7 @@ export default function VmDetail(props: Props) {
onDiskChanged={props.onDiskChanged}
/>
)}
{tab === 'profiles' && <Profiles vm={vm} status={status} toast={props.toast} onNeedsSetup={props.onNeedsSetup} />}
{tab === 'profiles' && <Profiles vm={vm} status={status} work={props.work} toast={props.toast} onNeedsSetup={props.onNeedsSetup} />}
{tab === 'log' && <LogView name={vm.name} status={status} toast={props.toast} />}
</div>
</main>
Expand Down
Loading