Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Jan 30, 2025
1 parent b6bf4d6 commit ac4e63a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 29 deletions.
4 changes: 3 additions & 1 deletion app/app_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,7 @@ func runScript(name, script string) {
}

func watchTheme(s *settings) {
go internalapp.WatchTheme(s.setupTheme)
go internalapp.WatchTheme(func() {
fyne.Do(s.setupTheme)
})
}
10 changes: 1 addition & 9 deletions app/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,12 @@ func (s *settings) ThemeVariant() fyne.ThemeVariant {
return s.variant
}

// must be called from main goroutine
func (s *settings) applyTheme(theme fyne.Theme, variant fyne.ThemeVariant) {
s.variant = variant
s.theme = theme
s.apply()
}

// must be called from main goroutine
func (s *settings) applyVariant(variant fyne.ThemeVariant) {
s.variant = variant
s.apply()
Expand Down Expand Up @@ -168,13 +166,7 @@ func (s *settings) setupTheme() {
variant = theme.VariantDark
}

if async.IsMainGoroutine() {
s.applyTheme(effectiveTheme, variant)
} else {
fyne.Do(func() {
s.applyTheme(effectiveTheme, variant)
})
}
s.applyTheme(effectiveTheme, variant)
}

func loadSettings() *settings {
Expand Down
33 changes: 14 additions & 19 deletions internal/driver/glfw/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,24 @@ func (d *gLDriver) runGL() {
if d.trayStart != nil {
d.trayStart()
}
if f := fyne.CurrentApp().Lifecycle().(*app.Lifecycle).OnStarted(); f != nil {
f()
}

var pendingSettings fyne.Settings
fyne.CurrentApp().Settings().AddListener(func(set fyne.Settings) {
pendingSettings = set
painter.ClearFontCache()
cache.ResetThemeCaches()
app.ApplySettingsWithCallback(set, fyne.CurrentApp(), func(w fyne.Window) {
c, ok := w.Canvas().(*glCanvas)
if !ok {
return
}
c.applyThemeOutOfTreeObjects()
c.reloadScale()
})
})

if f := fyne.CurrentApp().Lifecycle().(*app.Lifecycle).OnStarted(); f != nil {
f()
}

eventTick := time.NewTicker(time.Second / 60)
for {
select {
Expand Down Expand Up @@ -156,20 +165,6 @@ func (d *gLDriver) runGL() {
d.animation.TickAnimations()
d.drawSingleFrame()
}

if pendingSettings != nil {
painter.ClearFontCache()
cache.ResetThemeCaches()
app.ApplySettingsWithCallback(pendingSettings, fyne.CurrentApp(), func(w fyne.Window) {
c, ok := w.Canvas().(*glCanvas)
if !ok {
return
}
c.applyThemeOutOfTreeObjects()
c.reloadScale()
})
pendingSettings = nil
}
}
}

Expand Down

0 comments on commit ac4e63a

Please sign in to comment.