mirror of https://github.com/jetkvm/kvm.git
added rpc function to get usb config
now loads usb config values to set input values
This commit is contained in:
parent
f67b4c1fbc
commit
f7eba7c257
|
@ -478,6 +478,11 @@ func rpcSetUsbEmulationState(enabled bool) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func rpcGetUsbConfig() (UsbConfig, error) {
|
||||||
|
LoadConfig()
|
||||||
|
return config.UsbConfig, nil
|
||||||
|
}
|
||||||
|
|
||||||
func rpcSetUsbConfig(usbConfig UsbConfig) error {
|
func rpcSetUsbConfig(usbConfig UsbConfig) error {
|
||||||
LoadConfig()
|
LoadConfig()
|
||||||
config.UsbConfig = usbConfig
|
config.UsbConfig = usbConfig
|
||||||
|
@ -560,6 +565,7 @@ var rpcHandlers = map[string]RPCHandler{
|
||||||
"isUpdatePending": {Func: rpcIsUpdatePending},
|
"isUpdatePending": {Func: rpcIsUpdatePending},
|
||||||
"getUsbEmulationState": {Func: rpcGetUsbEmulationState},
|
"getUsbEmulationState": {Func: rpcGetUsbEmulationState},
|
||||||
"setUsbEmulationState": {Func: rpcSetUsbEmulationState, Params: []string{"enabled"}},
|
"setUsbEmulationState": {Func: rpcSetUsbEmulationState, Params: []string{"enabled"}},
|
||||||
|
"getUsbConfig": {Func: rpcGetUsbConfig},
|
||||||
"setUsbConfig": {Func: rpcSetUsbConfig, Params: []string{"usbConfig"}},
|
"setUsbConfig": {Func: rpcSetUsbConfig, Params: []string{"usbConfig"}},
|
||||||
"checkMountUrl": {Func: rpcCheckMountUrl, Params: []string{"url"}},
|
"checkMountUrl": {Func: rpcCheckMountUrl, Params: []string{"url"}},
|
||||||
"getVirtualMediaState": {Func: rpcGetVirtualMediaState},
|
"getVirtualMediaState": {Func: rpcGetVirtualMediaState},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { GridCard } from "@/components/Card";
|
import { GridCard } from "@/components/Card";
|
||||||
import {useCallback, useState} from "react";
|
import {useCallback, useEffect, useState} from "react";
|
||||||
import { Button } from "@components/Button";
|
import { Button } from "@components/Button";
|
||||||
import LogoBlueIcon from "@/assets/logo-blue.svg";
|
import LogoBlueIcon from "@/assets/logo-blue.svg";
|
||||||
import LogoWhiteIcon from "@/assets/logo-white.svg";
|
import LogoWhiteIcon from "@/assets/logo-white.svg";
|
||||||
|
@ -8,6 +8,14 @@ import { InputFieldWithLabel } from "./InputField";
|
||||||
import { useJsonRpc } from "@/hooks/useJsonRpc";
|
import { useJsonRpc } from "@/hooks/useJsonRpc";
|
||||||
import { useUsbConfigModalStore } from "@/hooks/stores";
|
import { useUsbConfigModalStore } from "@/hooks/stores";
|
||||||
|
|
||||||
|
export interface UsbConfigState {
|
||||||
|
vendor_id: string;
|
||||||
|
product_id: string;
|
||||||
|
serial_number: string;
|
||||||
|
manufacturer: string;
|
||||||
|
product_name: string;
|
||||||
|
}
|
||||||
|
|
||||||
export default function USBConfigDialog({
|
export default function USBConfigDialog({
|
||||||
open,
|
open,
|
||||||
setOpen,
|
setOpen,
|
||||||
|
@ -77,6 +85,25 @@ function UpdateUsbConfigModal({
|
||||||
usb_manufacturer: '',
|
usb_manufacturer: '',
|
||||||
usb_product: '',
|
usb_product: '',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const [usbConfigState, setUsbConfigState] = useState<UsbConfigState>();
|
||||||
|
const [send] = useJsonRpc();
|
||||||
|
|
||||||
|
const syncUsbConfig = useCallback(() => {
|
||||||
|
send("getUsbConfig", {}, resp => {
|
||||||
|
if ("result" in resp) {
|
||||||
|
setUsbConfigState(resp.result as UsbConfigState);
|
||||||
|
} else {
|
||||||
|
console.error("Failed to load USB Config:", resp.error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [send, setUsbConfigState]);
|
||||||
|
|
||||||
|
// Load stored usb config from the backend
|
||||||
|
useEffect(() => {
|
||||||
|
syncUsbConfig();
|
||||||
|
}, [syncUsbConfig]);
|
||||||
|
|
||||||
const handleUsbVendorIdChange = (vendorId: string) => {
|
const handleUsbVendorIdChange = (vendorId: string) => {
|
||||||
setUsbConfig({... usbConfig, usb_vendor_id: vendorId})
|
setUsbConfig({... usbConfig, usb_vendor_id: vendorId})
|
||||||
};
|
};
|
||||||
|
@ -115,35 +142,35 @@ function UpdateUsbConfigModal({
|
||||||
required
|
required
|
||||||
label="Vendor ID"
|
label="Vendor ID"
|
||||||
placeholder="Enter Vendor ID"
|
placeholder="Enter Vendor ID"
|
||||||
value={usbConfig.usb_vendor_id || ""}
|
value={usbConfigState?.vendor_id}
|
||||||
onChange={e => handleUsbVendorIdChange(e.target.value)}
|
onChange={e => handleUsbVendorIdChange(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<InputFieldWithLabel
|
<InputFieldWithLabel
|
||||||
required
|
required
|
||||||
label="Product ID"
|
label="Product ID"
|
||||||
placeholder="Enter Product ID"
|
placeholder="Enter Product ID"
|
||||||
value={usbConfig.usb_product_id || ""}
|
value={usbConfigState?.product_id}
|
||||||
onChange={e => handleUsbProductIdChange(e.target.value)}
|
onChange={e => handleUsbProductIdChange(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<InputFieldWithLabel
|
<InputFieldWithLabel
|
||||||
required
|
required
|
||||||
label="Serial Number"
|
label="Serial Number"
|
||||||
placeholder="Enter Serial Number"
|
placeholder="Enter Serial Number"
|
||||||
value={usbConfig.usb_serial_number || ""}
|
value={usbConfigState?.serial_number}
|
||||||
onChange={e => handleUsbSerialChange(e.target.value)}
|
onChange={e => handleUsbSerialChange(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<InputFieldWithLabel
|
<InputFieldWithLabel
|
||||||
required
|
required
|
||||||
label="Manufacturer"
|
label="Manufacturer"
|
||||||
placeholder="Enter Manufacturer"
|
placeholder="Enter Manufacturer"
|
||||||
value={usbConfig.usb_manufacturer || ""}
|
value={usbConfigState?.manufacturer}
|
||||||
onChange={e => handleUsbManufacturer(e.target.value)}
|
onChange={e => handleUsbManufacturer(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<InputFieldWithLabel
|
<InputFieldWithLabel
|
||||||
required
|
required
|
||||||
label="Product Name"
|
label="Product Name"
|
||||||
placeholder="Enter Product Name"
|
placeholder="Enter Product Name"
|
||||||
value={usbConfig.usb_product || ""}
|
value={usbConfigState?.product_name}
|
||||||
onChange={e => handleUsbProduct(e.target.value)}
|
onChange={e => handleUsbProduct(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<div className="flex gap-x-2">
|
<div className="flex gap-x-2">
|
||||||
|
|
Loading…
Reference in New Issue