From bffac9a6b51f95eb6273477e69986946200281e9 Mon Sep 17 00:00:00 2001 From: Adrian Date: Sat, 25 Jan 2025 16:56:59 -0600 Subject: [PATCH] cleaned up var names --- config.go | 20 ++++++++++---------- ui/src/components/USBConfigDialog.tsx | 26 +++++++++++++------------- usb.go | 18 +++++++++--------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/config.go b/config.go index 4b067da..bee17df 100644 --- a/config.go +++ b/config.go @@ -12,11 +12,11 @@ type WakeOnLanDevice struct { } type UsbConfig struct { - UsbVendorId string `json:"usb_vendor_id"` - UsbProductId string `json:"usb_product_id"` - UsbSerialNumber string `json:"usb_serial_number"` - UsbManufacturer string `json:"usb_manufacturer"` - UsbProduct string `json:"usb_product"` + VendorId string `json:"vendor_id"` + ProductId string `json:"product_id"` + SerialNumber string `json:"serial_number"` + Manufacturer string `json:"manufacturer"` + Product string `json:"product"` } type Config struct { @@ -39,11 +39,11 @@ var defaultConfig = &Config{ CloudURL: "https://api.jetkvm.com", AutoUpdateEnabled: true, // Set a default value UsbConfig: UsbConfig{ - UsbVendorId: "0x1d6b", //The Linux Foundation - UsbProductId: "0x0104", //Multifunction Composite Gadget¬ - UsbSerialNumber: "", - UsbManufacturer: "JetKVM", - UsbProduct: "JetKVM USB Emulation Device", + VendorId: "0x1d6b", //The Linux Foundation + ProductId: "0x0104", //Multifunction Composite Gadget¬ + SerialNumber: "", + Manufacturer: "JetKVM", + Product: "JetKVM USB Emulation Device", }, } diff --git a/ui/src/components/USBConfigDialog.tsx b/ui/src/components/USBConfigDialog.tsx index 815a58b..316233f 100644 --- a/ui/src/components/USBConfigDialog.tsx +++ b/ui/src/components/USBConfigDialog.tsx @@ -79,11 +79,11 @@ function UpdateUsbConfigModal({ error: string | null; }) { const [usbConfig, setUsbConfig] = useState({ - usb_vendor_id: '', - usb_product_id: '', - usb_serial_number: '', - usb_manufacturer: '', - usb_product: '', + vendor_id: '', + product_id: '', + serial_number: '', + manufacturer: '', + product: '', }) const [usbConfigState, setUsbConfigState] = useState(); @@ -91,11 +91,11 @@ function UpdateUsbConfigModal({ const syncUsbConfig = useCallback(() => { send("getUsbConfig", {}, resp => { - if ("result" in resp) { + if ("error" in resp) { + console.error("Failed to load USB Config:", resp.error); + } else { console.info("Successfully synced USB Config: ", resp.result); setUsbConfigState(resp.result as UsbConfigState); - } else { - console.error("Failed to load USB Config:", resp.error); } }); }, [send, setUsbConfigState]); @@ -106,23 +106,23 @@ function UpdateUsbConfigModal({ }, [syncUsbConfig]); const handleUsbVendorIdChange = (vendorId: string) => { - setUsbConfig({... usbConfig, usb_vendor_id: vendorId}) + setUsbConfig({... usbConfig, vendor_id: vendorId}) }; const handleUsbProductIdChange = (productId: string) => { - setUsbConfig({... usbConfig, usb_product_id: productId}) + setUsbConfig({... usbConfig, product_id: productId}) }; const handleUsbSerialChange = (serialNumber: string) => { - setUsbConfig({... usbConfig, usb_serial_number: serialNumber}) + setUsbConfig({... usbConfig, serial_number: serialNumber}) }; const handleUsbManufacturer = (manufacturer: string) => { - setUsbConfig({... usbConfig, usb_manufacturer: manufacturer}) + setUsbConfig({... usbConfig, manufacturer: manufacturer}) }; const handleUsbProduct = (name: string) => { - setUsbConfig({... usbConfig, usb_product: name}) + setUsbConfig({... usbConfig, product: name}) }; return ( diff --git a/usb.go b/usb.go index e8e0dfa..9125ce2 100644 --- a/usb.go +++ b/usb.go @@ -61,8 +61,8 @@ func init() { func UpdateGadgetConfig() error { LoadConfig() gadgetAttrs := [][]string{ - {"idVendor", config.UsbConfig.UsbVendorId}, - {"idProduct", config.UsbConfig.UsbProductId}, + {"idVendor", config.UsbConfig.VendorId}, + {"idProduct", config.UsbConfig.ProductId}, } err := writeGadgetAttrs(kvmGadgetPath, gadgetAttrs) if err != nil { @@ -72,9 +72,9 @@ func UpdateGadgetConfig() error { log.Printf("Successfully updated usb gadget attributes: %v", gadgetAttrs) strAttrs := [][]string{ - {"serialnumber", config.UsbConfig.UsbSerialNumber}, - {"manufacturer", config.UsbConfig.UsbManufacturer}, - {"product", config.UsbConfig.UsbProduct}, + {"serialnumber", config.UsbConfig.SerialNumber}, + {"manufacturer", config.UsbConfig.Manufacturer}, + {"product", config.UsbConfig.Product}, } gadgetStringsPath := filepath.Join(kvmGadgetPath, "strings", "0x409") err = os.MkdirAll(gadgetStringsPath, 0755) @@ -120,8 +120,8 @@ func writeGadgetConfig() error { LoadConfig() err = writeGadgetAttrs(kvmGadgetPath, [][]string{ {"bcdUSB", "0x0200"}, //USB 2.0 - {"idVendor", config.UsbConfig.UsbVendorId}, - {"idProduct", config.UsbConfig.UsbProductId}, + {"idVendor", config.UsbConfig.VendorId}, + {"idProduct", config.UsbConfig.ProductId}, {"bcdDevice", "0100"}, }) if err != nil { @@ -136,8 +136,8 @@ func writeGadgetConfig() error { err = writeGadgetAttrs(gadgetStringsPath, [][]string{ {"serialnumber", GetDeviceID()}, - {"manufacturer", config.UsbConfig.UsbManufacturer}, - {"product", config.UsbConfig.UsbProduct}, + {"manufacturer", config.UsbConfig.Manufacturer}, + {"product", config.UsbConfig.Product}, }) if err != nil { return err