From 538e201e228f58434b032b4be2e18cd39277da67 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Thu, 30 Jan 2025 22:49:06 -0300 Subject: [PATCH] fyne.Do in radios page and loading dots widget --- ui/browsing/radiospage.go | 37 ++++++++++++++++++++----------------- ui/widgets/loadingdots.go | 4 ++-- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/ui/browsing/radiospage.go b/ui/browsing/radiospage.go index 1bedd614..a43b447b 100644 --- a/ui/browsing/radiospage.go +++ b/ui/browsing/radiospage.go @@ -78,25 +78,28 @@ func (a *RadiosPage) load(searchOnLoad bool, scrollPos float32) { if err != nil { log.Printf("error loading radios: %v", err.Error()) } - if len(radios) == 0 { - a.noRadiosMsg.Show() - } else { - a.noRadiosMsg.Hide() - } - a.radios = radios - if searchOnLoad { - a.onSearched(a.searcher.Entry.Text) - if scrollPos != 0 { - a.list.list.ScrollToOffset(scrollPos) + + fyne.Do(func() { + if len(radios) == 0 { + a.noRadiosMsg.Show() + } else { + a.noRadiosMsg.Hide() } - } else { - a.list.SetRadios(a.radios) - if scrollPos != 0 { - a.list.list.ScrollToOffset(scrollPos) - return + a.radios = radios + if searchOnLoad { + a.onSearched(a.searcher.Entry.Text) + if scrollPos != 0 { + a.list.list.ScrollToOffset(scrollPos) + } + } else { + a.list.SetRadios(a.radios) + if scrollPos != 0 { + a.list.list.ScrollToOffset(scrollPos) + return + } + a.list.Refresh() } - a.list.Refresh() - } + }) } func (a *RadiosPage) onPlay(station *mediaprovider.RadioStation) { diff --git a/ui/widgets/loadingdots.go b/ui/widgets/loadingdots.go index 2f2f5488..47d19c63 100644 --- a/ui/widgets/loadingdots.go +++ b/ui/widgets/loadingdots.go @@ -62,16 +62,16 @@ func (l *LoadingDots) Stop() { func (l *LoadingDots) animate(ctx context.Context) { foreground := theme.ForegroundColor() disabled := theme.DisabledColor() - l.doTick(foreground, disabled) ticker := time.NewTicker(333 * time.Millisecond) for { + fyne.Do(func() { l.doTick(foreground, disabled) }) select { case <-ctx.Done(): ticker.Stop() l.running.Store(false) return case <-ticker.C: - fyne.Do(func() { l.doTick(foreground, disabled) }) + continue } } }