Skip to content

Commit 305201d

Browse files
committed
fix: wrap UI updates in fyne.Do for thread safety
Since Fyne 2.6, UI modifications from background goroutines must be wrapped in fyne.Do() to run on the main thread. The OnTick and OnEnd callbacks are called from the pomodoro ticker goroutine, causing thread safety warnings.
1 parent 78abb56 commit 305201d

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

ui/ui.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,17 @@ func MakeClassicLayout(thePomodoro *pomodoro.Pomodoro) fyne.CanvasObject {
127127
}
128128

129129
thePomodoro.OnTick = func() {
130-
setTimerRemainingTime(thePomodoro, timer)
130+
fyne.Do(func() {
131+
setTimerRemainingTime(thePomodoro, timer)
132+
})
131133
}
132134
thePomodoro.OnEnd = func(kind pomodoro.Kind) {
133-
setTimerRemainingTime(thePomodoro, timer)
135+
fyne.Do(func() {
136+
setTimerRemainingTime(thePomodoro, timer)
134137

135-
playButton.Icon = theme.MediaPlayIcon()
136-
playButton.Refresh()
138+
playButton.Icon = theme.MediaPlayIcon()
139+
playButton.Refresh()
140+
})
137141

138142
notifyPomodoroDone(kind)
139143
}

0 commit comments

Comments
 (0)