Merge branch 'main' into feature/shuffle
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/deluan/sanitize"
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider/jellyfin"
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
"github.com/dweymouth/supersonic/ui/util"
|
||||
)
|
||||
@@ -49,7 +50,13 @@ func (sp *SelectPlaylist) fetchUserOwnedPlaylists() {
|
||||
log.Printf("error getting playlists: %s", err.Error())
|
||||
}
|
||||
userPlaylists := sharedutil.FilterSlice(playlists, func(playlist *mediaprovider.Playlist) bool {
|
||||
return playlist.Owner == sp.loggedInUser
|
||||
if _, isJellyfin := sp.mp.(*jellyfin.JellyfinMediaProvider); isJellyfin {
|
||||
// Jellyfin usernames are case-insensitive
|
||||
return strings.EqualFold(playlist.Owner, sp.loggedInUser)
|
||||
} else {
|
||||
// Subsonic usernames are case-sensitive
|
||||
return playlist.Owner == sp.loggedInUser
|
||||
}
|
||||
})
|
||||
sp.allPlaylistResuts = sharedutil.MapSlice(userPlaylists, sp.playlistToSearchResult)
|
||||
}
|
||||
|
||||
@@ -32,6 +32,10 @@ type PeakMeter struct {
|
||||
lPeakHoldFrame uint64
|
||||
rPeakHoldFrame uint64
|
||||
frameCounter uint64
|
||||
|
||||
// true iff only a layout is needed, rathern than a full refresh.
|
||||
// cleared by the renderer
|
||||
refreshLayoutOnly bool
|
||||
}
|
||||
|
||||
func NewPeakMeter() *PeakMeter {
|
||||
@@ -68,6 +72,7 @@ func (p *PeakMeter) UpdatePeaks(lPeak, rPeak, lRMS, rRMS float64) {
|
||||
}
|
||||
|
||||
p.frameCounter++
|
||||
p.refreshLayoutOnly = true
|
||||
p.Refresh()
|
||||
}
|
||||
|
||||
@@ -75,6 +80,11 @@ func (p *PeakMeter) CreateRenderer() fyne.WidgetRenderer {
|
||||
return newPeakMeterRenderer(p)
|
||||
}
|
||||
|
||||
func (p *PeakMeter) Refresh() {
|
||||
p.refreshLayoutOnly = false
|
||||
p.BaseWidget.Refresh()
|
||||
}
|
||||
|
||||
type peakMeterRenderer struct {
|
||||
p *PeakMeter
|
||||
|
||||
@@ -168,6 +178,12 @@ func (l *peakMeterRenderer) Layout(size fyne.Size) {
|
||||
}
|
||||
|
||||
func (l *peakMeterRenderer) Refresh() {
|
||||
if l.p.refreshLayoutOnly {
|
||||
l.p.refreshLayoutOnly = false
|
||||
l.Layout(l.p.Size())
|
||||
return
|
||||
}
|
||||
|
||||
foreground := theme.ForegroundColor()
|
||||
background := theme.BackgroundColor()
|
||||
errC := theme.ErrorColor()
|
||||
|
||||
+40
-17
@@ -410,6 +410,17 @@ func (t *tracklistRowBase) TrackID() string {
|
||||
}
|
||||
|
||||
func (t *tracklistRowBase) Update(tm *util.TrackListModel, rowNum int, onUpdate func()) {
|
||||
// Show only columns configured to be visible
|
||||
for i := 2; i < len(t.tracklist.columns); i++ {
|
||||
t.setColVisibility(i, !t.tracklist.visibleColumns[i])
|
||||
}
|
||||
|
||||
// Ealy return if nothing else needs updating
|
||||
if !t.needsUpdate(tm, rowNum) {
|
||||
return
|
||||
}
|
||||
|
||||
// Throttle updates when many are happening in a short time
|
||||
if tracklistUpdateCounter.NumEventsSince(time.Now().Add(-300*time.Millisecond)) > 10 {
|
||||
t.doUpdate(&emptyTrack, 1)
|
||||
if t.nextUpdateModel == nil {
|
||||
@@ -434,11 +445,31 @@ func (t *tracklistRowBase) Update(tm *util.TrackListModel, rowNum int, onUpdate
|
||||
}
|
||||
}
|
||||
|
||||
func (t *tracklistRowBase) needsUpdate(tm *util.TrackListModel, rowNum int) bool {
|
||||
tr := tm.Track()
|
||||
if tm.Selected != t.Selected {
|
||||
return true
|
||||
}
|
||||
if t.trackID != tr.ID || t.trackNum != rowNum {
|
||||
return true
|
||||
}
|
||||
if t.playCount != tr.PlayCount || t.isFavorite != tr.Favorite || t.rating.Rating != tr.Rating {
|
||||
return true
|
||||
}
|
||||
if t.rating.IsDisabled != t.tracklist.Options.DisableRating {
|
||||
return true
|
||||
}
|
||||
if isPlaying := t.tracklist.nowPlayingID == tr.ID; isPlaying != t.isPlaying {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *tracklistRowBase) doUpdate(tm *util.TrackListModel, rowNum int) {
|
||||
changed := false
|
||||
fullRefresh := false
|
||||
if tm.Selected != t.Selected {
|
||||
t.Selected = tm.Selected
|
||||
changed = true
|
||||
fullRefresh = true
|
||||
}
|
||||
|
||||
// Update info that can change if this row is bound to
|
||||
@@ -473,7 +504,7 @@ func (t *tracklistRowBase) doUpdate(tm *util.TrackListModel, rowNum int) {
|
||||
t.dateAdded.Text = util.FormatDate(tr.DateAdded)
|
||||
t.path.Text = tr.FilePath
|
||||
t.path.SetToolTip(tr.FilePath)
|
||||
changed = true
|
||||
fullRefresh = true
|
||||
}
|
||||
|
||||
// Update track num if needed
|
||||
@@ -493,21 +524,20 @@ func (t *tracklistRowBase) doUpdate(tm *util.TrackListModel, rowNum int) {
|
||||
} else {
|
||||
str = strconv.Itoa(rowNum)
|
||||
}
|
||||
t.num.Text = str
|
||||
changed = true
|
||||
t.num.SetText(str)
|
||||
}
|
||||
|
||||
// Update play count if needed
|
||||
if tr.PlayCount != t.playCount {
|
||||
t.playCount = tr.PlayCount
|
||||
t.plays.Text = strconv.Itoa(int(tr.PlayCount))
|
||||
changed = true
|
||||
t.plays.SetText(strconv.Itoa(int(tr.PlayCount)))
|
||||
}
|
||||
|
||||
// Render whether track is playing or not
|
||||
if isPlaying := t.tracklist.nowPlayingID == tr.ID; isPlaying != t.isPlaying {
|
||||
t.isPlaying = isPlaying
|
||||
t.name.Segments[0].(*widget.TextSegment).Style.TextStyle.Bold = isPlaying
|
||||
t.name.Refresh()
|
||||
|
||||
if isPlaying {
|
||||
t.originalNumColContent = t.Content.(*fyne.Container).Objects[0]
|
||||
@@ -515,14 +545,14 @@ func (t *tracklistRowBase) doUpdate(tm *util.TrackListModel, rowNum int) {
|
||||
} else {
|
||||
t.Content.(*fyne.Container).Objects[0] = t.originalNumColContent
|
||||
}
|
||||
changed = true
|
||||
canvas.Refresh(t)
|
||||
}
|
||||
|
||||
// Update favorite column
|
||||
if tr.Favorite != t.isFavorite {
|
||||
t.isFavorite = tr.Favorite
|
||||
t.favorite.Objects[0].(*FavoriteIcon).Favorite = tr.Favorite
|
||||
changed = true
|
||||
canvas.Refresh(t.favorite)
|
||||
}
|
||||
|
||||
// Update rating column
|
||||
@@ -535,14 +565,7 @@ func (t *tracklistRowBase) doUpdate(tm *util.TrackListModel, rowNum int) {
|
||||
t.rating.Refresh()
|
||||
}
|
||||
|
||||
// Show only columns configured to be visible
|
||||
for i := 2; i < len(t.tracklist.columns); i++ {
|
||||
if ch := t.setColVisibility(i, !t.tracklist.visibleColumns[i]); ch {
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
|
||||
if changed {
|
||||
if fullRefresh {
|
||||
tracklistUpdateCounter.Add()
|
||||
t.Refresh()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user