1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-04-15 02:02:08 -04:00

Fix ddc brightness not applying because process exits before debounce timer runs (#2217)

* Fix ddc brightness not applying because process exits before debounce timer runs

* Added sync.WaitGroup to DDCBackend and use it instead of loop in wait logic, added timeout in case i2c hangs.

* go fmt

---------

Co-authored-by: bbedward <bbedward@gmail.com>
This commit is contained in:
DavutHaxor
2026-04-14 17:27:36 +03:00
committed by GitHub
parent 8d415e9568
commit eff728fdf5
3 changed files with 18 additions and 0 deletions

View File

@@ -236,6 +236,7 @@ func runBrightnessSet(cmd *cobra.Command, args []string) {
defer ddc.Close() defer ddc.Close()
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
if err := ddc.SetBrightnessWithExponent(deviceID, percent, exponential, exponent, nil); err == nil { if err := ddc.SetBrightnessWithExponent(deviceID, percent, exponential, exponent, nil); err == nil {
ddc.WaitPending()
fmt.Printf("Set %s to %d%%\n", deviceID, percent) fmt.Printf("Set %s to %d%%\n", deviceID, percent)
return return
} }

View File

@@ -218,7 +218,9 @@ func (b *DDCBackend) SetBrightnessWithExponent(id string, value int, exponential
if timer, exists := b.debounceTimers[id]; exists { if timer, exists := b.debounceTimers[id]; exists {
timer.Reset(200 * time.Millisecond) timer.Reset(200 * time.Millisecond)
} else { } else {
b.debounceWg.Add(1)
b.debounceTimers[id] = time.AfterFunc(200*time.Millisecond, func() { b.debounceTimers[id] = time.AfterFunc(200*time.Millisecond, func() {
defer b.debounceWg.Done()
b.debounceMutex.Lock() b.debounceMutex.Lock()
pending, exists := b.debouncePending[id] pending, exists := b.debouncePending[id]
if exists { if exists {
@@ -490,5 +492,19 @@ func (b *DDCBackend) valueToPercent(value int, max int, exponential bool) int {
return percent return percent
} }
func (b *DDCBackend) WaitPending() {
done := make(chan struct{})
go func() {
b.debounceWg.Wait()
close(done)
}()
select {
case <-done:
case <-time.After(5 * time.Second):
log.Debug("WaitPending timed out waiting for DDC writes")
}
}
func (b *DDCBackend) Close() { func (b *DDCBackend) Close() {
} }

View File

@@ -84,6 +84,7 @@ type DDCBackend struct {
debounceMutex sync.Mutex debounceMutex sync.Mutex
debounceTimers map[string]*time.Timer debounceTimers map[string]*time.Timer
debouncePending map[string]ddcPendingSet debouncePending map[string]ddcPendingSet
debounceWg sync.WaitGroup
} }
type ddcPendingSet struct { type ddcPendingSet struct {