From c7adeb5e32ac75983be7358eeb61a9c44cf91913 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Sun, 12 Jan 2025 15:16:07 -0800 Subject: [PATCH] a few more goroutines --- main.go | 2 +- ui/browsing/genrespage.go | 28 +++++++++++++++------------- ui/browsing/nowplayingpage.go | 16 +++++++--------- ui/browsing/playlistpage.go | 3 ++- ui/mainwindow.go | 16 ---------------- ui/util/util.go | 4 +++- 6 files changed, 28 insertions(+), 41 deletions(-) diff --git a/main.go b/main.go index d5c2137..07d5430 100644 --- a/main.go +++ b/main.go @@ -77,7 +77,7 @@ func main() { mainWindow := ui.NewMainWindow(fyneApp, res.AppName, res.DisplayName, res.AppVersion, myApp) mainWindow.Window.SetMaster() myApp.OnReactivate = mainWindow.Show - myApp.OnExit = mainWindow.Quit + myApp.OnExit = func() { fyne.Do(mainWindow.Quit) } fyneApp.Lifecycle().SetOnEnteredForeground(sync.OnceFunc(func() { defaultServer := myApp.ServerManager.GetDefaultServer() diff --git a/ui/browsing/genrespage.go b/ui/browsing/genrespage.go index ea358a3..ceeea50 100644 --- a/ui/browsing/genrespage.go +++ b/ui/browsing/genrespage.go @@ -64,20 +64,22 @@ func (a *GenresPage) load(searchOnLoad bool, scrollPos float32) { if err != nil { log.Printf("error loading genres: %v", err.Error()) } - a.genres = genres - if searchOnLoad { - a.onSearched(a.searcher.Entry.Text) - if scrollPos != 0 { - a.list.list.ScrollToOffset(scrollPos) + fyne.Do(func() { + a.genres = genres + if searchOnLoad { + a.onSearched(a.searcher.Entry.Text) + if scrollPos != 0 { + a.list.list.ScrollToOffset(scrollPos) + } + } else { + a.list.SetGenres(a.genres) + if scrollPos != 0 { + a.list.list.ScrollToOffset(scrollPos) + return + } + a.list.Refresh() } - } else { - a.list.SetGenres(a.genres) - if scrollPos != 0 { - a.list.list.ScrollToOffset(scrollPos) - return - } - a.list.Refresh() - } + }) } func (a *GenresPage) onSearched(query string) { diff --git a/ui/browsing/nowplayingpage.go b/ui/browsing/nowplayingpage.go index c77a459..06262c1 100644 --- a/ui/browsing/nowplayingpage.go +++ b/ui/browsing/nowplayingpage.go @@ -297,7 +297,8 @@ func (a *NowPlayingPage) onImageLoaded(img image.Image, err error) { if err != nil { log.Printf("error loading cover art: %v\n", err) } - a.card.SetCoverImage(img) + + fyne.Do(func() { a.card.SetCoverImage(img) }) if img == nil { return } @@ -307,18 +308,15 @@ func (a *NowPlayingPage) onImageLoaded(img image.Image, err error) { return } - evenFrame := true + // Fyne animation starting is currently thread-safe, + // despite not being marked as such + // TODO: if this changes, use fyne.Do anim := canvas.NewColorRGBAAnimation( a.background.StartColor, c, 75*time.Millisecond, func(c color.Color) { - // reduce fps to reduce mem allocations - if evenFrame { - a.background.StartColor = c - a.background.Refresh() - } - evenFrame = !evenFrame + a.background.StartColor = c + a.background.Refresh() }) anim.Start() - } func (a *NowPlayingPage) updateLyrics() { diff --git a/ui/browsing/playlistpage.go b/ui/browsing/playlistpage.go index f930070..9df0be0 100644 --- a/ui/browsing/playlistpage.go +++ b/ui/browsing/playlistpage.go @@ -349,6 +349,7 @@ func (a *PlaylistPageHeader) Update(playlist *mediaprovider.PlaylistWithTracks) a.Refresh() } +// should be called asynchronously func (a *PlaylistPageHeader) showPopUpCover() { if a.fullSizeCoverFetching || a.playlistInfo == nil { return @@ -361,7 +362,7 @@ func (a *PlaylistPageHeader) showPopUpCover() { return } if a.page != nil { - a.page.contr.ShowPopUpImage(cover) + fyne.Do(func() { a.page.contr.ShowPopUpImage(cover) }) } } diff --git a/ui/mainwindow.go b/ui/mainwindow.go index d90e5e9..d7e3e4f 100644 --- a/ui/mainwindow.go +++ b/ui/mainwindow.go @@ -133,22 +133,6 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string, m.Window.SetCloseIntercept(func() { m.SaveWindowSize() - // save settings in case we crash during shutdown - // TODO: when all shutdowns exit cleanly, remove these lines - // as they are already executed in app.Shutdown() - app.Config.LocalPlayback.Volume = app.LocalPlayer.GetVolume() - repeatMode := "None" - switch app.PlaybackManager.GetLoopMode() { - case backend.LoopOne: - repeatMode = "One" - case backend.LoopAll: - repeatMode = "All" - } - app.Config.Playback.RepeatMode = repeatMode - app.Config.Playback.Autoplay = app.PlaybackManager.IsAutoplay() - app.SavePlayQueueIfEnabled() - app.SaveConfigFile() - if app.Config.Application.CloseToSystemTray && m.HaveSystemTray() { m.Window.Hide() } else { diff --git a/ui/util/util.go b/ui/util/util.go index 25fb190..1757cdd 100644 --- a/ui/util/util.go +++ b/ui/util/util.go @@ -199,7 +199,9 @@ func NewDebouncer(dur time.Duration, callOnDone func()) func() { if timer != nil { timer.Stop() } - timer = time.AfterFunc(dur, callOnDone) + timer = time.AfterFunc(dur, func() { + fyne.Do(callOnDone) + }) } }