From 61ea4bd38522085d8b5ed5be71e1a65ea936d0e2 Mon Sep 17 00:00:00 2001 From: jingyuexing <19589872+jingyuexing@users.noreply.github.com> Date: Mon, 14 Jul 2025 14:52:48 +0800 Subject: [PATCH] chore: cherry pick --- server/config/hardware.go | 37 ++++++++--- server/router/application.go | 4 ++ server/service/application/settings.go | 63 +++++++++++++++++++ web/src/api/application.ts | 8 +++ web/src/jotai/settings.ts | 2 + web/src/pages/desktop/menu/index.tsx | 9 ++- web/src/pages/desktop/menu/screen/index.tsx | 9 +-- .../menu/settings/device/advanced/index.tsx | 3 +- .../desktop/menu/settings/device/index.tsx | 23 ++++--- 9 files changed, 134 insertions(+), 24 deletions(-) create mode 100644 server/service/application/settings.go diff --git a/server/config/hardware.go b/server/config/hardware.go index 79d4e2f..1913707 100644 --- a/server/config/hardware.go +++ b/server/config/hardware.go @@ -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 } diff --git a/server/router/application.go b/server/router/application.go index 1c4d269..351e0ce 100644 --- a/server/router/application.go +++ b/server/router/application.go @@ -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) + } diff --git a/server/service/application/settings.go b/server/service/application/settings.go new file mode 100644 index 0000000..9b8ef48 --- /dev/null +++ b/server/service/application/settings.go @@ -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{}) + } +} diff --git a/web/src/api/application.ts b/web/src/api/application.ts index dcb1385..4c69108 100644 --- a/web/src/api/application.ts +++ b/web/src/api/application.ts @@ -26,3 +26,11 @@ export function setPreviewUpdates(enable: boolean) { export function getPreviewUpdates() { return http.get('/api/application/preview'); } + +export function getSettingsDisabledItems() { + return http.get('/api/application/settings/disabled-items'); +} + +export function getMenuDisableItems(){ + return http.get("/api/application/menu/disabled-items") +} diff --git a/web/src/jotai/settings.ts b/web/src/jotai/settings.ts index 82f9e49..6b79508 100644 --- a/web/src/jotai/settings.ts +++ b/web/src/jotai/settings.ts @@ -3,5 +3,7 @@ import { atom } from 'jotai'; // menu bar disabled items export const menuDisabledItemsAtom = atom([]); + // web title export const webTitleAtom = atom(''); + diff --git a/web/src/pages/desktop/menu/index.tsx b/web/src/pages/desktop/menu/index.tsx index 97cc63c..9f651b7 100644 --- a/web/src/pages/desktop/menu/index.tsx +++ b/web/src/pages/desktop/menu/index.tsx @@ -20,6 +20,7 @@ import { Script } from './script'; import { Settings } from './settings'; import { Terminal } from './terminal'; import { Wol } from './wol'; +import { getMenuDisableItems } from '@/api/application.ts'; export const Menu = () => { const { t } = useTranslation(); @@ -34,7 +35,13 @@ export const Menu = () => { // disabled menu items const items = getMenuDisabledItems(); setMenuDisabledItems(items); - + getMenuDisableItems().then(res=>{ + let disableItems = new Set(items) + if(res.code === 0){ + (res.data as string[]).forEach((ele)=>disableItems.add(ele)) + } + setMenuDisabledItems([...disableItems.values()]) + }) // react-draggable bounds const handleResize = () => { if (!nodeRef.current) return; diff --git a/web/src/pages/desktop/menu/screen/index.tsx b/web/src/pages/desktop/menu/screen/index.tsx index 1d149c8..390ae60 100644 --- a/web/src/pages/desktop/menu/screen/index.tsx +++ b/web/src/pages/desktop/menu/screen/index.tsx @@ -16,13 +16,14 @@ import { Quality } from './quality'; import { Reset } from './reset.tsx'; import { Resolution } from './resolution'; import { VideoMode } from './video-mode.tsx'; +import { menuDisabledItemsAtom } from '@/jotai/settings.ts'; export const Screen = () => { const { t } = useTranslation(); const videoMode = useAtomValue(videoModeAtom); const resolution = useAtomValue(resolutionAtom); - + const menuDisabledItems = useAtomValue(menuDisabledItemsAtom); const [fps, setFps] = useState(30); const [quality, setQuality] = useState(2); const [gop, setGop] = useState(30); @@ -71,9 +72,9 @@ export const Screen = () => { const content = (
- - - + {!menuDisabledItems.includes('screen:resolution') && } + {!menuDisabledItems.includes('screen:quality') && } + {!menuDisabledItems.includes('screen:fps') && } {videoMode === 'mjpeg' ? : }
diff --git a/web/src/pages/desktop/menu/settings/device/advanced/index.tsx b/web/src/pages/desktop/menu/settings/device/advanced/index.tsx index 7dfb16a..6fafb6c 100644 --- a/web/src/pages/desktop/menu/settings/device/advanced/index.tsx +++ b/web/src/pages/desktop/menu/settings/device/advanced/index.tsx @@ -9,12 +9,13 @@ const children = ( ); -export const Advanced = () => { +export const Advanced = ({disable = false}:{disable?:boolean}) => { const { t } = useTranslation(); return ( diff --git a/web/src/pages/desktop/menu/settings/device/index.tsx b/web/src/pages/desktop/menu/settings/device/index.tsx index cb818d9..787f518 100644 --- a/web/src/pages/desktop/menu/settings/device/index.tsx +++ b/web/src/pages/desktop/menu/settings/device/index.tsx @@ -1,6 +1,6 @@ import { useEffect } from 'react'; import { Divider } from 'antd'; -import { useAtom } from 'jotai'; +import { useAtom, useAtomValue } from 'jotai'; import { useTranslation } from 'react-i18next'; import * as api from '@/api/hid.ts'; @@ -17,10 +17,11 @@ import { Ssh } from './ssh.tsx'; import { Tls } from './tls.tsx'; import { VirtualDevices } from './virtual-devices.tsx'; import { Wifi } from './wifi.tsx'; +import { menuDisabledItemsAtom } from '@/jotai/settings.ts'; export const Device = () => { const { t } = useTranslation(); - + const disableMenus = useAtomValue(menuDisabledItemsAtom) const [hidMode, setHidMode] = useAtom(hidModeAtom); useEffect(() => { @@ -37,23 +38,25 @@ export const Device = () => {
- - - - + {!disableMenus.includes('device:tls') && } + {!disableMenus.includes('device:ssh') && } + {!disableMenus.includes('device:mdns') && } + {!disableMenus.includes('device:hdmi') && } + {hidMode === 'normal' ? : }
- - - + {!disableMenus.includes('device:oled') && } + {!disableMenus.includes('device:wifi') && } + {!disableMenus.includes('device:mouse') && } +
- +