Merge pull request #183 from reiasu2/fix/capture-compat-input-ui
fix(input): adapt to runtimes without --capture and clarify modifier key settings
This commit is contained in:
22 files changed
+593
-68
No files matched your search
@@ -53,6 +53,7 @@ interface Props {
|
||||
locale: Locale
|
||||
host: HostReport
|
||||
fixedModeSupported?: boolean
|
||||
captureSupported?: boolean
|
||||
tasks?: Task[]
|
||||
draft?: WizardDraft | null
|
||||
onClose: () => void
|
||||
@@ -80,7 +81,7 @@ const SOURCES: { mode: 'offline' | 'apple' | 'installer' | 'disk'; icon: LucideI
|
||||
{ mode: 'disk', icon: HardDrive, title: 'srcDiskTitle', sub: 'srcDiskSub' },
|
||||
]
|
||||
|
||||
export const CreateWizard: React.FC<Props> = ({ locale, host, fixedModeSupported = false, tasks = [], draft, onClose, onSubmit }) => {
|
||||
export const CreateWizard: React.FC<Props> = ({ locale, host, fixedModeSupported = false, captureSupported = false, tasks = [], draft, onClose, onSubmit }) => {
|
||||
const tr = (k: I18nKey, v?: Record<string, string | number>) => t(locale, k, v)
|
||||
const [step, setStep] = useState(draft?.step ?? 1)
|
||||
// Once the user has reached the review step, keep validating so step markers stay current.
|
||||
@@ -126,7 +127,7 @@ export const CreateWizard: React.FC<Props> = ({ locale, host, fixedModeSupported
|
||||
resolution: recommendedResolution(host),
|
||||
displays: 1,
|
||||
borderless: false,
|
||||
capture: false,
|
||||
...(captureSupported ? { capture: false } : {}),
|
||||
audio: true,
|
||||
network: false,
|
||||
network_mode: 'off',
|
||||
@@ -159,6 +160,9 @@ export const CreateWizard: React.FC<Props> = ({ locale, host, fixedModeSupported
|
||||
|
||||
const buildPayload = (): CreateOpts => {
|
||||
const p: CreateOpts = { ...opts, offline: opts.source_mode === 'offline' }
|
||||
if (!captureSupported) {
|
||||
delete p.capture
|
||||
}
|
||||
if (p.source_mode === 'offline') {
|
||||
p.installer = ''
|
||||
p.disk = ''
|
||||
@@ -229,7 +233,7 @@ export const CreateWizard: React.FC<Props> = ({ locale, host, fixedModeSupported
|
||||
.finally(() => { if (live) setChecking(false) })
|
||||
}, 200)
|
||||
return () => { live = false; clearTimeout(timer) }
|
||||
}, [step, reviewed, opts, validationRefresh])
|
||||
}, [step, reviewed, opts, validationRefresh, captureSupported])
|
||||
|
||||
const pickDir = async () => {
|
||||
const dir = await api.PickDirectory(tr('vmDir'))
|
||||
@@ -668,11 +672,13 @@ export const CreateWizard: React.FC<Props> = ({ locale, host, fixedModeSupported
|
||||
title={tr('enableAudio')}
|
||||
control={<Switch label={tr('enableAudio')} checked={!!opts.audio} onChange={(audio) => set({ audio })} />}
|
||||
/>
|
||||
<SetRow
|
||||
title={tr('captureInput')}
|
||||
desc={tr('captureInputHint')}
|
||||
control={<Switch label={tr('captureInput')} checked={!!opts.capture} onChange={(capture) => set({ capture })} />}
|
||||
/>
|
||||
{captureSupported && (
|
||||
<SetRow
|
||||
title={tr('captureInput')}
|
||||
desc={tr('captureInputHint')}
|
||||
control={<Switch label={tr('captureInput')} checked={!!opts.capture} onChange={(capture) => set({ capture })} />}
|
||||
/>
|
||||
)}
|
||||
<SetRow
|
||||
title={tr('fullscreenLaunch')}
|
||||
desc={opts.borderless ? tr('fullscreenDecoupledHint') : tr('fullscreenLaunchHint')}
|
||||
@@ -702,6 +708,7 @@ export const CreateWizard: React.FC<Props> = ({ locale, host, fixedModeSupported
|
||||
locale={locale}
|
||||
host={host}
|
||||
opts={opts}
|
||||
captureSupported={captureSupported}
|
||||
networkUplink={networkAdapters?.find((adapter) => adapter.guid === opts.uplink_guid)?.name}
|
||||
issues={issues}
|
||||
checking={checking}
|
||||
@@ -765,6 +772,7 @@ interface ReviewProps {
|
||||
locale: Locale
|
||||
host: HostReport
|
||||
opts: CreateOpts
|
||||
captureSupported: boolean
|
||||
issues: ValidationIssue[]
|
||||
checking: boolean
|
||||
command: string
|
||||
@@ -780,7 +788,7 @@ type Row = { label: string; value: string; mono?: boolean }
|
||||
const fileName = (p?: string) => (p ?? '').split(/[\\/]/).pop() || (p ?? '')
|
||||
|
||||
/** Step ⑤: what will be created, grouped by the step that set it, with the CLI equivalent folded away. */
|
||||
const Review: React.FC<ReviewProps> = ({ locale, host, opts, issues, checking, command, onEdit, onName, onDir, onPickDir, onStartAfter, networkUplink }) => {
|
||||
const Review: React.FC<ReviewProps> = ({ locale, host, opts, captureSupported, issues, checking, command, onEdit, onName, onDir, onPickDir, onStartAfter, networkUplink }) => {
|
||||
const tr = (k: I18nKey, v?: Record<string, string | number>) => t(locale, k, v)
|
||||
const [copied, setCopied] = useState(false)
|
||||
const onOff = (b?: boolean) => tr(b ? 'summaryOn' : 'off')
|
||||
@@ -835,7 +843,7 @@ const Review: React.FC<ReviewProps> = ({ locale, host, opts, issues, checking, c
|
||||
...graphicsRows,
|
||||
{ label: tr('fieldAudio'), value: onOff(opts.audio) },
|
||||
{ label: tr('fieldNetwork'), value: opts.network_mode === 'bridge' ? `${tr('networkBridge')} · ${networkUplink ?? tr('bridgeUplink')}` : tr((opts.network_mode ?? (opts.network ? 'nat' : 'off')) === 'off' ? 'off' : 'networkNAT') },
|
||||
{ label: tr('captureInput'), value: onOff(opts.capture) },
|
||||
...(captureSupported ? [{ label: tr('captureInput'), value: onOff(opts.capture) }] : []),
|
||||
{ label: tr('summarySSH'), value: opts.ssh_port ? tr('summarySSHPort', { n: opts.ssh_port }) : tr('off') },
|
||||
{ label: tr('summaryLogs'), value: onOff(opts.logs) },
|
||||
],
|
||||
|
||||
@@ -123,7 +123,7 @@ function baseline(detail: VMDetail, host: HostReport): SetOpts {
|
||||
disk_cache: (detail.disk_cache as DiskCache) || 'default',
|
||||
resolution: detail.resolution,
|
||||
borderless: detail.borderless,
|
||||
capture: detail.capture,
|
||||
...(detail.capture_supported ? { capture: detail.capture } : {}),
|
||||
gpu: icd ?? (detail.gpu || 'auto'),
|
||||
logs: detail.logs,
|
||||
log_level: detail.log_level,
|
||||
@@ -206,13 +206,22 @@ export const SettingsModal: React.FC<Props> = ({ locale, detail, driverID, stats
|
||||
setCustomLog(!!base.log_level && !(LOG_LEVELS as readonly string[]).includes(base.log_level))
|
||||
}, [base])
|
||||
|
||||
useEffect(() => {
|
||||
setForm((f) => {
|
||||
if (!detail.capture_supported) {
|
||||
return f.capture === undefined ? f : { ...f, capture: undefined }
|
||||
}
|
||||
return f.capture === undefined ? { ...f, capture: detail.capture } : f
|
||||
})
|
||||
}, [detail.capture_supported, detail.capture])
|
||||
|
||||
const set = (patch: Partial<SetOpts>) => {
|
||||
edited.current = true
|
||||
setForm((f) => ({ ...f, ...patch }))
|
||||
const touched = Object.keys(patch)
|
||||
setIssues((list) => list.filter((i) => !touched.includes(i.field)))
|
||||
}
|
||||
const dirty = (f: Field) => !same(f, form[f], base[f])
|
||||
const dirty = (f: Field) => (f === 'capture' && !detail.capture_supported ? false : !same(f, form[f], base[f]))
|
||||
const reset = (f: Field) => () => {
|
||||
set({ [f]: base[f] } as Partial<SetOpts>)
|
||||
if (f === 'resolution' || f === 'borderless') setCustomRes(false)
|
||||
@@ -741,15 +750,17 @@ export const SettingsModal: React.FC<Props> = ({ locale, detail, driverID, stats
|
||||
|
||||
const input = (
|
||||
<>
|
||||
<SetGroup title={tr('catInput')}>
|
||||
<SetRow
|
||||
{...rowProps('capture')}
|
||||
title={tr('captureInput')}
|
||||
desc={tr('captureInputHint')}
|
||||
control={<Switch label={tr('captureInput')} checked={!!form.capture} onChange={(capture) => set({ capture })} />}
|
||||
/>
|
||||
</SetGroup>
|
||||
<KeymapSection locale={locale} vm={detail.name} state={keymap} />
|
||||
{detail.capture_supported && (
|
||||
<SetGroup title={tr('catInput')}>
|
||||
<SetRow
|
||||
{...rowProps('capture')}
|
||||
title={tr('captureInput')}
|
||||
desc={tr('captureInputHint')}
|
||||
control={<Switch label={tr('captureInput')} checked={!!form.capture} onChange={(capture) => set({ capture })} />}
|
||||
/>
|
||||
</SetGroup>
|
||||
)}
|
||||
<KeymapSection locale={locale} vm={detail.name} state={keymap} captureSupported={detail.capture_supported} />
|
||||
<VMPluginGroup locale={locale} group="keyboard" state={plugins} />
|
||||
<SetGroup title={tr('catAudio')} note={tr('audioTroubleshootNote')}>
|
||||
<SetRow
|
||||
|
||||
@@ -534,7 +534,7 @@ export const VMPage: React.FC<Props> = ({
|
||||
<span className="sep">·</span>
|
||||
<kbd>Ctrl+Alt+G</kbd> {tr('shortcutBarRelease')}
|
||||
</p>
|
||||
) : detail.capture ? (
|
||||
) : (!detail.capture_supported || detail.capture) ? (
|
||||
<p className="vm-footnote">
|
||||
<kbd>Ctrl+Alt+Win</kbd> {tr('shortcutBarRelease')}
|
||||
</p>
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
import React, { useEffect, useRef, useState } from 'react'
|
||||
import { I18nKey, t } from '../../i18n'
|
||||
import { createKeymapRequests, keymapPresetUpdate, keymapUpdate, type KeymapState } from '../../lib/vmKeymap'
|
||||
import { createKeymapRequests, keymapPresetUpdate, keymapStatusHint, keymapUpdate, visibleKeymapPresets, type KeymapState } from '../../lib/vmKeymap'
|
||||
import { Locale, VMKeymapGuestModifier, VMKeymapHostModifier, VMKeymapPreset } from '../../types'
|
||||
import { PopupSelect, Segmented, SetGroup, SetRow, Switch } from '../../ui/settings'
|
||||
import { PopupSelect, Segmented, SetGroup, SetRow, SetValue, Switch } from '../../ui/settings'
|
||||
import { api } from '../../wails'
|
||||
|
||||
const PRESET_LABEL: Record<VMKeymapPreset, I18nKey> = {
|
||||
off: 'keymapPresetOff',
|
||||
win_to_cmd: 'keymapPresetWinToCmd',
|
||||
swap_alt_win: 'keymapPresetSwapAltWin',
|
||||
custom: 'keymapPresetCustom',
|
||||
}
|
||||
|
||||
/** The VM's modifier key mapping, refreshed while shown. */
|
||||
export function useKeymap(vm: string, running: boolean, shown: boolean) {
|
||||
const activeVMNameRef = useRef(vm)
|
||||
@@ -28,24 +35,20 @@ export function useKeymap(vm: string, running: boolean, shown: boolean) {
|
||||
return { keymap, keymapErr, keymapBusy, write: keymapRequests.write }
|
||||
}
|
||||
|
||||
export const KeymapSection: React.FC<{ locale: Locale; vm: string; state: ReturnType<typeof useKeymap> }> = ({ locale, vm, state }) => {
|
||||
export const KeymapSection: React.FC<{ locale: Locale; vm: string; state: ReturnType<typeof useKeymap>; captureSupported: boolean }> = ({ locale, vm, state, captureSupported }) => {
|
||||
const tr = (k: I18nKey, v?: Record<string, string | number>) => t(locale, k, v)
|
||||
const { keymap, keymapErr, keymapBusy, write } = state
|
||||
const statusHint = keymap ? keymapStatusHint(keymap) : null
|
||||
const presetOptions = keymap
|
||||
? visibleKeymapPresets(keymap.preset, captureSupported).map((value) => ({ value, label: tr(PRESET_LABEL[value]) }))
|
||||
: []
|
||||
return (
|
||||
<SetGroup title={tr('keymapGroupTitle')} note={tr('keymapGroupNote')}>
|
||||
{keymapErr && <div className="notice notice-error" role="alert">{keymapErr}</div>}
|
||||
{keymap && <>
|
||||
<SetRow title={tr('keymapPresetTitle')} disabled={keymapBusy}
|
||||
desc={keymap.preset === 'off' && !keymap.capture_host_shortcuts ? undefined
|
||||
: !keymap.input_service_available ? tr('keymapInputServiceRequired')
|
||||
: !keymap.running ? tr('keymapStopped')
|
||||
: keymap.needs_guest_tools && !keymap.guest_connected ? tr('keymapWaiting')
|
||||
: keymap.needs_guest_tools && (keymap.guest_agent_version ?? 0) < keymap.required_agent_version
|
||||
? tr('keymapUpgrade', { version: keymap.required_agent_version })
|
||||
: keymap.needs_guest_tools && !keymap.guest_keymap_active ? tr('keymapPending')
|
||||
: tr(keymap.hook_active ? 'keymapRunning' : 'keymapInactive')}
|
||||
<SetRow title={tr('keymapPresetTitle')} desc={tr('keymapPresetDesc')} disabled={keymapBusy}
|
||||
control={<Segmented<VMKeymapPreset> label={tr('keymapPresetTitle')} value={keymap.preset}
|
||||
options={[{ value: 'off', label: tr('keymapPresetOff') }, { value: 'win_to_cmd', label: tr('keymapPresetWinToCmd') }, { value: 'swap_alt_win', label: tr('keymapPresetSwapAltWin') }, { value: 'custom', label: tr('keymapPresetCustom') }]}
|
||||
options={presetOptions}
|
||||
onChange={(preset) => {
|
||||
const request = keymapPresetUpdate(keymap, preset)
|
||||
if (request) void write(vm, request)
|
||||
@@ -55,6 +58,9 @@ export const KeymapSection: React.FC<{ locale: Locale; vm: string; state: Return
|
||||
control={<Switch label={tr('keymapCaptureHostShortcutsTitle')} checked={keymap.capture_host_shortcuts}
|
||||
onChange={(capture_host_shortcuts) => { void write(vm, keymapUpdate(keymap, { capture_host_shortcuts })) }} />}
|
||||
/>
|
||||
{statusHint && (
|
||||
<SetValue title={tr('keymapStatusTitle')} value={tr(statusHint.key, statusHint.vars)} />
|
||||
)}
|
||||
{keymap.preset === 'custom' && ([
|
||||
['lwin', 'keymapHostLwin'],
|
||||
['rwin', 'keymapHostRwin'],
|
||||
|
||||
Reference in new issue
Block a user