mirror of
https://github.com/sipeed/NanoKVM.git
synced 2026-09-11 00:22:56 -05:00
Merge pull request #529 from tpretz/hdmi-persist
Make HDMI toggle state persist across reboots
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
"NanoKVM-Server/middleware"
|
||||
"NanoKVM-Server/router"
|
||||
"NanoKVM-Server/service/vm/jiggler"
|
||||
"NanoKVM-Server/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
cors "github.com/rs/cors/wrapper/gin"
|
||||
@@ -38,7 +39,9 @@ func initialize() {
|
||||
vision := common.GetKvmVision()
|
||||
vision.SetHDMI(false)
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
vision.SetHDMI(true)
|
||||
if !utils.IsHdmiDisabled() {
|
||||
vision.SetHDMI(true)
|
||||
}
|
||||
|
||||
// run mouse jiggler
|
||||
jiggler.GetJiggler().Run()
|
||||
|
||||
@@ -5,13 +5,12 @@ import (
|
||||
|
||||
"NanoKVM-Server/common"
|
||||
"NanoKVM-Server/proto"
|
||||
"NanoKVM-Server/utils"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var hdmiEnabled = true
|
||||
|
||||
func (s *Service) ResetHdmi(c *gin.Context) {
|
||||
var rsp proto.Response
|
||||
|
||||
@@ -20,7 +19,7 @@ func (s *Service) ResetHdmi(c *gin.Context) {
|
||||
vision.SetHDMI(false)
|
||||
time.Sleep(1 * time.Second)
|
||||
vision.SetHDMI(true)
|
||||
hdmiEnabled = true
|
||||
utils.PersistHDMIEnabled()
|
||||
|
||||
rsp.OkRsp(c)
|
||||
log.Debug("reset hdmi")
|
||||
@@ -32,7 +31,7 @@ func (s *Service) EnableHdmi(c *gin.Context) {
|
||||
vision := common.GetKvmVision()
|
||||
|
||||
vision.SetHDMI(true)
|
||||
hdmiEnabled = true
|
||||
utils.PersistHDMIEnabled()
|
||||
|
||||
rsp.OkRsp(c)
|
||||
log.Debug("enable hdmi")
|
||||
@@ -44,7 +43,7 @@ func (s *Service) DisableHdmi(c *gin.Context) {
|
||||
vision := common.GetKvmVision()
|
||||
|
||||
vision.SetHDMI(false)
|
||||
hdmiEnabled = false
|
||||
utils.PersistHDMIDisabled()
|
||||
|
||||
rsp.OkRsp(c)
|
||||
log.Debug("disable hdmi")
|
||||
@@ -54,7 +53,7 @@ func (s *Service) GetHdmiState(c *gin.Context) {
|
||||
var rsp proto.Response
|
||||
|
||||
rsp.OkRspWithData(c, &proto.GetGetHdmiStateRsp{
|
||||
Enabled: hdmiEnabled,
|
||||
Enabled: !utils.IsHdmiDisabled(),
|
||||
})
|
||||
|
||||
log.Debug("get hdmi state")
|
||||
|
||||
38
server/utils/hdmi.go
Normal file
38
server/utils/hdmi.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
HDMIDisableFile = "/etc/kvm/hdmi_disable"
|
||||
)
|
||||
|
||||
func PersistHDMIDisabled() {
|
||||
f, err := os.OpenFile(HDMIDisableFile, os.O_CREATE|os.O_RDONLY, 0644)
|
||||
if err != nil {
|
||||
log.Error("failed to create hdmi disable file:", err)
|
||||
return
|
||||
}
|
||||
f.Close()
|
||||
}
|
||||
|
||||
func PersistHDMIEnabled() {
|
||||
if err := os.Remove(HDMIDisableFile); err != nil {
|
||||
log.Error("failed to remove hdmi disable file:", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func IsHdmiDisabled() bool {
|
||||
if _, err := os.Stat(HDMIDisableFile); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return false // HDMI is enabled
|
||||
}
|
||||
log.Error("failed to check hdmi disable file:", err)
|
||||
return false // Assume HDMI is enabled on error
|
||||
}
|
||||
return true // HDMI is disabled
|
||||
}
|
||||
Reference in New Issue
Block a user