mirror of https://github.com/jetkvm/kvm.git
chore: use UIObjSetState instead of Add+Remove
This commit is contained in:
parent
068619fee6
commit
bba113f58b
|
@ -2,5 +2,6 @@
|
||||||
"tailwindCSS.classFunctions": [
|
"tailwindCSS.classFunctions": [
|
||||||
"cva",
|
"cva",
|
||||||
"cx"
|
"cx"
|
||||||
]
|
],
|
||||||
|
"cmake.sourceDirectory": "/Users/aveline/Projects/JetKVM/ymjk/internal/native/cgo"
|
||||||
}
|
}
|
7
Makefile
7
Makefile
|
@ -25,7 +25,7 @@ GO_ARGS := GOOS=linux GOARCH=arm GOARM=7 ARCHFLAGS="-arch arm"
|
||||||
ifneq ($(wildcard $(BUILDKIT_PATH)),)
|
ifneq ($(wildcard $(BUILDKIT_PATH)),)
|
||||||
GO_ARGS := $(GO_ARGS) \
|
GO_ARGS := $(GO_ARGS) \
|
||||||
CGO_CFLAGS="-I$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/include -I$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/sysroot/usr/include" \
|
CGO_CFLAGS="-I$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/include -I$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/sysroot/usr/include" \
|
||||||
CGO_LDFLAGS="-L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/lib -L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/sysroot/usr/lib -lrockit -lrockchip_mpp -lrga -lpthread -lm" \
|
CGO_LDFLAGS="-L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/lib -L$(BUILDKIT_PATH)/$(BUILDKIT_FLAVOR)/sysroot/usr/lib -lrockit -lrockchip_mpp -lrga -lpthread -lm -lgpiod" \
|
||||||
CC="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-gcc" \
|
CC="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-gcc" \
|
||||||
LD="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-ld" \
|
LD="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-ld" \
|
||||||
CGO_ENABLED=1
|
CGO_ENABLED=1
|
||||||
|
@ -40,7 +40,10 @@ TEST_DIRS := $(shell find . -name "*_test.go" -type f -exec dirname {} \; | sort
|
||||||
|
|
||||||
build_native:
|
build_native:
|
||||||
@echo "Building native..."
|
@echo "Building native..."
|
||||||
cd internal/native/cgo && ./ui_index.gen.sh && ./build.sh
|
cd internal/native/cgo && ./ui_index.gen.sh && \
|
||||||
|
CC="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-gcc" \
|
||||||
|
LD="$(BUILDKIT_PATH)/bin/$(BUILDKIT_FLAVOR)-ld" \
|
||||||
|
./build.sh
|
||||||
|
|
||||||
build_dev: build_native
|
build_dev: build_native
|
||||||
@echo "Building..."
|
@echo "Building..."
|
||||||
|
|
1
cloud.go
1
cloud.go
|
@ -170,6 +170,7 @@ func setCloudConnectionState(state CloudConnectionState) {
|
||||||
|
|
||||||
go waitCtrlAndRequestDisplayUpdate(
|
go waitCtrlAndRequestDisplayUpdate(
|
||||||
previousState != state,
|
previousState != state,
|
||||||
|
"set_cloud_connection_state",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
41
display.go
41
display.go
|
@ -42,17 +42,21 @@ func updateDisplay() {
|
||||||
|
|
||||||
if usbState == "configured" {
|
if usbState == "configured" {
|
||||||
nativeInstance.UpdateLabelIfChanged("usb_status_label", "Connected")
|
nativeInstance.UpdateLabelIfChanged("usb_status_label", "Connected")
|
||||||
_, _ = nativeInstance.UIObjSetState("usb_status", "LV_STATE_DEFAULT")
|
_, _ = nativeInstance.UIObjAddState("usb_status", "LV_STATE_DEFAULT")
|
||||||
|
_, _ = nativeInstance.UIObjRemoveState("usb_status", "LV_STATE_DISABLED")
|
||||||
} else {
|
} else {
|
||||||
nativeInstance.UpdateLabelIfChanged("usb_status_label", "Disconnected")
|
nativeInstance.UpdateLabelIfChanged("usb_status_label", "Disconnected")
|
||||||
_, _ = nativeInstance.UIObjSetState("usb_status", "LV_STATE_DISABLED")
|
_, _ = nativeInstance.UIObjAddState("usb_status", "LV_STATE_DISABLED")
|
||||||
|
_, _ = nativeInstance.UIObjRemoveState("usb_status", "LV_STATE_DEFAULT")
|
||||||
}
|
}
|
||||||
if lastVideoState.Ready {
|
if lastVideoState.Ready {
|
||||||
nativeInstance.UpdateLabelIfChanged("hdmi_status_label", "Connected")
|
nativeInstance.UpdateLabelIfChanged("hdmi_status_label", "Connected")
|
||||||
_, _ = nativeInstance.UIObjSetState("hdmi_status", "LV_STATE_DEFAULT")
|
_, _ = nativeInstance.UIObjAddState("hdmi_status", "LV_STATE_DEFAULT")
|
||||||
|
_, _ = nativeInstance.UIObjRemoveState("hdmi_status", "LV_STATE_DISABLED")
|
||||||
} else {
|
} else {
|
||||||
nativeInstance.UpdateLabelIfChanged("hdmi_status_label", "Disconnected")
|
nativeInstance.UpdateLabelIfChanged("hdmi_status_label", "Disconnected")
|
||||||
_, _ = nativeInstance.UIObjSetState("hdmi_status", "LV_STATE_DISABLED")
|
_, _ = nativeInstance.UIObjAddState("hdmi_status", "LV_STATE_DISABLED")
|
||||||
|
_, _ = nativeInstance.UIObjRemoveState("hdmi_status", "LV_STATE_DEFAULT")
|
||||||
}
|
}
|
||||||
nativeInstance.UpdateLabelIfChanged("cloud_status_label", fmt.Sprintf("%d active", actionSessions))
|
nativeInstance.UpdateLabelIfChanged("cloud_status_label", fmt.Sprintf("%d active", actionSessions))
|
||||||
|
|
||||||
|
@ -124,7 +128,7 @@ var (
|
||||||
waitDisplayUpdate = sync.Mutex{}
|
waitDisplayUpdate = sync.Mutex{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func requestDisplayUpdate(shouldWakeDisplay bool) {
|
func requestDisplayUpdate(shouldWakeDisplay bool, reason string) {
|
||||||
displayUpdateLock.Lock()
|
displayUpdateLock.Lock()
|
||||||
defer displayUpdateLock.Unlock()
|
defer displayUpdateLock.Unlock()
|
||||||
|
|
||||||
|
@ -134,7 +138,7 @@ func requestDisplayUpdate(shouldWakeDisplay bool) {
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
if shouldWakeDisplay {
|
if shouldWakeDisplay {
|
||||||
wakeDisplay(false)
|
wakeDisplay(false, reason)
|
||||||
}
|
}
|
||||||
displayLogger.Debug().Msg("display updating")
|
displayLogger.Debug().Msg("display updating")
|
||||||
//TODO: only run once regardless how many pending updates
|
//TODO: only run once regardless how many pending updates
|
||||||
|
@ -142,12 +146,12 @@ func requestDisplayUpdate(shouldWakeDisplay bool) {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitCtrlAndRequestDisplayUpdate(shouldWakeDisplay bool) {
|
func waitCtrlAndRequestDisplayUpdate(shouldWakeDisplay bool, reason string) {
|
||||||
waitDisplayUpdate.Lock()
|
waitDisplayUpdate.Lock()
|
||||||
defer waitDisplayUpdate.Unlock()
|
defer waitDisplayUpdate.Unlock()
|
||||||
|
|
||||||
// nativeInstance.WaitCtrlClientConnected()
|
// nativeInstance.WaitCtrlClientConnected()
|
||||||
requestDisplayUpdate(shouldWakeDisplay)
|
requestDisplayUpdate(shouldWakeDisplay, reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateStaticContents() {
|
func updateStaticContents() {
|
||||||
|
@ -182,7 +186,7 @@ func updateStaticContents() {
|
||||||
|
|
||||||
// setDisplayBrightness sets /sys/class/backlight/backlight/brightness to alter
|
// setDisplayBrightness sets /sys/class/backlight/backlight/brightness to alter
|
||||||
// the backlight brightness of the JetKVM hardware's display.
|
// the backlight brightness of the JetKVM hardware's display.
|
||||||
func setDisplayBrightness(brightness int) error {
|
func setDisplayBrightness(brightness int, reason string) error {
|
||||||
// NOTE: The actual maximum value for this is 255, but out-of-the-box, the value is set to 64.
|
// NOTE: The actual maximum value for this is 255, but out-of-the-box, the value is set to 64.
|
||||||
// The maximum set here is set to 100 to reduce the risk of drawing too much power (and besides, 255 is very bright!).
|
// The maximum set here is set to 100 to reduce the risk of drawing too much power (and besides, 255 is very bright!).
|
||||||
if brightness > 100 || brightness < 0 {
|
if brightness > 100 || brightness < 0 {
|
||||||
|
@ -201,14 +205,14 @@ func setDisplayBrightness(brightness int) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
displayLogger.Info().Int("brightness", brightness).Msg("set brightness")
|
displayLogger.Info().Int("brightness", brightness).Str("reason", reason).Msg("set brightness")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// tick_displayDim() is called when when dim ticker expires, it simply reduces the brightness
|
// tick_displayDim() is called when when dim ticker expires, it simply reduces the brightness
|
||||||
// of the display by half of the max brightness.
|
// of the display by half of the max brightness.
|
||||||
func tick_displayDim() {
|
func tick_displayDim() {
|
||||||
err := setDisplayBrightness(config.DisplayMaxBrightness / 2)
|
err := setDisplayBrightness(config.DisplayMaxBrightness/2, "tick_display_dim")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
displayLogger.Warn().Err(err).Msg("failed to dim display")
|
displayLogger.Warn().Err(err).Msg("failed to dim display")
|
||||||
}
|
}
|
||||||
|
@ -221,7 +225,7 @@ func tick_displayDim() {
|
||||||
// tick_displayOff() is called when the off ticker expires, it turns off the display
|
// tick_displayOff() is called when the off ticker expires, it turns off the display
|
||||||
// by setting the brightness to zero.
|
// by setting the brightness to zero.
|
||||||
func tick_displayOff() {
|
func tick_displayOff() {
|
||||||
err := setDisplayBrightness(0)
|
err := setDisplayBrightness(0, "tick_display_off")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
displayLogger.Warn().Err(err).Msg("failed to turn off display")
|
displayLogger.Warn().Err(err).Msg("failed to turn off display")
|
||||||
}
|
}
|
||||||
|
@ -234,7 +238,7 @@ func tick_displayOff() {
|
||||||
// wakeDisplay sets the display brightness back to config.DisplayMaxBrightness and stores the time the display
|
// wakeDisplay sets the display brightness back to config.DisplayMaxBrightness and stores the time the display
|
||||||
// last woke, ready for displayTimeoutTick to put the display back in the dim/off states.
|
// last woke, ready for displayTimeoutTick to put the display back in the dim/off states.
|
||||||
// Set force to true to skip the backlight state check, this should be done if altering the tickers.
|
// Set force to true to skip the backlight state check, this should be done if altering the tickers.
|
||||||
func wakeDisplay(force bool) {
|
func wakeDisplay(force bool, reason string) {
|
||||||
if backlightState == 0 && !force {
|
if backlightState == 0 && !force {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -244,7 +248,11 @@ func wakeDisplay(force bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := setDisplayBrightness(config.DisplayMaxBrightness)
|
if reason == "" {
|
||||||
|
reason = "wake_display"
|
||||||
|
}
|
||||||
|
|
||||||
|
err := setDisplayBrightness(config.DisplayMaxBrightness, reason)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
displayLogger.Warn().Err(err).Msg("failed to wake display")
|
displayLogger.Warn().Err(err).Msg("failed to wake display")
|
||||||
}
|
}
|
||||||
|
@ -266,7 +274,7 @@ func startBacklightTickers() {
|
||||||
// Don't start the tickers if the display is switched off.
|
// Don't start the tickers if the display is switched off.
|
||||||
// Set the display to off if that's the case.
|
// Set the display to off if that's the case.
|
||||||
if config.DisplayMaxBrightness == 0 {
|
if config.DisplayMaxBrightness == 0 {
|
||||||
_ = setDisplayBrightness(0)
|
_ = setDisplayBrightness(0, "display_disabled")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,7 +324,6 @@ func initDisplay() {
|
||||||
displayInited = true
|
displayInited = true
|
||||||
displayLogger.Info().Msg("display inited")
|
displayLogger.Info().Msg("display inited")
|
||||||
startBacklightTickers()
|
startBacklightTickers()
|
||||||
wakeDisplay(true)
|
requestDisplayUpdate(true, "init_display")
|
||||||
requestDisplayUpdate(true)
|
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
@ -348,7 +348,7 @@ func rpcSetBacklightSettings(params BacklightSettings) error {
|
||||||
// are reset to the new settings, and will bring the display up to maxBrightness.
|
// are reset to the new settings, and will bring the display up to maxBrightness.
|
||||||
// Calling with force set to true, to ignore the current state of the display, and force
|
// Calling with force set to true, to ignore the current state of the display, and force
|
||||||
// it to reset the tickers.
|
// it to reset the tickers.
|
||||||
wakeDisplay(true)
|
wakeDisplay(true, "backlight_settings_changed")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,11 @@ func initNative(systemVersion *semver.Version, appVersion *semver.Version) {
|
||||||
OnVideoStateChange: func(state native.VideoState) {
|
OnVideoStateChange: func(state native.VideoState) {
|
||||||
lastVideoState = state
|
lastVideoState = state
|
||||||
triggerVideoStateUpdate()
|
triggerVideoStateUpdate()
|
||||||
requestDisplayUpdate(true)
|
requestDisplayUpdate(true, "video_state_changed")
|
||||||
},
|
},
|
||||||
OnIndevEvent: func(event string) {
|
OnIndevEvent: func(event string) {
|
||||||
nativeLogger.Trace().Str("event", event).Msg("indev event received")
|
nativeLogger.Trace().Str("event", event).Msg("indev event received")
|
||||||
wakeDisplay(false)
|
wakeDisplay(false, "indev_event")
|
||||||
},
|
},
|
||||||
OnVideoFrameReceived: func(frame []byte, duration time.Duration) {
|
OnVideoFrameReceived: func(frame []byte, duration time.Duration) {
|
||||||
if currentSession != nil {
|
if currentSession != nil {
|
||||||
|
|
|
@ -18,7 +18,7 @@ var (
|
||||||
|
|
||||||
func networkStateChanged() {
|
func networkStateChanged() {
|
||||||
// do not block the main thread
|
// do not block the main thread
|
||||||
go waitCtrlAndRequestDisplayUpdate(true)
|
go waitCtrlAndRequestDisplayUpdate(true, "network_state_changed")
|
||||||
|
|
||||||
// always restart mDNS when the network state changes
|
// always restart mDNS when the network state changes
|
||||||
if mDNS != nil {
|
if mDNS != nil {
|
||||||
|
|
2
usb.go
2
usb.go
|
@ -81,6 +81,6 @@ func checkUSBState() {
|
||||||
usbState = newState
|
usbState = newState
|
||||||
|
|
||||||
usbLogger.Info().Str("from", usbState).Str("to", newState).Msg("USB state changed")
|
usbLogger.Info().Str("from", usbState).Str("to", newState).Msg("USB state changed")
|
||||||
requestDisplayUpdate(true)
|
requestDisplayUpdate(true, "usb_state_changed")
|
||||||
triggerUSBStateUpdate()
|
triggerUSBStateUpdate()
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,7 +206,7 @@ func newSession(config SessionConfig) (*Session, error) {
|
||||||
var actionSessions = 0
|
var actionSessions = 0
|
||||||
|
|
||||||
func onActiveSessionsChanged() {
|
func onActiveSessionsChanged() {
|
||||||
requestDisplayUpdate(true)
|
requestDisplayUpdate(true, "active_sessions_changed")
|
||||||
}
|
}
|
||||||
|
|
||||||
func onFirstSessionConnected() {
|
func onFirstSessionConnected() {
|
||||||
|
|
Loading…
Reference in New Issue