Skip to content

Commit

Permalink
more fyne.Dos
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Jan 30, 2025
1 parent 5b08fc3 commit 4e1f51f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 51 deletions.
42 changes: 24 additions & 18 deletions ui/browsing/browsingpane.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,30 +255,36 @@ func (b *BrowsingPane) doSetPage(p Page) bool {
}

func (b *BrowsingPane) onSongChange(song mediaprovider.MediaItem, lastScrobbledIfAny *mediaprovider.Track) {
if b.curPage == nil {
return
}
if p, ok := b.curPage.(CanShowNowPlaying); ok {
fyne.Do(func() { p.OnSongChange(song, lastScrobbledIfAny) })
}
fyne.Do(func() {
if b.curPage == nil {
return
}
if p, ok := b.curPage.(CanShowNowPlaying); ok {
p.OnSongChange(song, lastScrobbledIfAny)
}
})
}

func (b *BrowsingPane) onPlayTimeUpdate(cur, total float64, seeked bool) {
if b.curPage == nil {
return
}
if p, ok := b.curPage.(CanShowPlayTime); ok {
p.OnPlayTimeUpdate(cur, total, seeked)
}
fyne.Do(func() {
if b.curPage == nil {
return
}
if p, ok := b.curPage.(CanShowPlayTime); ok {
p.OnPlayTimeUpdate(cur, total, seeked)
}
})
}

func (b *BrowsingPane) onQueueChange() {
if b.curPage == nil {
return
}
if p, ok := b.curPage.(CanShowPlayQueue); ok {
p.OnPlayQueueChange()
}
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) {
Expand Down
43 changes: 16 additions & 27 deletions ui/browsing/nowplayingpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/url"
"slices"
"strings"
"sync"
"time"

"github.com/cenkalti/dominantcolor"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -369,20 +363,17 @@ func (a *NowPlayingPage) fetchLyrics(ctx context.Context, song *mediaprovider.Tr
case <-ctx.Done():
return
default:
a.lyricLock.Lock()
a.lyricsLoading.Stop()
a.lyricsViewer.SetLyrics(lyrics)
if lyrics != nil {
a.lyricsViewer.OnSeeked(a.lastPlayPos)
}
a.lyricLock.Unlock()
fyne.Do(func() {
a.lyricsLoading.Stop()
a.lyricsViewer.SetLyrics(lyrics)
if lyrics != nil {
a.lyricsViewer.OnSeeked(a.lastPlayPos)
}
})
}
}

func (a *NowPlayingPage) updateRelatedList() {
a.relatedLock.Lock()
defer a.relatedLock.Unlock()

if a.relatedFetchCancel != nil {
a.relatedFetchCancel()
}
Expand All @@ -407,11 +398,11 @@ func (a *NowPlayingPage) updateRelatedList() {
case <-ctx.Done():
return
default:
a.relatedLock.Lock()
a.related = related
a.relatedList.SetTracks(a.related)
a.relatedLoading.Stop()
a.relatedLock.Unlock()
fyne.Do(func() {
a.related = related
a.relatedList.SetTracks(a.related)
a.relatedLoading.Stop()
})
}
}(ctx)
}
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 10 additions & 6 deletions ui/browsing/playlistspage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
a.playlists = playlists
if searchOnLoad {
a.onSearched(a.searcher.Entry.Text)
} else {
a.refreshView(playlists)
}

fyne.Do(func() {
a.playlists = playlists
if searchOnLoad {
a.onSearched(a.searcher.Entry.Text)
} else {
a.refreshView(playlists)
}
})
}

func (a *PlaylistsPage) createListView() {
Expand Down

0 comments on commit 4e1f51f

Please sign in to comment.