diff --git a/config.go b/config.go index f12ab45..ecb0909 100644 --- a/config.go +++ b/config.go @@ -37,7 +37,7 @@ type Config struct { DisplayMaxBrightness int `json:"display_max_brightness"` DisplayDimAfterSec int `json:"display_dim_after_sec"` DisplayOffAfterSec int `json:"display_off_after_sec"` - UsbConfig UsbConfig `json:"usb_config"` + UsbConfig *UsbConfig `json:"usb_config"` } const configPath = "/userdata/kvm_config.json" @@ -50,7 +50,7 @@ var defaultConfig = &Config{ DisplayMaxBrightness: 64, DisplayDimAfterSec: 120, // 2 minutes DisplayOffAfterSec: 1800, // 30 minutes - UsbConfig: UsbConfig{ + UsbConfig: &UsbConfig{ VendorId: "0x1d6b", //The Linux Foundation ProductId: "0x0104", //Multifunction Composite Gadget SerialNumber: "", @@ -90,6 +90,11 @@ func LoadConfig() { return } + // merge the user config with the default config + if loadedConfig.UsbConfig == nil { + loadedConfig.UsbConfig = defaultConfig.UsbConfig + } + config = &loadedConfig } diff --git a/jsonrpc.go b/jsonrpc.go index 1b87465..b1b36c5 100644 --- a/jsonrpc.go +++ b/jsonrpc.go @@ -540,12 +540,12 @@ func rpcSetUsbEmulationState(enabled bool) error { func rpcGetUsbConfig() (UsbConfig, error) { LoadConfig() - return config.UsbConfig, nil + return *config.UsbConfig, nil } func rpcSetUsbConfig(usbConfig UsbConfig) error { LoadConfig() - config.UsbConfig = usbConfig + config.UsbConfig = &usbConfig err := UpdateGadgetConfig() if err != nil {