mirror of https://github.com/jetkvm/kvm.git
usb configuration now preserved on dropdown selector
This commit is contained in:
parent
aade07447f
commit
33a01abba5
|
@ -8,14 +8,7 @@ import { InputFieldWithLabel } from "./InputField";
|
||||||
import { useJsonRpc } from "@/hooks/useJsonRpc";
|
import { useJsonRpc } from "@/hooks/useJsonRpc";
|
||||||
import { useUsbConfigModalStore } from "@/hooks/stores";
|
import { useUsbConfigModalStore } from "@/hooks/stores";
|
||||||
import ExtLink from "@components/ExtLink";
|
import ExtLink from "@components/ExtLink";
|
||||||
|
import { UsbConfigState } from "@/utils"
|
||||||
export interface UsbConfigState {
|
|
||||||
vendor_id: string;
|
|
||||||
product_id: string;
|
|
||||||
serial_number: string;
|
|
||||||
manufacturer: string;
|
|
||||||
product: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function USBConfigDialog({
|
export default function USBConfigDialog({
|
||||||
open,
|
open,
|
||||||
|
|
|
@ -26,6 +26,7 @@ import { LocalDevice } from "@routes/devices.$id";
|
||||||
import { useRevalidator } from "react-router-dom";
|
import { useRevalidator } from "react-router-dom";
|
||||||
import { ShieldCheckIcon } from "@heroicons/react/20/solid";
|
import { ShieldCheckIcon } from "@heroicons/react/20/solid";
|
||||||
import USBConfigDialog from "@components/USBConfigDialog";
|
import USBConfigDialog from "@components/USBConfigDialog";
|
||||||
|
import { UsbConfigState } from "@/utils"
|
||||||
|
|
||||||
export function SettingsItem({
|
export function SettingsItem({
|
||||||
title,
|
title,
|
||||||
|
@ -86,7 +87,6 @@ const edids = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
export default function SettingsSidebar() {
|
export default function SettingsSidebar() {
|
||||||
const setSidebarView = useUiStore(state => state.setSidebarView);
|
const setSidebarView = useUiStore(state => state.setSidebarView);
|
||||||
const settings = useSettingsStore();
|
const settings = useSettingsStore();
|
||||||
|
@ -97,7 +97,7 @@ export default function SettingsSidebar() {
|
||||||
const [jiggler, setJiggler] = useState(false);
|
const [jiggler, setJiggler] = useState(false);
|
||||||
const [edid, setEdid] = useState<string | null>(null);
|
const [edid, setEdid] = useState<string | null>(null);
|
||||||
const [customEdidValue, setCustomEdidValue] = useState<string | null>(null);
|
const [customEdidValue, setCustomEdidValue] = useState<string | null>(null);
|
||||||
const [usbConfigJson, setUsbConfigJson] = useState("");
|
const [usbConfigProduct, setUsbConfigProduct] = useState("");
|
||||||
|
|
||||||
const [isAdopted, setAdopted] = useState(false);
|
const [isAdopted, setAdopted] = useState(false);
|
||||||
const [deviceId, setDeviceId] = useState<string | null>(null);
|
const [deviceId, setDeviceId] = useState<string | null>(null);
|
||||||
|
@ -124,45 +124,84 @@ export default function SettingsSidebar() {
|
||||||
});
|
});
|
||||||
}, [send]);
|
}, [send]);
|
||||||
|
|
||||||
|
const syncUsbConfigProduct = useCallback(() => {
|
||||||
|
send("getUsbConfig", {}, resp => {
|
||||||
|
if ("error" in resp) {
|
||||||
|
console.error("Failed to load USB Config:", resp.error);
|
||||||
|
} else {
|
||||||
|
console.error("syncUsbConfigProduct#getUsbConfig result:", resp.result);
|
||||||
|
const usbConfigState = resp.result as UsbConfigState
|
||||||
|
setUsbConfigProduct(usbConfigState.product);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [send, setUsbConfigProduct]);
|
||||||
|
|
||||||
|
// Load stored usb config product from the backend
|
||||||
|
useEffect(() => {
|
||||||
|
syncUsbConfigProduct();
|
||||||
|
}, [syncUsbConfigProduct]);
|
||||||
|
|
||||||
const usbConfigs = [
|
const usbConfigs = [
|
||||||
{
|
{
|
||||||
value: JSON.stringify({
|
label: "JetKVM Default",
|
||||||
|
value: "JetKVM USB Emulation Device"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Logitech Universal Adapter",
|
||||||
|
value: "Logitech USB Input Device"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Microsoft Wireless MultiMedia Keyboard",
|
||||||
|
value: "Wireless MultiMedia Keyboard"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Dell Multimedia Pro Keyboard",
|
||||||
|
value: "Multimedia Pro Keyboard"
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
interface USBConfig {
|
||||||
|
vendor_id: string;
|
||||||
|
product_id: string;
|
||||||
|
serial_number: string | null;
|
||||||
|
manufacturer: string;
|
||||||
|
product: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
type UsbConfigMap = Record<string, USBConfig>;
|
||||||
|
|
||||||
|
|
||||||
|
const usbConfigData: UsbConfigMap = {
|
||||||
|
"JetKVM USB Emulation Device": {
|
||||||
vendor_id: "0x1d6b",
|
vendor_id: "0x1d6b",
|
||||||
product_id: "0x0104",
|
product_id: "0x0104",
|
||||||
serial_number: deviceId,
|
serial_number: deviceId,
|
||||||
manufacturer: "JetKVM",
|
manufacturer: "JetKVM",
|
||||||
product: "JetKVM USB Emulation Device",
|
product: "JetKVM USB Emulation Device",
|
||||||
}),
|
},
|
||||||
label: "JetKVM Default",
|
"Logitech USB Input Device": {
|
||||||
},
|
|
||||||
{
|
|
||||||
value: JSON.stringify({
|
|
||||||
vendor_id: "0x046d",
|
vendor_id: "0x046d",
|
||||||
product_id: "0xc52b",
|
product_id: "0xc52b",
|
||||||
|
serial_number: generatedSerialNumber,
|
||||||
manufacturer: "Logitech (x64)",
|
manufacturer: "Logitech (x64)",
|
||||||
product: "Logitech USB Input Device",
|
product: "Logitech USB Input Device",
|
||||||
}),
|
},
|
||||||
label: "Logitech Universal Adapter",
|
"Wireless MultiMedia Keyboard": {
|
||||||
},
|
|
||||||
{
|
|
||||||
value: JSON.stringify({
|
|
||||||
vendor_id: "0x045e",
|
vendor_id: "0x045e",
|
||||||
product_id: "0x005f",
|
product_id: "0x005f",
|
||||||
|
serial_number: generatedSerialNumber,
|
||||||
manufacturer: "Microsoft",
|
manufacturer: "Microsoft",
|
||||||
product: "Wireless MultiMedia Keyboard",
|
product: "Wireless MultiMedia Keyboard",
|
||||||
}),
|
},
|
||||||
label: "Microsoft Wireless MultiMedia Keyboard",
|
"Multimedia Pro Keyboard": {
|
||||||
},
|
|
||||||
{
|
|
||||||
value: JSON.stringify({
|
|
||||||
vendor_id: "0x413c",
|
vendor_id: "0x413c",
|
||||||
product_id: "0x2011",
|
product_id: "0x2011",
|
||||||
|
serial_number: generatedSerialNumber,
|
||||||
manufacturer: "Dell Inc.",
|
manufacturer: "Dell Inc.",
|
||||||
product: "Multimedia Pro Keyboard",
|
product: "Multimedia Pro Keyboard",
|
||||||
}),
|
}
|
||||||
label: "Dell Multimedia Pro Keyboard",
|
}
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
const handleUsbEmulationToggle = useCallback(
|
const handleUsbEmulationToggle = useCallback(
|
||||||
(enabled: boolean) => {
|
(enabled: boolean) => {
|
||||||
|
@ -237,12 +276,9 @@ export default function SettingsSidebar() {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleUsbConfigChange = (jsonString: string) => {
|
const handleUsbConfigChange = (product: string) => {
|
||||||
const usbConfig = JSON.parse(jsonString);
|
const usbConfig = usbConfigData[product];
|
||||||
if (!usbConfig?.serial_number) {
|
console.info(`USB config: ${JSON.stringify(usbConfig)}`)
|
||||||
usbConfig['serial_number'] = generatedSerialNumber
|
|
||||||
}
|
|
||||||
console.info(`Current USB serial number: ${usbConfig?.serial_number}`)
|
|
||||||
send("setUsbConfig", { usbConfig }, resp => {
|
send("setUsbConfig", { usbConfig }, resp => {
|
||||||
if ("error" in resp) {
|
if ("error" in resp) {
|
||||||
notifications.error(
|
notifications.error(
|
||||||
|
@ -250,8 +286,8 @@ export default function SettingsSidebar() {
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setUsbConfigJson(jsonString);
|
setUsbConfigProduct(usbConfig.product);
|
||||||
notifications.success(`USB Config set to ${usbConfig.product}`);
|
notifications.success(`USB Config set to ${usbConfig.manufacturer} ${usbConfig.product}`);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -939,10 +975,10 @@ export default function SettingsSidebar() {
|
||||||
size="SM"
|
size="SM"
|
||||||
label=""
|
label=""
|
||||||
fullWidth
|
fullWidth
|
||||||
value={usbConfigJson}
|
value={usbConfigProduct}
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
if (e.target.value === "custom") {
|
if (e.target.value === "custom") {
|
||||||
setUsbConfigJson(e.target.value);
|
setUsbConfigProduct(e.target.value);
|
||||||
} else {
|
} else {
|
||||||
handleUsbConfigChange(e.target.value as string);
|
handleUsbConfigChange(e.target.value as string);
|
||||||
}
|
}
|
||||||
|
@ -951,7 +987,7 @@ export default function SettingsSidebar() {
|
||||||
/>
|
/>
|
||||||
</SettingsItem>
|
</SettingsItem>
|
||||||
)}
|
)}
|
||||||
{usbConfigJson == "custom" && (
|
{usbConfigProduct === "custom" && (
|
||||||
<SettingsItem
|
<SettingsItem
|
||||||
title="USB Config"
|
title="USB Config"
|
||||||
description="Set Custom USB Descriptors"
|
description="Set Custom USB Descriptors"
|
||||||
|
|
|
@ -232,3 +232,11 @@ export function isChromeOS() {
|
||||||
/* ChromeOS sets navigator.platform to Linux :/ */
|
/* ChromeOS sets navigator.platform to Linux :/ */
|
||||||
return !!navigator.userAgent.match(" CrOS ");
|
return !!navigator.userAgent.match(" CrOS ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UsbConfigState {
|
||||||
|
vendor_id: string;
|
||||||
|
product_id: string;
|
||||||
|
serial_number: string;
|
||||||
|
manufacturer: string;
|
||||||
|
product: string;
|
||||||
|
}
|
Loading…
Reference in New Issue