Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-fix #2449 #2477

Merged
merged 9 commits into from Sep 30, 2021
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
6 changes: 3 additions & 3 deletions internal/preferences.go
Expand Up @@ -41,7 +41,7 @@ func (p *InMemoryPreferences) WriteValues(fn func(map[string]interface{})) {
fn(p.values)
p.lock.Unlock()

p.fireChange()
p.FireChange()
}

func (p *InMemoryPreferences) set(key string, value interface{}) {
Expand All @@ -50,7 +50,7 @@ func (p *InMemoryPreferences) set(key string, value interface{}) {
p.values[key] = value
p.lock.Unlock()

p.fireChange()
p.FireChange()
}

func (p *InMemoryPreferences) get(key string) (interface{}, bool) {
Expand All @@ -68,7 +68,7 @@ func (p *InMemoryPreferences) remove(key string) {
delete(p.values, key)
}

func (p *InMemoryPreferences) fireChange() {
func (p *InMemoryPreferences) FireChange() {
p.lock.RLock()
defer p.lock.RUnlock()

Expand Down