Skip to content

Commit

Permalink
Fix #495: use custom user-agent instead of go-http-client
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Oct 17, 2024
1 parent 3fd3c40 commit 58ebd3c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions backend/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (a *App) VersionTag() string {
return a.appVersionTag
}

func StartupApp(appName, displayAppName, appVersionTag, latestReleaseURL string) (*App, error) {
func StartupApp(appName, displayAppName, appVersion, appVersionTag, latestReleaseURL string) (*App, error) {
var confDir, cacheDir string
portableMode := false
if p := checkPortablePath(); p != "" {
Expand Down Expand Up @@ -118,7 +118,7 @@ func StartupApp(appName, displayAppName, appVersionTag, latestReleaseURL string)
return nil, err
}

a.ServerManager = NewServerManager(appName, a.Config, !portableMode /*use keyring*/)
a.ServerManager = NewServerManager(appName, appVersion, a.Config, !portableMode /*use keyring*/)
a.PlaybackManager = NewPlaybackManager(a.bgrndCtx, a.ServerManager, a.LocalPlayer, &a.Config.Scrobbling, &a.Config.Transcoding, &a.Config.Application)
a.ImageManager = NewImageManager(a.bgrndCtx, a.ServerManager, cacheDir)
a.Config.Application.MaxImageCacheSizeMB = clamp(a.Config.Application.MaxImageCacheSizeMB, 1, 500)
Expand Down
14 changes: 12 additions & 2 deletions backend/servermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/tls"
"errors"
"fmt"
"log"
"net/http"
"time"
Expand All @@ -26,15 +27,21 @@ type ServerManager struct {
useKeyring bool
prefetchCoverCB func(string)
appName string
appVersion string
config *Config
onServerConnected []func()
onLogout []func()
}

var ErrUnreachable = errors.New("server is unreachable")

func NewServerManager(appName string, config *Config, useKeyring bool) *ServerManager {
return &ServerManager{appName: appName, config: config, useKeyring: useKeyring}
func NewServerManager(appName, appVersion string, config *Config, useKeyring bool) *ServerManager {
return &ServerManager{
appName: appName,
appVersion: appVersion,
config: config,
useKeyring: useKeyring,
}
}

func (s *ServerManager) SetPrefetchAlbumCoverCallback(cb func(string)) {
Expand Down Expand Up @@ -194,8 +201,10 @@ func (s *ServerManager) connect(connection ServerConnection, password string) (m
}
}
} else {
ua := fmt.Sprintf("%s/%s", s.appName, s.appVersion)
cli = &subsonicMP.SubsonicServer{
Client: subsonic.Client{
UserAgent: ua,
Client: &http.Client{Timeout: 10 * time.Second},
BaseUrl: connection.Hostname,
User: connection.Username,
Expand All @@ -206,6 +215,7 @@ func (s *ServerManager) connect(connection ServerConnection, password string) (m
s.checkSetInsecureSkipVerify(cli.(*subsonicMP.SubsonicServer).Client.Client)
altCli = &subsonicMP.SubsonicServer{
Client: subsonic.Client{
UserAgent: ua,
Client: &http.Client{Timeout: 10 * time.Second},
BaseUrl: connection.AltHostname,
User: connection.Username,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/pelletier/go-toml/v2 v2.0.8
github.com/quarckster/go-mpris-server v1.0.3
github.com/supersonic-app/go-mpv v0.1.0
github.com/supersonic-app/go-subsonic v0.0.0-20240807031555-2cb1ccd78f85
github.com/supersonic-app/go-subsonic v0.0.0-20241017150725-a5686988ef9c
github.com/zalando/go-keyring v0.2.1
golang.org/x/net v0.25.0
golang.org/x/text v0.16.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/supersonic-app/go-mpv v0.1.0 h1:U+cCnLQxmpqx5mY6nMlC0J4uIdCCXUbAjpjS04XkFu8=
github.com/supersonic-app/go-mpv v0.1.0/go.mod h1:1bQz6kBQumJopXEbkiqoLxIXLy7F7yWFBvknvpAtIC0=
github.com/supersonic-app/go-subsonic v0.0.0-20240807031555-2cb1ccd78f85 h1:7PpVvIoF3kUQwqRyIJcKJui8VxbkLzqWH+Ysw1g84tU=
github.com/supersonic-app/go-subsonic v0.0.0-20240807031555-2cb1ccd78f85/go.mod h1:D+OWPXeD9owcdcoXATv5YPBGWxxVvn5k98rt5B4wMc4=
github.com/supersonic-app/go-subsonic v0.0.0-20241017150725-a5686988ef9c h1:UsXe5/TXViPgw21zO2Fgh0F/hSl0TXox0yjRc+vT6XQ=
github.com/supersonic-app/go-subsonic v0.0.0-20241017150725-a5686988ef9c/go.mod h1:D+OWPXeD9owcdcoXATv5YPBGWxxVvn5k98rt5B4wMc4=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
}
// rest of flag actions are handled in backend.StartupApp

myApp, err := backend.StartupApp(res.AppName, res.DisplayName, res.AppVersionTag, res.LatestReleaseURL)
myApp, err := backend.StartupApp(res.AppName, res.DisplayName, res.AppVersion, res.AppVersionTag, res.LatestReleaseURL)
if err != nil {
if err != backend.ErrAnotherInstance {
log.Fatalf("fatal startup error: %v", err.Error())
Expand Down

0 comments on commit 58ebd3c

Please sign in to comment.