Skip to content

Commit a7693df

Browse files
authored
fix: the screen doesn't dim or turn off
* Fix for #531 Fix for #531 * typo * Skip processing if lease hasn't changed to avoid unnecessary wake-ups * Add comment to clarify the need to stop the tickers
1 parent 8d77d75 commit a7693df

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

display.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,18 @@ func startBacklightTickers() {
339339
return
340340
}
341341

342-
if dimTicker == nil && config.DisplayDimAfterSec != 0 {
342+
// Stop existing tickers to prevent multiple active instances on repeated calls
343+
if dimTicker != nil {
344+
dimTicker.Stop()
345+
}
346+
347+
if offTicker != nil {
348+
offTicker.Stop()
349+
}
350+
351+
if config.DisplayDimAfterSec != 0 {
343352
displayLogger.Info().Msg("dim_ticker has started")
344353
dimTicker = time.NewTicker(time.Duration(config.DisplayDimAfterSec) * time.Second)
345-
defer dimTicker.Stop()
346354

347355
go func() {
348356
for { //nolint:staticcheck
@@ -354,10 +362,9 @@ func startBacklightTickers() {
354362
}()
355363
}
356364

357-
if offTicker == nil && config.DisplayOffAfterSec != 0 {
365+
if config.DisplayOffAfterSec != 0 {
358366
displayLogger.Info().Msg("off_ticker has started")
359367
offTicker = time.NewTicker(time.Duration(config.DisplayOffAfterSec) * time.Second)
360-
defer offTicker.Stop()
361368

362369
go func() {
363370
for { //nolint:staticcheck

internal/udhcpc/udhcpc.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"reflect"
89
"time"
910

1011
"github.com/fsnotify/fsnotify"
@@ -149,6 +150,12 @@ func (c *DHCPClient) loadLeaseFile() error {
149150
}
150151

151152
isFirstLoad := c.lease == nil
153+
154+
// Skip processing if lease hasn't changed to avoid unnecessary wake-ups.
155+
if reflect.DeepEqual(c.lease, lease) {
156+
return nil
157+
}
158+
152159
c.lease = lease
153160

154161
if lease.IPAddress == nil {

0 commit comments

Comments
 (0)