Run gofumpt on the project

This commit is contained in:
Jacalz
2025-09-17 22:30:49 +02:00
parent 534a7bfaaf
commit 08f335da44
41 changed files with 92 additions and 84 deletions
+1 -1
View File
@@ -317,7 +317,7 @@ func (c *Config) WriteConfigFile(filepath string) error {
if err != nil {
return err
}
os.WriteFile(filepath, b, 0644)
os.WriteFile(filepath, b, 0o644)
return nil
}
+1 -4
View File
@@ -39,9 +39,7 @@ type ImageCache struct {
cache map[string]CacheItem
}
var (
ErrNotFound = errors.New("item not found")
)
var ErrNotFound = errors.New("item not found")
func (i *ImageCache) Init(ctx context.Context, evictionInterval time.Duration) {
i.cache = make(map[string]CacheItem)
@@ -238,5 +236,4 @@ func (i *ImageCache) EvictExpired() {
delete(i.cache, key)
}
}
}
-1
View File
@@ -130,7 +130,6 @@ func (c *Client) Quit() error {
func (c *Client) sendRequest(path string) (string, error) {
resp, err := c.httpC.Get("http://supersonic/" + path)
if err != nil {
return "", err
}
@@ -438,7 +438,7 @@ func toTrack(ch *jellyfin.Song) *mediaprovider.Track {
Duration: time.Duration(ch.RunTimeTicks/runTimeTicksPerMicrosecond) * time.Microsecond,
TrackNumber: ch.IndexNumber,
DiscNumber: ch.DiscNumber,
//Genre: ch.Genres,
// Genre: ch.Genres,
ArtistIDs: artistIDs,
ArtistNames: artistNames,
Album: ch.Album,
+5 -3
View File
@@ -32,9 +32,11 @@ type MediaIterator[M any] interface {
Next() *M
}
type ArtistIterator = MediaIterator[Artist]
type AlbumIterator = MediaIterator[Album]
type TrackIterator = MediaIterator[Track]
type (
ArtistIterator = MediaIterator[Artist]
AlbumIterator = MediaIterator[Album]
TrackIterator = MediaIterator[Track]
)
type MediaFilter[M, F any] interface {
Options() F
@@ -298,7 +298,8 @@ func (s *subsonicMediaProvider) ClientDecidesScrobble() bool { return true }
func (s *subsonicMediaProvider) TrackBeganPlayback(trackID string) error {
return s.client.Scrobble(trackID, map[string]string{
"time": strconv.FormatInt(time.Now().UnixMilli(), 10),
"submission": "false"})
"submission": "false",
})
}
func (s *subsonicMediaProvider) TrackEndedPlayback(trackID string, _ int, submission bool) error {
@@ -307,7 +308,8 @@ func (s *subsonicMediaProvider) TrackEndedPlayback(trackID string, _ int, submis
}
return s.client.Scrobble(trackID, map[string]string{
"time": strconv.FormatInt(time.Now().UnixMilli(), 10),
"submission": "true"})
"submission": "true",
})
}
func (s *subsonicMediaProvider) SetFavorite(params mediaprovider.RatingFavoriteParameters, favorite bool) error {
+1 -3
View File
@@ -24,9 +24,7 @@ var (
_ types.OrgMprisMediaPlayer2PlayerAdapterLoopStatus = (*MPRISHandler)(nil)
)
var (
errNotSupported = errors.New("not supported")
)
var errNotSupported = errors.New("not supported")
type MPRISHandler struct {
// Function called if the player is requested to quit through MPRIS.
-1
View File
@@ -109,7 +109,6 @@ func (j *JukeboxPlayer) SetNextTrack(track *mediaprovider.Track) error {
}
j.queueLength += 1
return nil
}
func (j *JukeboxPlayer) SeekSeconds(secs float64) error {
+1
View File
@@ -3,6 +3,7 @@ package mpv
// #include <mpv/client.h>
// int mpv_get_peaks(mpv_handle* handle, double* lPeak, double* rPeak, double* lRMS, double* rRMS);
import "C"
import (
"github.com/supersonic-app/go-mpv"
)
+1 -1
View File
@@ -492,7 +492,7 @@ func (p *Player) eventHandler(ctx context.Context) {
default:
e := p.mpv.WaitEvent(1 /*timeout seconds*/)
if e.Event_Id != mpv.EVENT_NONE {
//log.Printf("mpv event: %+v\n", e)
// log.Printf("mpv event: %+v\n", e)
}
switch e.Event_Id {
case mpv.EVENT_PLAYBACK_RESTART:
+1 -1
View File
@@ -51,7 +51,7 @@ func SavePlayQueue(serverID string, pm *PlaybackManager, filepath string, server
TimePos: stats.TimePos,
}
b, _ := json.Marshal(saved)
err := os.WriteFile(filepath, b, 0644)
err := os.WriteFile(filepath, b, 0o644)
if server != nil {
// save to server
+2 -2
View File
@@ -308,7 +308,7 @@ func analyzeWavFile(ctx context.Context, transcodeFile string, data *waveformDat
currentSize := stat.Size()
// how many bytes can we read without nearing EOF
readableBytes := currentSize - int64(samplesPerChunk)*int64(curChunk)*bytesPerSample - 8192 //buffer for safety
readableBytes := currentSize - int64(samplesPerChunk)*int64(curChunk)*bytesPerSample - 8192 // buffer for safety
// Estimate how many samples we can read
maxSamples := int(readableBytes / bytesPerSample)
@@ -391,7 +391,7 @@ func computePeakAndRMS(chunk []float64) (peak float64, rms float64) {
sumSquares += float64(v * v)
}
rms = math.Sqrt(sumSquares / float64(len(chunk)))
return
return peak, rms
}
func float64ToByte(val float64) byte {
+4 -2
View File
@@ -17,8 +17,10 @@ import (
"golang.org/x/sys/windows"
)
type SMTCPlaybackState int
type SMTCButton int
type (
SMTCPlaybackState int
SMTCButton int
)
const (
// constants from smtc.h in github.com/supersonic-app/smtc-dll
+4 -2
View File
@@ -4,8 +4,10 @@ package windows
import "errors"
type SMTCPlaybackState int
type SMTCButton int
type (
SMTCPlaybackState int
SMTCButton int
)
const (
// constants from smtc.h in github.com/supersonic-app/smtc-dll
+1
View File
@@ -10,6 +10,7 @@ package windows
extern void goButtonClicked(int);
*/
import "C"
import (
"errors"
"image"
-1
View File
@@ -8,7 +8,6 @@ import (
)
func Test_ReorderItems(t *testing.T) {
tracks := []*mediaprovider.Track{
{ID: "a"}, // 0
{ID: "b"}, // 1
+1 -1
View File
@@ -486,7 +486,7 @@ type ArtistPageHeader struct {
menuBtn *widget.Button
container *fyne.Container
fullSizeCoverFetching bool
//shareMenuItem *fyne.MenuItem
// shareMenuItem *fyne.MenuItem
}
func NewArtistPageHeader(page *ArtistPage) *ArtistPageHeader {
+3 -2
View File
@@ -204,7 +204,8 @@ func NewGenreList(sorting widgets.ListHeaderSort) *GenreList {
a.hdr = widgets.NewListHeader([]widgets.ListColumn{
{Text: lang.L("Name"), Alignment: fyne.TextAlignLeading, CanToggleVisible: false},
{Text: albumCount, Alignment: fyne.TextAlignTrailing, CanToggleVisible: false},
{Text: trackCount, Alignment: fyne.TextAlignTrailing, CanToggleVisible: false}},
{Text: trackCount, Alignment: fyne.TextAlignTrailing, CanToggleVisible: false},
},
a.columnsLayout)
a.hdr.SetSorting(sorting)
a.hdr.OnColumnSortChanged = a.onSorted
@@ -261,7 +262,7 @@ func (g *GenreList) doSortGenres() {
return
}
switch g.sorting.ColNumber {
case 0: //Name
case 0: // Name
g.stringSort(func(g *mediaprovider.Genre) string { return g.Name })
case 1: // Album Count
g.intSort(func(g *mediaprovider.Genre) int { return g.AlbumCount })
+4 -3
View File
@@ -360,8 +360,10 @@ func (a *NowPlayingPage) updateLyrics() {
// set the widget to an empty (not nil) lyric during fetch
// to keep it from showing "Lyrics not available"
a.lyricsViewer.DisableTapToSeek()
a.lyricsViewer.SetLyrics(&mediaprovider.Lyrics{Synced: true,
Lines: []mediaprovider.LyricLine{{Text: ""}}})
a.lyricsViewer.SetLyrics(&mediaprovider.Lyrics{
Synced: true,
Lines: []mediaprovider.LyricLine{{Text: ""}},
})
tr, _ := a.nowPlaying.(*mediaprovider.Track)
go a.fetchLyrics(ctx, tr)
}
@@ -482,7 +484,6 @@ func (a *NowPlayingPage) OnPlayTimeUpdate(curTime, _ float64, seeked bool) {
func (a *NowPlayingPage) currentTracklistOrNil() *widgets.PlayQueueList {
if a.tabs != nil {
switch a.tabs.SelectedIndex() {
case 0: /*queue*/
return a.queueList
+3 -2
View File
@@ -389,7 +389,8 @@ func (p *PlaylistList) buildHeaderAndLayout() {
{Text: lang.L("Name"), Alignment: fyne.TextAlignLeading, CanToggleVisible: false},
{Text: lang.L("_Description"), Alignment: fyne.TextAlignLeading, CanToggleVisible: false},
{Text: lang.L("Owner"), Alignment: fyne.TextAlignLeading, CanToggleVisible: false},
{Text: trackCount, Alignment: fyne.TextAlignTrailing, CanToggleVisible: false}}, p.columnsLayout)
{Text: trackCount, Alignment: fyne.TextAlignTrailing, CanToggleVisible: false},
}, p.columnsLayout)
p.header.SetSorting(p.sorting)
p.header.OnColumnSortChanged = p.onSorted
}
@@ -422,7 +423,7 @@ func (p *PlaylistList) doSortPlaylists() {
return
}
switch p.sorting.ColNumber {
case 0: //Name
case 0: // Name
p.stringSort(func(p *mediaprovider.Playlist) string { return p.Name })
case 1: // Description
p.stringSort(func(p *mediaprovider.Playlist) string { return p.Description })
+4 -4
View File
@@ -253,7 +253,8 @@ func NewRadioList(nowPlayingIDPtr *string) *RadioList {
a.ExtendBaseWidget(a)
a.hdr = widgets.NewListHeader([]widgets.ListColumn{
{Text: lang.L("Name"), Alignment: fyne.TextAlignLeading, CanToggleVisible: false},
{Text: lang.L("Home Page"), Alignment: fyne.TextAlignLeading, CanToggleVisible: false}},
{Text: lang.L("Home Page"), Alignment: fyne.TextAlignLeading, CanToggleVisible: false},
},
a.columnsLayout)
a.hdr.DisableSorting = true
a.list = widgets.NewFocusList(
@@ -299,9 +300,8 @@ func NewRadioList(nowPlayingIDPtr *string) *RadioList {
row.IsPlaying = isPlaying
row.nameLabel.Segments[0].(*widget.TextSegment).Style.TextStyle.Bold = isPlaying
if isPlaying {
row.Content.(*fyne.Container).Objects[0] =
container.NewBorder(nil, nil, a.playingIcon, nil,
container.New(layout.NewCustomPaddedLayout(0, 0, -5, 0), row.nameLabel))
row.Content.(*fyne.Container).Objects[0] = container.NewBorder(nil, nil, a.playingIcon, nil,
container.New(layout.NewCustomPaddedLayout(0, 0, -5, 0), row.nameLabel))
} else {
row.Content.(*fyne.Container).Objects[0] = row.nameLabel
}
-3
View File
@@ -309,7 +309,6 @@ func (c *Controller) ShowAboutDialog() {
}
func (c *Controller) ShowSettingsDialog(themeUpdateCallbk func(), themeFiles map[string]string) {
devs, err := c.App.LocalPlayer.ListAudioDevices()
if err != nil {
log.Printf("error listing audio devices: %v", err)
@@ -358,7 +357,6 @@ func (c *Controller) ShowSettingsDialog(themeUpdateCallbk func(), themeFiles map
c.ClosePopUpOnEscape(pop)
c.haveModal = true
pop.Show()
}
func (c *Controller) doModalClosed() {
@@ -467,7 +465,6 @@ func (c *Controller) ShowDownloadDialog(tracks []*mediaprovider.Track, downloadN
} else {
go c.downloadTracks(tracks, file.URI().Path(), downloadName)
}
},
c.MainWindow)
dg.SetFileName(fileName)
-1
View File
@@ -88,7 +88,6 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) {
}()
}
}
})
m.ClosePopUpOnEscape(pop)
m.haveModal = true
+1
View File
@@ -81,6 +81,7 @@ func GenresRoute() Route {
func PlaylistRoute(id string) Route {
return Route{Page: Playlist, Arg: id}
}
func PlaylistsRoute() Route {
return Route{Page: Playlists}
}
-1
View File
@@ -200,7 +200,6 @@ func (m *Controller) PromptForLoginAndConnect() {
pop.Show()
}
}, m.MainWindow)
}
m.haveModal = true
pop.Show()
-1
View File
@@ -374,5 +374,4 @@ func (q *searchEntry) TypedKey(e *fyne.KeyEvent) {
default:
q.SearchEntry.TypedKey(e)
}
}
+2 -1
View File
@@ -488,7 +488,8 @@ func (s *SettingsDialog) createAppearanceTab(window fyne.Window) *container.TabI
themeModeSelect := widget.NewSelect([]string{
string(myTheme.AppearanceDark),
string(myTheme.AppearanceLight),
string(myTheme.AppearanceAuto)}, nil)
string(myTheme.AppearanceAuto),
}, nil)
themeModeSelect.OnChanged = func(_ string) {
s.config.Theme.Appearance = themeModeSelect.Options[themeModeSelect.SelectedIndex()]
if s.OnThemeSettingChanged != nil {
+4 -2
View File
@@ -20,6 +20,8 @@ var (
ShortcutNavSeven = desktop.CustomShortcut{KeyName: fyne.Key7, Modifier: fyne.KeyModifierShortcutDefault}
ShortcutNavEight = desktop.CustomShortcut{KeyName: fyne.Key8, Modifier: fyne.KeyModifierShortcutDefault}
NavShortcuts = []desktop.CustomShortcut{ShortcutNavOne, ShortcutNavTwo, ShortcutNavThree,
ShortcutNavFour, ShortcutNavFive, ShortcutNavSix, ShortcutNavSeven, ShortcutNavEight}
NavShortcuts = []desktop.CustomShortcut{
ShortcutNavOne, ShortcutNavTwo, ShortcutNavThree,
ShortcutNavFour, ShortcutNavFive, ShortcutNavSix, ShortcutNavSeven, ShortcutNavEight,
}
)
-1
View File
@@ -89,7 +89,6 @@ func (t *ToastOverlay) makeToastAnimFunc(endPos fyne.Position, dismissal bool) f
t.cancelPreviousToast()
}
}
}
}
+3 -3
View File
@@ -225,7 +225,7 @@ func colorToHexAndOpacity(color color.Color) (hexStr, aStr string) {
r, g, b, a := toNRGBA(color)
cBytes := []byte{byte(r), byte(g), byte(b)}
hexStr, aStr = "#"+hex.EncodeToString(cBytes), strconv.FormatFloat(float64(a)/0xff, 'f', 6, 64)
return
return hexStr, aStr
}
// toNRGBA converts a color to RGBA values which are not premultiplied, unlike color.RGBA().
@@ -300,7 +300,7 @@ func toNRGBA(c color.Color) (r, g, b, a int) {
default: // RGBA, RGBA64, and unknown implementations of Color
r, g, b, a = unmultiplyAlpha(c)
}
return
return r, g, b, a
}
// unmultiplyAlpha returns a color's RGBA components as 8-bit integers by calling c.RGBA() and then removing the alpha premultiplication.
@@ -317,5 +317,5 @@ func unmultiplyAlpha(c color.Color) (r, g, b, a int) {
g = int(green >> 8)
b = int(blue >> 8)
a = int(alpha >> 8)
return
return r, g, b, a
}
+1 -1
View File
@@ -55,7 +55,7 @@ func dateFormatForLocale(locale string) DateFormat {
}
func shortMonthName(month int) string {
var months = [12]string{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"}
months := [12]string{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"}
if month >= 1 && month <= 12 {
return lang.L(months[month-1])
}
+1 -1
View File
@@ -210,7 +210,7 @@ func (l *peakMeterRenderer) Refresh() {
func (l *peakMeterRenderer) Objects() []fyne.CanvasObject {
if l.objects == nil {
l.objects = make([]fyne.CanvasObject, 0, 2*len(l.rulerLines) + 8)
l.objects = make([]fyne.CanvasObject, 0, 2*len(l.rulerLines)+8)
for i := range l.rulerLines {
l.objects = append(l.objects, &l.rulerLines[i], &l.rulerLabels[i])
}
+1 -1
View File
@@ -49,7 +49,7 @@ func NewAuxControls(initialVolume int, initialLoopMode backend.LoopMode, initial
a.cast.SetToolTip(lang.L("Cast to device"))
a.autoplay.Highlighted = initialAutoplay
//a.autoplay.IconSize = IconButtonSizeSmaller
// a.autoplay.IconSize = IconButtonSizeSmaller
a.autoplay.SetToolTip(lang.L("Autoplay"))
a.autoplay.OnTapped = func() {
a.SetAutoplay(!a.autoplay.Highlighted)
+7 -5
View File
@@ -71,10 +71,12 @@ func (g *FocusList) FocusNeighbor(curItem widget.ListItemID, up bool) {
}
}
var _ fyne.Tappable = (*FocusListRowBase)(nil)
var _ fyne.Widget = (*FocusListRowBase)(nil)
var _ fyne.Focusable = (*FocusListRowBase)(nil)
var _ desktop.Hoverable = (*FocusListRowBase)(nil)
var (
_ fyne.Tappable = (*FocusListRowBase)(nil)
_ fyne.Widget = (*FocusListRowBase)(nil)
_ fyne.Focusable = (*FocusListRowBase)(nil)
_ desktop.Hoverable = (*FocusListRowBase)(nil)
)
// Base type used for all list rows in widgets such as Tracklist, etc.
type FocusListRowBase struct {
@@ -88,7 +90,7 @@ type FocusListRowBase struct {
OnTapped func()
OnDoubleTapped func()
OnFocusNeighbor func(up bool) //TODO: func(up, selecting bool)
OnFocusNeighbor func(up bool) // TODO: func(up, selecting bool)
tappedAt int64 // unixMillis
focusedRect canvas.Rectangle
+4 -2
View File
@@ -21,8 +21,10 @@ import (
"github.com/dweymouth/supersonic/ui/util"
)
var _ fyne.Widget = (*GridViewItem)(nil)
var _ fyne.Focusable = (*GridViewItem)(nil)
var (
_ fyne.Widget = (*GridViewItem)(nil)
_ fyne.Focusable = (*GridViewItem)(nil)
)
var _ fyne.Widget = (*coverImage)(nil)
+4 -2
View File
@@ -28,8 +28,10 @@ type LoadingDots struct {
func NewLoadingDots() *LoadingDots {
l := &LoadingDots{}
for i := range l.dots {
l.dots[i] = minSizeCircle{Circle: canvas.Circle{
FillColor: theme.DisabledColor()},
l.dots[i] = minSizeCircle{
Circle: canvas.Circle{
FillColor: theme.DisabledColor(),
},
}
}
l.ExtendBaseWidget(l)
+5 -5
View File
@@ -31,7 +31,7 @@ type MultiHyperlink struct {
// TODO: Once https://github.com/fyne-io/fyne/issues/4336 is resolved,
// we can switch to the much cleaner RichText implementation
//provider *widget.RichText
// provider *widget.RichText
objects []fyne.CanvasObject
suffixLabel *ttwidget.RichText
@@ -45,11 +45,11 @@ type MultiHyperlinkSegment struct {
func NewMultiHyperlink() *MultiHyperlink {
c := &MultiHyperlink{
//provider: widget.NewRichText(),
// provider: widget.NewRichText(),
content: container.NewWithoutLayout(),
}
c.ExtendBaseWidget(c)
//c.provider.Truncation = fyne.TextTruncateEllipsis
// c.provider.Truncation = fyne.TextTruncateEllipsis
return c
}
@@ -302,12 +302,12 @@ func (c *MultiHyperlink) Resize(size fyne.Size) {
}
func (c *MultiHyperlink) Refresh() {
//c.syncSegments()
// c.syncSegments()
c.layoutObjects()
c.BaseWidget.Refresh()
}
func (c *MultiHyperlink) CreateRenderer() fyne.WidgetRenderer {
return widget.NewSimpleRenderer(c.content)
//return widget.NewSimpleRenderer(c.provider)
// return widget.NewSimpleRenderer(c.provider)
}
-1
View File
@@ -264,7 +264,6 @@ func (p *PlayQueueList) onShowContextMenu(e *fyne.PointEvent, trackIdx int) {
p.ensureRadiosMenu()
p.radiosMenu.ShowAtPosition(e.AbsolutePosition)
}
}
func (p *PlayQueueList) ensureTracksMenu() {
+1 -1
View File
@@ -103,7 +103,7 @@ var _ fyne.Tappable = (*StarRating)(nil)
func (s *StarRating) Tapped(*fyne.PointEvent) {
if s.mouseHoverRating <= 0 {
return //shouldn't happen
return // shouldn't happen
}
if s.Rating == s.mouseHoverRating {
s.Rating = 0
+1
View File
@@ -352,6 +352,7 @@ func (t *tracklistRowBase) create(tracklist *Tracklist) {
func (t *tracklistRowBase) SetOnTappedSecondary(f func(*fyne.PointEvent, int)) {
t.OnTappedSecondary = f
}
func (t *tracklistRowBase) TrackID() string {
return t.trackID
}