Skip to content

Commit 3b6d76e

Browse files
committed
Fix Fyne races. WIP
1 parent 4111908 commit 3b6d76e

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

internal/gui/cardReaderUI.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ func setUI(doc document.Document) {
6565

6666
buttonBar := container.New(layout.NewHBoxLayout(), buttonBarObjects...)
6767

68-
state.documentUiMainContainer.RemoveAll()
69-
state.documentUiMainContainer.Add(page)
70-
state.documentUiMainContainer.Add(buttonBar)
68+
fyne.DoAndWait(func() {
69+
state.documentUiMainContainer.RemoveAll()
70+
state.documentUiMainContainer.Add(page)
71+
state.documentUiMainContainer.Add(buttonBar)
7172

72-
state.startPage.Hide()
73-
state.documentUiMainContainer.Show()
73+
state.startPage.Hide()
74+
state.documentUiMainContainer.Show()
75+
})
7476

7577
resizeWindow(false)
7678
}
@@ -117,8 +119,10 @@ func setStatus(statusId string, err error) {
117119
}
118120

119121
status := t(statusId)
120-
state.statusBar.SetStatus(status, isError)
121-
state.statusBar.Refresh()
122+
fyne.Do(func() {
123+
state.statusBar.SetStatus(status, isError)
124+
state.statusBar.Refresh()
125+
})
122126
}
123127

124128
func updateMedicalDocHandler(doc *document.MedicalDocument) func() {
@@ -159,8 +163,10 @@ func setTimedStatus(label string) {
159163
go func() {
160164
time.Sleep(2 * time.Second)
161165
if state.statusBar.GetStatus() == label {
162-
state.statusBar.SetStatus("", false)
163-
state.statusBar.Refresh()
166+
fyne.Do(func() {
167+
state.statusBar.SetStatus("", false)
168+
state.statusBar.Refresh()
169+
})
164170
}
165171
}()
166172
}
@@ -179,15 +185,19 @@ func setTimedStatusError(labelKey string, err error) {
179185
go func() {
180186
time.Sleep(2 * time.Second)
181187
if state.statusBar.GetStatus() == label {
182-
state.statusBar.SetStatus("", false)
183-
state.statusBar.Refresh()
188+
fyne.Do(func() {
189+
state.statusBar.SetStatus("", false)
190+
state.statusBar.Refresh()
191+
})
184192
}
185193
}()
186194
}
187195

188196
func showDocumentUI() {
189-
state.mainContainer.RemoveAll()
190-
state.mainContainer.Add(state.documentUi)
197+
fyne.DoAndWait(func() {
198+
state.mainContainer.RemoveAll()
199+
state.mainContainer.Add(state.documentUi)
200+
})
191201
}
192202

193203
func resizeWindow(keepCurrentSize bool) {
@@ -205,5 +215,7 @@ func resizeWindow(keepCurrentSize bool) {
205215
}
206216
}
207217

208-
state.window.Resize(minSize)
218+
fyne.Do(func() {
219+
state.window.Resize(minSize)
220+
})
209221
}

internal/gui/widgets/startPage.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ func (r *StartPageRenderer) Refresh() {
6969
r.statusText.Color = theme.Color(theme.ColorNameForeground)
7070
}
7171

72-
r.statusText.Refresh()
73-
r.explanationText.Refresh()
72+
fyne.Do(func() {
73+
r.statusText.Refresh()
74+
r.explanationText.Refresh()
75+
})
7476
}
7577

7678
func (r *StartPageRenderer) Layout(s fyne.Size) {

internal/gui/widgets/statusBar.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ func (r *StatusBarRenderer) Refresh() {
5656
r.statusText.Color = theme.Color(theme.ColorNameForeground)
5757
}
5858

59-
r.statusText.Refresh()
59+
fyne.Do(func() {
60+
r.statusText.Refresh()
61+
})
6062
}
6163

6264
func (r *StatusBarRenderer) Layout(s fyne.Size) {

0 commit comments

Comments
 (0)