4
4
"bytes"
5
5
"os"
6
6
"path/filepath"
7
- "sync"
8
7
9
8
"fyne.io/fyne/v2"
10
9
"fyne.io/fyne/v2/internal/app"
@@ -33,17 +32,14 @@ func (sc *SettingsSchema) StoragePath() string {
33
32
var _ fyne.Settings = (* settings )(nil )
34
33
35
34
type settings struct {
36
- propertyLock sync.RWMutex
37
35
theme fyne.Theme
38
36
themeSpecified bool
39
37
variant fyne.ThemeVariant
40
38
39
+ listeners []func (fyne.Settings )
41
40
changeListeners async.Map [chan fyne.Settings , bool ]
42
41
watcher any // normally *fsnotify.Watcher or nil - avoid import in this file
43
42
44
- changeListenerFuncsMutex sync.Mutex
45
- changeListenerFuncs []func (fyne.Settings )
46
-
47
43
schema SettingsSchema
48
44
}
49
45
@@ -52,8 +48,6 @@ func (s *settings) BuildType() fyne.BuildType {
52
48
}
53
49
54
50
func (s * settings ) PrimaryColor () string {
55
- s .propertyLock .RLock ()
56
- defer s .propertyLock .RUnlock ()
57
51
return s .schema .PrimaryColor
58
52
}
59
53
@@ -62,8 +56,6 @@ func (s *settings) PrimaryColor() string {
62
56
//
63
57
// Deprecated: Use container.NewThemeOverride to change the appearance of part of your application.
64
58
func (s * settings ) OverrideTheme (theme fyne.Theme , name string ) {
65
- s .propertyLock .Lock ()
66
- defer s .propertyLock .Unlock ()
67
59
s .schema .PrimaryColor = name
68
60
s .theme = theme
69
61
}
@@ -73,8 +65,6 @@ func (s *settings) Theme() fyne.Theme {
73
65
fyne .LogError ("Attempt to access current Fyne theme when no app is started" , nil )
74
66
return nil
75
67
}
76
- s .propertyLock .RLock ()
77
- defer s .propertyLock .RUnlock ()
78
68
return s .theme
79
69
}
80
70
@@ -92,23 +82,17 @@ func (s *settings) ThemeVariant() fyne.ThemeVariant {
92
82
}
93
83
94
84
func (s * settings ) applyTheme (theme fyne.Theme , variant fyne.ThemeVariant ) {
95
- s .propertyLock .Lock ()
96
- defer s .propertyLock .Unlock ()
97
85
s .variant = variant
98
86
s .theme = theme
99
87
s .apply ()
100
88
}
101
89
102
90
func (s * settings ) applyVariant (variant fyne.ThemeVariant ) {
103
- s .propertyLock .Lock ()
104
- defer s .propertyLock .Unlock ()
105
91
s .variant = variant
106
92
s .apply ()
107
93
}
108
94
109
95
func (s * settings ) Scale () float32 {
110
- s .propertyLock .RLock ()
111
- defer s .propertyLock .RUnlock ()
112
96
if s .schema .Scale < 0.0 {
113
97
return 1.0 // catching any really old data still using the `-1` value for "auto" scale
114
98
}
@@ -119,10 +103,8 @@ func (s *settings) AddChangeListener(listener chan fyne.Settings) {
119
103
s .changeListeners .Store (listener , true ) // the boolean is just a dummy value here.
120
104
}
121
105
122
- func (s * settings ) AddChangeListenerFunc (f func (fyne.Settings )) {
123
- s .changeListenerFuncsMutex .Lock ()
124
- s .changeListenerFuncs = append (s .changeListenerFuncs , f )
125
- s .changeListenerFuncsMutex .Unlock ()
106
+ func (s * settings ) AddListener (listener func (fyne.Settings )) {
107
+ s .listeners = append (s .listeners , listener )
126
108
}
127
109
128
110
func (s * settings ) apply () {
@@ -135,11 +117,10 @@ func (s *settings) apply() {
135
117
}
136
118
return true
137
119
})
138
- s . changeListenerFuncsMutex . Lock ()
139
- for _ , f := range s .changeListenerFuncs {
140
- f (s )
120
+
121
+ for _ , l := range s .listeners {
122
+ l (s )
141
123
}
142
- s .changeListenerFuncsMutex .Unlock ()
143
124
}
144
125
145
126
func (s * settings ) fileChanged () {
0 commit comments