import { GridCard } from "@/components/Card"; import {useCallback, useEffect, useState} from "react"; import { Button } from "@components/Button"; import LogoBlueIcon from "@/assets/logo-blue.svg"; import LogoWhiteIcon from "@/assets/logo-white.svg"; import Modal from "@components/Modal"; import { InputFieldWithLabel } from "./InputField"; import { useJsonRpc } from "@/hooks/useJsonRpc"; import { useUsbConfigModalStore } from "@/hooks/stores"; export interface UsbConfigState { vendor_id: string; product_id: string; serial_number: string; manufacturer: string; product: string; } export default function USBConfigDialog({ open, setOpen, }: { open: boolean; setOpen: (open: boolean) => void; }) { return ( setOpen(false)}> ); } export function Dialog({ setOpen }: { setOpen: (open: boolean) => void }) { const { modalView, setModalView } = useUsbConfigModalStore(); const [error, setError] = useState(null); const [send] = useJsonRpc(); const handleUsbConfigChange = useCallback((usbConfig: object) => { send("setUsbConfig", { usbConfig }, resp => { if ("error" in resp) { setError(`Failed to update USB Config: ${resp.error.data || "Unknown error"}`); return; } setModalView("updateUsbConfigSuccess"); }); }, [send, setModalView]); return ( {modalView === "updateUsbConfig" && ( setOpen(false)} error={error} /> )} {modalView === "updateUsbConfigSuccess" && ( setOpen(false)} /> )} ); } function UpdateUsbConfigModal({ onSetUsbConfig, onCancel, error, }: { onSetUsbConfig: (usb_config: object) => void; onCancel: () => void; error: string | null; }) { const [usbConfigState, setUsbConfigState] = useState({ vendor_id: '', product_id: '', serial_number: '', manufacturer: '', product: '' }); const [send] = useJsonRpc(); const syncUsbConfig = useCallback(() => { send("getUsbConfig", {}, resp => { if ("error" in resp) { console.error("Failed to load USB Config:", resp.error); } else { setUsbConfigState(resp.result as UsbConfigState); } }); }, [send, setUsbConfigState]); // Load stored usb config from the backend useEffect(() => { syncUsbConfig(); }, [syncUsbConfig]); const handleUsbVendorIdChange = (value: string) => { setUsbConfigState({... usbConfigState, vendor_id: value}) }; const handleUsbProductIdChange = (value: string) => { setUsbConfigState({... usbConfigState, product_id: value}) }; const handleUsbSerialChange = (value: string) => { setUsbConfigState({... usbConfigState, serial_number: value}) }; const handleUsbManufacturer = (value: string) => { setUsbConfigState({... usbConfigState, manufacturer: value}) }; const handleUsbProduct = (value: string) => { setUsbConfigState({... usbConfigState, product: value}) }; return ( USB Emulation Configuration Set custom USB parameters to control how the USB device is emulated. The device will rebind once the parameters are updated. handleUsbVendorIdChange(e.target.value)} /> handleUsbProductIdChange(e.target.value)} /> handleUsbSerialChange(e.target.value)} /> handleUsbManufacturer(e.target.value)} /> handleUsbProduct(e.target.value)} /> onSetUsbConfig(usbConfigState)} /> {error && {error}} ); } function SuccessModal({ headline, description, onClose, }: { headline: string; description: string; onClose: () => void; }) { return ( {headline} {description} ); }
Set custom USB parameters to control how the USB device is emulated. The device will rebind once the parameters are updated.
{error}
{description}