Skip to content

Commit

Permalink
Fix fyne-io#2449 by retrying ignored changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nullst committed Sep 16, 2021
1 parent e9ec0d1 commit 8cfce11
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/preferences.go
Expand Up @@ -16,6 +16,7 @@ type preferences struct {

prefLock sync.RWMutex
ignoreChange bool
numIgnoredChanges int

app *fyneApp
}
Expand All @@ -28,7 +29,13 @@ func (p *preferences) resetIgnore() {
time.Sleep(time.Millisecond * 100) // writes are not always atomic. 10ms worked, 100 is safer.
p.prefLock.Lock()
p.ignoreChange = false
changes := p.numIgnoredChanges
p.numIgnoredChanges = 0
p.prefLock.Unlock()

if changes > 0 {
p.InMemoryPreferences.FireChange()
}
}()
}

Expand Down Expand Up @@ -112,9 +119,12 @@ func newPreferences(app *fyneApp) *preferences {
}

p.AddChangeListener(func() {
p.prefLock.RLock()
p.prefLock.Lock()
shouldIgnoreChange := p.ignoreChange
p.prefLock.RUnlock()
if shouldIgnoreChange {
p.numIgnoredChanges++
}
p.prefLock.Unlock()
if shouldIgnoreChange { // callback after loading, no need to save
return
}
Expand Down

0 comments on commit 8cfce11

Please sign in to comment.