feat(guesttools): add read-only Windows drive sharing
This commit is contained in:
1 parent
8397d15bc5
commit
d30c694e2f
21 files changed
+1134
-74
No files matched your search
@@ -22,7 +22,7 @@ import {
|
||||
optStatusLabel,
|
||||
parseKernelIrqchip,
|
||||
} from '../lib/optimizations'
|
||||
import { DiskCompactResult, DiskResizeResult, HostReport, Locale, Optimization, SetOpts, ValidationIssue, VMDetail, VMStats } from '../types'
|
||||
import { DiskCompactResult, DiskResizeResult, DriveShareSettings, HostReport, Locale, Optimization, SetOpts, ValidationIssue, VMDetail, VMStats } from '../types'
|
||||
import { Button, IconButton } from '../ui/controls'
|
||||
import { Modal } from '../ui/dialog'
|
||||
import { NumberField, OptionCards, PopupSelect, RangeField, ScreenArt, Segmented, SetGroup, SetRow, SetValue, Switch } from '../ui/settings'
|
||||
@@ -142,6 +142,12 @@ export const SettingsModal: React.FC<Props> = ({ locale, detail, stats, host, op
|
||||
const [diskOpBusy, setDiskOpBusy] = useState<'resize' | 'compact' | ''>('')
|
||||
const [resizeResult, setResizeResult] = useState<DiskResizeResult | null>(null)
|
||||
const [compactResult, setCompactResult] = useState<DiskCompactResult | null>(null)
|
||||
const [driveSettings, setDriveSettings] = useState<DriveShareSettings | null>(null)
|
||||
const [driveBusy, setDriveBusy] = useState(false)
|
||||
const driveBusyRef = useRef(false)
|
||||
const activeVMNameRef = useRef(detail.name)
|
||||
activeVMNameRef.current = detail.name
|
||||
const [driveErr, setDriveErr] = useState('')
|
||||
const pane = useRef<HTMLDivElement>(null)
|
||||
|
||||
const presets = recommendedDisplayPresets(host)
|
||||
@@ -186,6 +192,35 @@ export const SettingsModal: React.FC<Props> = ({ locale, detail, stats, host, op
|
||||
el?.scrollIntoView({ block: 'nearest', behavior: 'smooth' })
|
||||
}, [issues, cat])
|
||||
|
||||
useEffect(() => {
|
||||
let active = true
|
||||
setDriveSettings(null)
|
||||
setDriveErr('')
|
||||
api.GetVMDriveShareSettings(detail.name)
|
||||
.then((settings) => { if (active) setDriveSettings(settings) })
|
||||
.catch((e) => { if (active) setDriveErr(String(e).replace(/^Error:\s*/, '')) })
|
||||
return () => { active = false }
|
||||
}, [detail.name])
|
||||
|
||||
const updateDriveShares = async (enabled: boolean, selected: string[]) => {
|
||||
if (driveBusyRef.current || !driveSettings) return
|
||||
driveBusyRef.current = true
|
||||
const vmName = detail.name
|
||||
setDriveBusy(true)
|
||||
setDriveErr('')
|
||||
try {
|
||||
const next = await api.SetVMDriveShareSettings(vmName, enabled, selected)
|
||||
if (activeVMNameRef.current === vmName) setDriveSettings(next)
|
||||
} catch (e) {
|
||||
if (activeVMNameRef.current === vmName) setDriveErr(String(e).replace(/^Error:\s*/, ''))
|
||||
} finally {
|
||||
driveBusyRef.current = false
|
||||
setDriveBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
const selectedDrives = () => (driveSettings?.drives ?? []).filter((d) => d.selected).map((d) => d.drive)
|
||||
|
||||
const handleSave = async () => {
|
||||
if (busy || changed.length === 0 || localBlock) return
|
||||
setErr('')
|
||||
@@ -593,6 +628,52 @@ export const SettingsModal: React.FC<Props> = ({ locale, detail, stats, host, op
|
||||
}
|
||||
/>
|
||||
</SetGroup>
|
||||
<SetGroup title={tr('driveShareTitle')} note={tr('driveShareReadOnly')}>
|
||||
<SetRow
|
||||
title={tr('driveShareMaster')}
|
||||
desc={tr('driveShareMasterDesc')}
|
||||
control={
|
||||
<Switch
|
||||
label={tr('driveShareMaster')}
|
||||
checked={!!driveSettings?.enabled}
|
||||
disabled={!driveSettings || driveBusy}
|
||||
onChange={(enabled) => void updateDriveShares(enabled, selectedDrives())}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
{driveErr && <div className="notice" role="alert">{driveErr}</div>}
|
||||
{driveSettings?.enabled && selectedDrives().length > 0 &&
|
||||
(detail.guest_tools_agent_version ?? 0) < driveSettings.required_agent_version && (
|
||||
<div className="notice">{tr('driveShareNeedsTools', { version: driveSettings.required_agent_version })}</div>
|
||||
)}
|
||||
{(driveSettings?.drives ?? []).map((drive) => {
|
||||
const title = `Windows (${drive.drive}:)`
|
||||
return (
|
||||
<SetRow
|
||||
key={drive.drive}
|
||||
title={title}
|
||||
desc={drive.system ? tr('driveShareSystem', { root: drive.root }) : tr('driveShareDrive', { root: drive.root })}
|
||||
disabled={!driveSettings?.enabled || driveBusy}
|
||||
reason={!driveSettings?.enabled ? tr('driveShareMasterOff') : undefined}
|
||||
control={
|
||||
<Switch
|
||||
label={title}
|
||||
checked={drive.selected}
|
||||
disabled={driveBusy}
|
||||
onChange={(enabled) => {
|
||||
const next = selectedDrives().filter((letter) => letter !== drive.drive)
|
||||
if (enabled) next.push(drive.drive)
|
||||
void updateDriveShares(driveSettings?.enabled ?? false, next)
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
{driveSettings && driveSettings.drives.length === 0 && (
|
||||
<SetValue title={tr('driveShareTitle')} value={tr('driveShareNoDrives')} />
|
||||
)}
|
||||
</SetGroup>
|
||||
<SetGroup title={tr('catNetwork')}>
|
||||
<SetRow
|
||||
{...rowProps('network')}
|
||||
|
||||
Reference in new issue
Block a user