chore: cherry pick

This commit is contained in:
jingyuexing
2025-07-14 14:52:48 +08:00
parent 32c81f220d
commit 61ea4bd385
9 changed files with 134 additions and 24 deletions

View File

@@ -11,8 +11,10 @@ type HWVersion int
const (
HWVersionAlpha HWVersion = iota
HWVersionPro
HWVersionBeta
HWVersionPcie
HWVersionATX
HWVersionFile = "/etc/kvm/hw"
)
@@ -41,6 +43,14 @@ var HWPcie = Hardware{
GPIOHDDLed: "",
}
var HWPro = Hardware{
Version: HWVersionPro,
GPIOReset: "/sys/class/gpio/gpio35/value",
GPIOPower: "/sys/class/gpio/gpio7/value",
GPIOPowerLED: "/sys/class/gpio/gpio75/value",
GPIOHDDLed: "/sys/class/gpio/gpio74/value",
}
func (h HWVersion) String() string {
switch h {
case HWVersionAlpha:
@@ -49,29 +59,38 @@ func (h HWVersion) String() string {
return "Beta"
case HWVersionPcie:
return "PCIE"
case HWVersionPro:
return "Pro"
default:
return "Unknown"
}
}
func getHwVersion() HWVersion {
func GetHwVersion() HWVersion {
content, err := os.ReadFile(HWVersionFile)
if err != nil {
return HWVersionAlpha
}
version := strings.ReplaceAll(string(content), "\n", "")
if version == "beta" {
switch version {
case "alpha":
return HWVersionAlpha
case "beta":
return HWVersionBeta
} else if version == "pcie" {
case "pcie":
return HWVersionPcie
case "atx":
return HWVersionATX
case "pro":
return HWVersionPro
default:
return HWVersionAlpha
}
return HWVersionAlpha
}
func getHardware() (h Hardware) {
version := getHwVersion()
version := GetHwVersion()
switch version {
case HWVersionAlpha:
@@ -83,10 +102,12 @@ func getHardware() (h Hardware) {
case HWVersionPcie:
h = HWPcie
case HWVersionPro:
h = HWPro
default:
h = HWAlpha
log.Errorf("Unsupported hardware version: %s", version)
}
return
return h
}

View File

@@ -16,4 +16,8 @@ func applicationRouter(r *gin.Engine) {
api.GET("/application/preview", service.GetPreview) // get preview updates state
api.POST("/application/preview", service.SetPreview) // set preview updates state
api.GET("/application/settings/disabled-items", service.GetDisableItems) // get disable items list
api.GET("/application/menu/disabled-items", service.GetDisableMenus)
}

View File

@@ -0,0 +1,63 @@
package application
import (
"NanoKVM-Server/config"
"NanoKVM-Server/proto"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
)
const (
DeviceTLS = "device:tls"
DeviceSSH = "device:ssh"
DeviceMDNS = "device:mdns"
DeviceHDMI = "device:hdmi"
DeviceWIFI = "device:wifi"
DeviceMouse = "device:mouse"
DeviceReboot = "device:reboot"
DeviceOLED = "device:oled"
DeviceAdvance = "device:advance"
DeviceAdvancedSwap = "device:advance:swap"
)
const (
MenuScript = "script"
MenuImage = "image"
MenuDownload = "download"
MenuTerminal = "terminal"
MenuScreen = "screen"
MenuScreenResolution = "screen:resolution"
)
func (s *Service) GetDisableItems(ctx *gin.Context) {
var rsp proto.Response
switch config.GetHwVersion() {
case config.HWVersionPcie, config.HWVersionATX:
rsp.OkRspWithData(ctx, []string{
DeviceAdvancedSwap,
DeviceAdvance,
MenuScreenResolution,
})
log.Debugf("disable menus items %s", DeviceAdvancedSwap)
return
default:
rsp.OkRspWithData(ctx, []string{})
}
}
func (s *Service) GetDisableMenus(ctx *gin.Context) {
var rsp proto.Response
switch config.GetHwVersion() {
case config.HWVersionPcie, config.HWVersionATX:
rsp.OkRspWithData(ctx, []string{
DeviceAdvancedSwap,
DeviceAdvance,
MenuScreenResolution,
})
log.Debugf("disable menus items %s", DeviceAdvancedSwap)
return
default:
rsp.OkRspWithData(ctx, []string{})
}
}