1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-04-17 11:12:06 -04:00

fix(ddc): prevent negative WaitGroup counter on rapid brightness changes

This commit is contained in:
bbedward
2026-04-16 10:25:08 -04:00
parent 787d213722
commit cf0fa7da6b

View File

@@ -215,25 +215,27 @@ func (b *DDCBackend) SetBrightnessWithExponent(id string, value int, exponential
callback: callback, callback: callback,
} }
if timer, exists := b.debounceTimers[id]; exists { if existing, exists := b.debounceTimers[id]; exists {
timer.Reset(200 * time.Millisecond) if existing.Stop() {
} else { b.debounceWg.Done()
}
}
b.debounceWg.Add(1) 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() defer b.debounceWg.Done()
b.debounceMutex.Lock() b.debounceMutex.Lock()
pending, exists := b.debouncePending[id] pending, hasPending := b.debouncePending[id]
if exists {
delete(b.debouncePending, id) delete(b.debouncePending, id)
} delete(b.debounceTimers, id)
b.debounceMutex.Unlock() b.debounceMutex.Unlock()
if !exists { if !hasPending {
return return
} }
err := b.setBrightnessImmediateWithExponent(id, pending.percent) if err := b.setBrightnessImmediateWithExponent(id, pending.percent); err != nil {
if err != nil {
log.Debugf("Failed to set brightness for %s: %v", id, err) log.Debugf("Failed to set brightness for %s: %v", id, err)
} }
@@ -241,7 +243,6 @@ func (b *DDCBackend) SetBrightnessWithExponent(id string, value int, exponential
pending.callback() pending.callback()
} }
}) })
}
b.debounceMutex.Unlock() b.debounceMutex.Unlock()
return nil return nil