Skip to content

Commit 68f32a3

Browse files
committed
Delay the large FyneDo warning unless hints is on
1 parent 797cd98 commit 68f32a3

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

app/app.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ package app // import "fyne.io/fyne/v2/app"
55

66
import (
77
"fmt"
8-
"log"
98
"time"
109

1110
"fyne.io/fyne/v2"
1211
"fyne.io/fyne/v2/internal"
1312
"fyne.io/fyne/v2/internal/app"
13+
"fyne.io/fyne/v2/internal/async"
1414
"fyne.io/fyne/v2/internal/build"
1515
intRepo "fyne.io/fyne/v2/internal/repository"
1616
"fyne.io/fyne/v2/internal/scheduler"
@@ -80,10 +80,8 @@ func (a *fyneApp) Run() {
8080
a.settings.watchSettings()
8181
}
8282

83-
if !build.MigratedToFyneDo() {
84-
log.Println("*** This application has not been migrated to the fyne.Do threading model ***")
85-
log.Println("*** The next major Fyne release will remove this safety! ***")
86-
log.Println("*** Read more at https://docs.fyne.io/started/goroutines ***")
83+
if !build.MigratedToFyneDo() && build.HasHints {
84+
async.PrintFyneDoWarning()
8785
}
8886
a.driver.Run()
8987
}

internal/async/goroutine.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ import (
1010
"fyne.io/fyne/v2/internal/build"
1111
)
1212

13-
// mainGoroutineID stores the main goroutine ID.
14-
// This ID must be initialized during setup by calling `SetMainGoroutine` because
15-
// a main goroutine may not equal to 1 due to the influence of a garbage collector.
16-
var mainGoroutineID atomic.Uint64
13+
var (
14+
// mainGoroutineID stores the main goroutine ID.
15+
// This ID must be initialized during setup by calling `SetMainGoroutine` because
16+
// a main goroutine may not equal to 1 due to the influence of a garbage collector.
17+
mainGoroutineID atomic.Uint64
18+
19+
warnedNotMigrated bool
20+
)
1721

1822
func SetMainGoroutine() {
1923
mainGoroutineID.Store(goroutineID())
@@ -29,6 +33,7 @@ func EnsureNotMain(fn func()) {
2933
fn()
3034
return
3135
}
36+
PrintFyneDoWarning()
3237

3338
log.Println("*** Error in Fyne call thread, fyne.Do[AndWait] called from main goroutine ***")
3439
log.Println("*** This error needs to be addressed as it will become a deadlock soon ***")
@@ -48,6 +53,7 @@ func EnsureMain(fn func()) {
4853
fn()
4954
return
5055
}
56+
PrintFyneDoWarning()
5157

5258
log.Println("*** Error in Fyne call thread, this should have been called in fyne.Do[AndWait] ***")
5359
log.Println("*** This error needs to be addressed as it could cause concurrent errors soon ***")
@@ -89,3 +95,14 @@ func goroutineID() (id uint64) {
8995

9096
return id
9197
}
98+
99+
func PrintFyneDoWarning() {
100+
if warnedNotMigrated { // shown before
101+
return
102+
}
103+
104+
warnedNotMigrated = true
105+
log.Println("*** This application has not been migrated to the fyne.Do threading model ***")
106+
log.Println("*** The next major Fyne release will remove this safety! ***")
107+
log.Println("*** Read more at https://docs.fyne.io/started/goroutines ***")
108+
}

0 commit comments

Comments
 (0)