mirror of
https://github.com/luckfox-eng29/kvm.git
synced 2026-01-18 03:28:19 +01:00
feat(usb): dynamic usb devices config
This commit is contained in:
52
jsonrpc.go
52
jsonrpc.go
@@ -544,19 +544,7 @@ func rpcGetUsbConfig() (UsbConfig, error) {
|
||||
func rpcSetUsbConfig(usbConfig UsbConfig) error {
|
||||
LoadConfig()
|
||||
config.UsbConfig = &usbConfig
|
||||
|
||||
err := UpdateGadgetConfig()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to write gadget config: %w", err)
|
||||
}
|
||||
|
||||
err = SaveConfig()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to save usb config: %w", err)
|
||||
}
|
||||
|
||||
log.Printf("[jsonrpc.go:rpcSetUsbConfig] usb config set to %s", usbConfig)
|
||||
return nil
|
||||
return updateUsbRelatedConfig()
|
||||
}
|
||||
|
||||
func rpcGetWakeOnLanDevices() ([]WakeOnLanDevice, error) {
|
||||
@@ -751,6 +739,41 @@ func rpcSetSerialSettings(settings SerialSettings) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func rpcGetUsbDevices() (UsbDevicesConfig, error) {
|
||||
return *config.UsbDevices, nil
|
||||
}
|
||||
|
||||
func updateUsbRelatedConfig() error {
|
||||
if err := UpdateGadgetConfig(); err != nil {
|
||||
return fmt.Errorf("failed to write gadget config: %w", err)
|
||||
}
|
||||
if err := SaveConfig(); err != nil {
|
||||
return fmt.Errorf("failed to save config: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func rpcSetUsbDevices(usbDevices UsbDevicesConfig) error {
|
||||
config.UsbDevices = &usbDevices
|
||||
return updateUsbRelatedConfig()
|
||||
}
|
||||
|
||||
func rpcSetUsbDeviceState(device string, enabled bool) error {
|
||||
switch device {
|
||||
case "absoluteMouse":
|
||||
config.UsbDevices.AbsoluteMouse = enabled
|
||||
case "relativeMouse":
|
||||
config.UsbDevices.RelativeMouse = enabled
|
||||
case "keyboard":
|
||||
config.UsbDevices.Keyboard = enabled
|
||||
case "massStorage":
|
||||
config.UsbDevices.MassStorage = enabled
|
||||
default:
|
||||
return fmt.Errorf("invalid device: %s", device)
|
||||
}
|
||||
return updateUsbRelatedConfig()
|
||||
}
|
||||
|
||||
func rpcSetCloudUrl(apiUrl string, appUrl string) error {
|
||||
config.CloudURL = apiUrl
|
||||
config.CloudAppURL = appUrl
|
||||
@@ -831,6 +854,9 @@ var rpcHandlers = map[string]RPCHandler{
|
||||
"setATXPowerAction": {Func: rpcSetATXPowerAction, Params: []string{"action"}},
|
||||
"getSerialSettings": {Func: rpcGetSerialSettings},
|
||||
"setSerialSettings": {Func: rpcSetSerialSettings, Params: []string{"settings"}},
|
||||
"getUsbDevices": {Func: rpcGetUsbDevices},
|
||||
"setUsbDevices": {Func: rpcSetUsbDevices, Params: []string{"devices"}},
|
||||
"setUsbDeviceState": {Func: rpcSetUsbDeviceState, Params: []string{"device", "enabled"}},
|
||||
"setCloudUrl": {Func: rpcSetCloudUrl, Params: []string{"apiUrl", "appUrl"}},
|
||||
"getScrollSensitivity": {Func: rpcGetScrollSensitivity},
|
||||
"setScrollSensitivity": {Func: rpcSetScrollSensitivity, Params: []string{"sensitivity"}},
|
||||
|
||||
Reference in New Issue
Block a user