Skip to content

Commit da97a17

Browse files
authored
fix(usb_config): check if usb_config is defined in kvm_config.json (#220)
2 parents 7e6a248 + a60d373 commit da97a17

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

config.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type Config struct {
3737
DisplayMaxBrightness int `json:"display_max_brightness"`
3838
DisplayDimAfterSec int `json:"display_dim_after_sec"`
3939
DisplayOffAfterSec int `json:"display_off_after_sec"`
40-
UsbConfig UsbConfig `json:"usb_config"`
40+
UsbConfig *UsbConfig `json:"usb_config"`
4141
}
4242

4343
const configPath = "/userdata/kvm_config.json"
@@ -50,7 +50,7 @@ var defaultConfig = &Config{
5050
DisplayMaxBrightness: 64,
5151
DisplayDimAfterSec: 120, // 2 minutes
5252
DisplayOffAfterSec: 1800, // 30 minutes
53-
UsbConfig: UsbConfig{
53+
UsbConfig: &UsbConfig{
5454
VendorId: "0x1d6b", //The Linux Foundation
5555
ProductId: "0x0104", //Multifunction Composite Gadget
5656
SerialNumber: "",
@@ -90,6 +90,11 @@ func LoadConfig() {
9090
return
9191
}
9292

93+
// merge the user config with the default config
94+
if loadedConfig.UsbConfig == nil {
95+
loadedConfig.UsbConfig = defaultConfig.UsbConfig
96+
}
97+
9398
config = &loadedConfig
9499
}
95100

jsonrpc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,12 +540,12 @@ func rpcSetUsbEmulationState(enabled bool) error {
540540

541541
func rpcGetUsbConfig() (UsbConfig, error) {
542542
LoadConfig()
543-
return config.UsbConfig, nil
543+
return *config.UsbConfig, nil
544544
}
545545

546546
func rpcSetUsbConfig(usbConfig UsbConfig) error {
547547
LoadConfig()
548-
config.UsbConfig = usbConfig
548+
config.UsbConfig = &usbConfig
549549

550550
err := UpdateGadgetConfig()
551551
if err != nil {

0 commit comments

Comments
 (0)