fix: the screen doesn't dim or turn off

* Fix for #531

Fix for https://github.com/jetkvm/kvm/issues/531

* typo

* Skip processing if lease hasn't changed to avoid unnecessary wake-ups

* Add comment to clarify the need to stop the tickers
This commit is contained in:
Alex Ballas 2025-06-03 02:28:14 +03:00 committed by GitHub
parent 8d77d75294
commit a7693df92c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 4 deletions

View File

@ -339,10 +339,18 @@ func startBacklightTickers() {
return return
} }
if dimTicker == nil && config.DisplayDimAfterSec != 0 { // Stop existing tickers to prevent multiple active instances on repeated calls
if dimTicker != nil {
dimTicker.Stop()
}
if offTicker != nil {
offTicker.Stop()
}
if config.DisplayDimAfterSec != 0 {
displayLogger.Info().Msg("dim_ticker has started") displayLogger.Info().Msg("dim_ticker has started")
dimTicker = time.NewTicker(time.Duration(config.DisplayDimAfterSec) * time.Second) dimTicker = time.NewTicker(time.Duration(config.DisplayDimAfterSec) * time.Second)
defer dimTicker.Stop()
go func() { go func() {
for { //nolint:staticcheck for { //nolint:staticcheck
@ -354,10 +362,9 @@ func startBacklightTickers() {
}() }()
} }
if offTicker == nil && config.DisplayOffAfterSec != 0 { if config.DisplayOffAfterSec != 0 {
displayLogger.Info().Msg("off_ticker has started") displayLogger.Info().Msg("off_ticker has started")
offTicker = time.NewTicker(time.Duration(config.DisplayOffAfterSec) * time.Second) offTicker = time.NewTicker(time.Duration(config.DisplayOffAfterSec) * time.Second)
defer offTicker.Stop()
go func() { go func() {
for { //nolint:staticcheck for { //nolint:staticcheck

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"reflect"
"time" "time"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
@ -149,6 +150,12 @@ func (c *DHCPClient) loadLeaseFile() error {
} }
isFirstLoad := c.lease == nil isFirstLoad := c.lease == nil
// Skip processing if lease hasn't changed to avoid unnecessary wake-ups.
if reflect.DeepEqual(c.lease, lease) {
return nil
}
c.lease = lease c.lease = lease
if lease.IPAddress == nil { if lease.IPAddress == nil {