more fyne.Dos

This commit is contained in:
Drew Weymouth
2025-02-08 08:35:34 -03:00
parent 61bfbeb349
commit e72e56db1c
3 changed files with 50 additions and 51 deletions
+7 -1
View File
@@ -255,30 +255,36 @@ func (b *BrowsingPane) doSetPage(p Page) bool {
}
func (b *BrowsingPane) onSongChange(song mediaprovider.MediaItem, lastScrobbledIfAny *mediaprovider.Track) {
fyne.Do(func() {
if b.curPage == nil {
return
}
if p, ok := b.curPage.(CanShowNowPlaying); ok {
fyne.Do(func() { p.OnSongChange(song, lastScrobbledIfAny) })
p.OnSongChange(song, lastScrobbledIfAny)
}
})
}
func (b *BrowsingPane) onPlayTimeUpdate(cur, total float64, seeked bool) {
fyne.Do(func() {
if b.curPage == nil {
return
}
if p, ok := b.curPage.(CanShowPlayTime); ok {
p.OnPlayTimeUpdate(cur, total, seeked)
}
})
}
func (b *BrowsingPane) onQueueChange() {
fyne.Do(func() {
if b.curPage == nil {
return
}
if p, ok := b.curPage.(CanShowPlayQueue); ok {
p.OnPlayQueueChange()
}
})
}
func (b *BrowsingPane) addPageToHistory(p Page, truncate bool) {
+8 -19
View File
@@ -9,7 +9,6 @@ import (
"net/url"
"slices"
"strings"
"sync"
"time"
"github.com/cenkalti/dominantcolor"
@@ -49,9 +48,6 @@ type NowPlayingPage struct {
related []*mediaprovider.Track
alreadyLoaded bool
lyricLock sync.Mutex
relatedLock sync.Mutex
// widgets for render
background *canvas.LinearGradient
queueList *widgets.PlayQueueList
@@ -106,9 +102,10 @@ func NewNowPlayingPage(
a := &NowPlayingPage{nowPlayingPageState: state}
a.ExtendBaseWidget(a)
pm.OnPaused(a.formatStatusLine)
pm.OnPlaying(a.formatStatusLine)
pm.OnStopped(a.formatStatusLine)
doFmtStatus := func() { fyne.Do(a.formatStatusLine) }
pm.OnPaused(doFmtStatus)
pm.OnPlaying(doFmtStatus)
pm.OnStopped(doFmtStatus)
a.card = widgets.NewLargeNowPlayingCard()
a.card.OnAlbumNameTapped = func() {
@@ -320,9 +317,6 @@ func (a *NowPlayingPage) onImageLoaded(img image.Image, err error) {
}
func (a *NowPlayingPage) updateLyrics() {
a.lyricLock.Lock()
defer a.lyricLock.Unlock()
if a.lyricFetchCancel != nil {
a.lyricFetchCancel()
}
@@ -369,20 +363,17 @@ func (a *NowPlayingPage) fetchLyrics(ctx context.Context, song *mediaprovider.Tr
case <-ctx.Done():
return
default:
a.lyricLock.Lock()
fyne.Do(func() {
a.lyricsLoading.Stop()
a.lyricsViewer.SetLyrics(lyrics)
if lyrics != nil {
a.lyricsViewer.OnSeeked(a.lastPlayPos)
}
a.lyricLock.Unlock()
})
}
}
func (a *NowPlayingPage) updateRelatedList() {
a.relatedLock.Lock()
defer a.relatedLock.Unlock()
if a.relatedFetchCancel != nil {
a.relatedFetchCancel()
}
@@ -407,11 +398,11 @@ func (a *NowPlayingPage) updateRelatedList() {
case <-ctx.Done():
return
default:
a.relatedLock.Lock()
fyne.Do(func() {
a.related = related
a.relatedList.SetTracks(a.related)
a.relatedLoading.Stop()
a.relatedLock.Unlock()
})
}
}(ctx)
}
@@ -459,8 +450,6 @@ func (a *NowPlayingPage) OnPlayTimeUpdate(curTime, _ float64, seeked bool) {
if a.tabs == nil || a.tabs.SelectedIndex() != 1 /*lyrics*/ {
return
}
a.lyricLock.Lock()
defer a.lyricLock.Unlock()
if seeked {
a.lyricsViewer.OnSeeked(curTime)
} else {
+4
View File
@@ -108,17 +108,21 @@ func (p *PlaylistsPage) Scroll(scrollAmt float32) {
}
}
// should be called asynchronously
func (a *PlaylistsPage) load(searchOnLoad bool) {
playlists, err := a.mp.GetPlaylists()
if err != nil {
log.Printf("error loading playlists: %v", err.Error())
}
fyne.Do(func() {
a.playlists = playlists
if searchOnLoad {
a.onSearched(a.searcher.Entry.Text)
} else {
a.refreshView(playlists)
}
})
}
func (a *PlaylistsPage) createListView() {