Fix #104: add alternate hostname to server connection config
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
- [#117](https://github.com/dweymouth/supersonic/issues/117) Add (optional) system tray menu and close to tray support
|
- [#117](https://github.com/dweymouth/supersonic/issues/117) Add (optional) system tray menu and close to tray support
|
||||||
- [#55](https://github.com/dweymouth/supersonic/issues/55) Show disc number and disc count for multi-disc albums
|
- [#55](https://github.com/dweymouth/supersonic/issues/55) Show disc number and disc count for multi-disc albums
|
||||||
- [#115](https://github.com/dweymouth/supersonic/issues/115) Add search bar to artist, genres, and playlists pages
|
- [#115](https://github.com/dweymouth/supersonic/issues/115) Add search bar to artist, genres, and playlists pages
|
||||||
|
- [#104](https://github.com/dweymouth/supersonic/issues/104) Add alternate (e.g. external) hostname to server connection config
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
- **todo-commithash** Don't show update available prompt if the found version is the same as the running app version
|
- **todo-commithash** Don't show update available prompt if the found version is the same as the running app version
|
||||||
|
|||||||
@@ -13,11 +13,11 @@ Screenshots of Supersonic running against the Navidrome [demo server](https://ww
|
|||||||
<a href="https://raw.githubusercontent.com/dweymouth/supersonic/main/res/screenshots/FavoriteSongsView.png"><img src="https://raw.github.com/dweymouth/supersonic/main/res/screenshots/FavoriteSongsView.png" width="49.5%"/></a>
|
<a href="https://raw.githubusercontent.com/dweymouth/supersonic/main/res/screenshots/FavoriteSongsView.png"><img src="https://raw.github.com/dweymouth/supersonic/main/res/screenshots/FavoriteSongsView.png" width="49.5%"/></a>
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
* [x] Fast, lightweight, native UI
|
* [x] Fast, lightweight, native UI with infinite scrolling
|
||||||
* [x] High-quality gapless audio playback powered by MPV, with optional audio exclusive mode
|
* [x] High-quality gapless audio playback powered by MPV, with optional audio exclusive mode
|
||||||
* [x] ReplayGain support (depends on files being tagged on server)
|
* [x] ReplayGain support (depends on files being tagged on server)
|
||||||
* [x] Infinite scrolling
|
|
||||||
* [x] Scrobble plays to server, with configurable criteria
|
* [x] Scrobble plays to server, with configurable criteria
|
||||||
|
* [x] Primary and alternate server hostnames, e.g. for internal and external URLs
|
||||||
* [x] Browse by albums, artists, genres, playlists
|
* [x] Browse by albums, artists, genres, playlists
|
||||||
* [x] Album and playlist views with tracklist and cover image
|
* [x] Album and playlist views with tracklist and cover image
|
||||||
* [x] Artist view with biography, image, similar artists, and discography
|
* [x] Artist view with biography, image, similar artists, and discography
|
||||||
|
|||||||
+10
-7
@@ -7,12 +7,17 @@ import (
|
|||||||
"github.com/pelletier/go-toml"
|
"github.com/pelletier/go-toml"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServerConfig struct {
|
type ServerConnection struct {
|
||||||
ID uuid.UUID
|
|
||||||
Nickname string
|
|
||||||
Hostname string
|
Hostname string
|
||||||
|
AltHostname string
|
||||||
Username string
|
Username string
|
||||||
LegacyAuth bool
|
LegacyAuth bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServerConfig struct {
|
||||||
|
ServerConnection
|
||||||
|
ID uuid.UUID
|
||||||
|
Nickname string
|
||||||
Default bool
|
Default bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,13 +177,11 @@ func (c *Config) SetDefaultServer(serverID uuid.UUID) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) AddServer(nickname, hostname, username string, legacyAuth bool) *ServerConfig {
|
func (c *Config) AddServer(nickname string, connection ServerConnection) *ServerConfig {
|
||||||
s := &ServerConfig{
|
s := &ServerConfig{
|
||||||
ID: uuid.New(),
|
ID: uuid.New(),
|
||||||
Nickname: nickname,
|
Nickname: nickname,
|
||||||
Hostname: hostname,
|
ServerConnection: connection,
|
||||||
Username: username,
|
|
||||||
LegacyAuth: legacyAuth,
|
|
||||||
}
|
}
|
||||||
c.Servers = append(c.Servers, s)
|
c.Servers = append(c.Servers, s)
|
||||||
return s
|
return s
|
||||||
|
|||||||
+48
-13
@@ -1,6 +1,7 @@
|
|||||||
package backend
|
package backend
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@@ -26,7 +27,7 @@ func NewServerManager(appName string) *ServerManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServerManager) ConnectToServer(conf *ServerConfig, password string) error {
|
func (s *ServerManager) ConnectToServer(conf *ServerConfig, password string) error {
|
||||||
cli, err := s.testConnectionAndCreateClient(conf.Hostname, conf.Username, password, conf.LegacyAuth)
|
cli, err := s.testConnectionAndCreateClient(conf.ServerConnection, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -39,12 +40,12 @@ func (s *ServerManager) ConnectToServer(conf *ServerConfig, password string) err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServerManager) TestConnectionAndAuth(
|
func (s *ServerManager) TestConnectionAndAuth(
|
||||||
hostname, username, password string, legacyAuth bool, timeout time.Duration,
|
connection ServerConnection, password string, timeout time.Duration,
|
||||||
) error {
|
) error {
|
||||||
err := ErrUnreachable
|
err := ErrUnreachable
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
go func() {
|
go func() {
|
||||||
_, err = s.testConnectionAndCreateClient(hostname, username, password, legacyAuth)
|
_, err = s.testConnectionAndCreateClient(connection, password)
|
||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
t := time.NewTimer(timeout)
|
t := time.NewTimer(timeout)
|
||||||
@@ -57,16 +58,10 @@ func (s *ServerManager) TestConnectionAndAuth(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServerManager) testConnectionAndCreateClient(hostname, username, password string, legacyAuth bool) (*subsonic.Client, error) {
|
func (s *ServerManager) testConnectionAndCreateClient(connection ServerConnection, password string) (*subsonic.Client, error) {
|
||||||
cli := &subsonic.Client{
|
cli, err := s.connect(connection, password)
|
||||||
Client: &http.Client{},
|
if err != nil {
|
||||||
BaseUrl: hostname,
|
return nil, err
|
||||||
User: username,
|
|
||||||
PasswordAuth: legacyAuth,
|
|
||||||
ClientName: "supersonic",
|
|
||||||
}
|
|
||||||
if !cli.Ping() {
|
|
||||||
return nil, ErrUnreachable
|
|
||||||
}
|
}
|
||||||
if err := cli.Authenticate(password); err != nil {
|
if err := cli.Authenticate(password); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -74,6 +69,46 @@ func (s *ServerManager) testConnectionAndCreateClient(hostname, username, passwo
|
|||||||
return cli, nil
|
return cli, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ServerManager) connect(connection ServerConnection, password string) (*subsonic.Client, error) {
|
||||||
|
cli := &subsonic.Client{
|
||||||
|
Client: &http.Client{},
|
||||||
|
BaseUrl: connection.Hostname,
|
||||||
|
User: connection.Username,
|
||||||
|
PasswordAuth: connection.LegacyAuth,
|
||||||
|
ClientName: "supersonic",
|
||||||
|
}
|
||||||
|
altCli := &subsonic.Client{
|
||||||
|
Client: &http.Client{},
|
||||||
|
BaseUrl: connection.AltHostname,
|
||||||
|
User: connection.Username,
|
||||||
|
PasswordAuth: connection.LegacyAuth,
|
||||||
|
ClientName: "supersonic",
|
||||||
|
}
|
||||||
|
pingChan := make(chan bool, 2) // false for primary hostname, true for alternate
|
||||||
|
pingFunc := func(delay time.Duration, cli *subsonic.Client, val bool) {
|
||||||
|
<-time.After(delay)
|
||||||
|
if cli.Ping() {
|
||||||
|
pingChan <- val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
go pingFunc(0, cli, false)
|
||||||
|
if connection.AltHostname != "" {
|
||||||
|
go pingFunc(333*time.Millisecond, altCli, true) // give primary hostname ping a head start
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return nil, ErrUnreachable
|
||||||
|
case altPing := <-pingChan:
|
||||||
|
if altPing {
|
||||||
|
return altCli, nil
|
||||||
|
}
|
||||||
|
return cli, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ServerManager) Logout() {
|
func (s *ServerManager) Logout() {
|
||||||
if s.Server != nil {
|
if s.Server != nil {
|
||||||
keyring.Delete(s.appName, s.ServerID.String())
|
keyring.Delete(s.appName, s.ServerID.String())
|
||||||
|
|||||||
@@ -132,7 +132,13 @@ func (m *Controller) PromptForFirstServer() {
|
|||||||
// connection is good
|
// connection is good
|
||||||
pop.Hide()
|
pop.Hide()
|
||||||
m.doModalClosed()
|
m.doModalClosed()
|
||||||
server := m.App.Config.AddServer(d.Nickname, d.Host, d.Username, d.LegacyAuth)
|
conn := backend.ServerConnection{
|
||||||
|
Hostname: d.Host,
|
||||||
|
AltHostname: d.AltHost,
|
||||||
|
Username: d.Username,
|
||||||
|
LegacyAuth: d.LegacyAuth,
|
||||||
|
}
|
||||||
|
server := m.App.Config.AddServer(d.Nickname, conn)
|
||||||
if err := m.App.ServerManager.SetServerPassword(server, d.Password); err != nil {
|
if err := m.App.ServerManager.SetServerPassword(server, d.Password); err != nil {
|
||||||
log.Printf("error setting keyring credentials: %v", err)
|
log.Printf("error setting keyring credentials: %v", err)
|
||||||
// TODO: handle?
|
// TODO: handle?
|
||||||
@@ -254,7 +260,7 @@ func (m *Controller) PromptForLoginAndConnect() {
|
|||||||
d.DisableSubmit()
|
d.DisableSubmit()
|
||||||
d.SetInfoText("Testing connection...")
|
d.SetInfoText("Testing connection...")
|
||||||
go func() {
|
go func() {
|
||||||
err := m.App.ServerManager.TestConnectionAndAuth(server.Hostname, server.Username, password, server.LegacyAuth, 5*time.Second)
|
err := m.App.ServerManager.TestConnectionAndAuth(server.ServerConnection, password, 5*time.Second)
|
||||||
if err == backend.ErrUnreachable {
|
if err == backend.ErrUnreachable {
|
||||||
d.SetErrorText("Server unreachable")
|
d.SetErrorText("Server unreachable")
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
@@ -278,6 +284,7 @@ func (m *Controller) PromptForLoginAndConnect() {
|
|||||||
// connection is good
|
// connection is good
|
||||||
editPop.Hide()
|
editPop.Hide()
|
||||||
server.Hostname = editD.Host
|
server.Hostname = editD.Host
|
||||||
|
server.AltHostname = editD.AltHost
|
||||||
server.Nickname = editD.Nickname
|
server.Nickname = editD.Nickname
|
||||||
server.Username = editD.Username
|
server.Username = editD.Username
|
||||||
server.LegacyAuth = editD.LegacyAuth
|
server.LegacyAuth = editD.LegacyAuth
|
||||||
@@ -343,7 +350,7 @@ func (c *Controller) trySetPasswordAndConnectToServer(server *backend.ServerConf
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) tryConnectToServer(server *backend.ServerConfig, password string) error {
|
func (c *Controller) tryConnectToServer(server *backend.ServerConfig, password string) error {
|
||||||
if err := c.App.ServerManager.TestConnectionAndAuth(server.Hostname, server.Username, password, server.LegacyAuth, 10*time.Second); err != nil {
|
if err := c.App.ServerManager.TestConnectionAndAuth(server.ServerConnection, password, 10*time.Second); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.App.ServerManager.ConnectToServer(server, password); err != nil {
|
if err := c.App.ServerManager.ConnectToServer(server, password); err != nil {
|
||||||
@@ -355,7 +362,13 @@ func (c *Controller) tryConnectToServer(server *backend.ServerConfig, password s
|
|||||||
|
|
||||||
func (c *Controller) testConnectionAndUpdateDialogText(dlg *dialogs.AddEditServerDialog) bool {
|
func (c *Controller) testConnectionAndUpdateDialogText(dlg *dialogs.AddEditServerDialog) bool {
|
||||||
dlg.SetInfoText("Testing connection...")
|
dlg.SetInfoText("Testing connection...")
|
||||||
err := c.App.ServerManager.TestConnectionAndAuth(dlg.Host, dlg.Username, dlg.Password, dlg.LegacyAuth, 5*time.Second)
|
conn := backend.ServerConnection{
|
||||||
|
Hostname: dlg.Host,
|
||||||
|
AltHostname: dlg.AltHost,
|
||||||
|
Username: dlg.Username,
|
||||||
|
LegacyAuth: dlg.LegacyAuth,
|
||||||
|
}
|
||||||
|
err := c.App.ServerManager.TestConnectionAndAuth(conn, dlg.Password, 5*time.Second)
|
||||||
if err == backend.ErrUnreachable {
|
if err == backend.ErrUnreachable {
|
||||||
dlg.SetErrorText("Could not reach server (wrong hostname?)")
|
dlg.SetErrorText("Could not reach server (wrong hostname?)")
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ type AddEditServerDialog struct {
|
|||||||
|
|
||||||
Nickname string
|
Nickname string
|
||||||
Host string
|
Host string
|
||||||
|
AltHost string
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
LegacyAuth bool
|
LegacyAuth bool
|
||||||
@@ -34,6 +35,7 @@ func NewAddEditServerDialog(title string, prefillServer *backend.ServerConfig) *
|
|||||||
if prefillServer != nil {
|
if prefillServer != nil {
|
||||||
a.Nickname = prefillServer.Nickname
|
a.Nickname = prefillServer.Nickname
|
||||||
a.Host = prefillServer.Hostname
|
a.Host = prefillServer.Hostname
|
||||||
|
a.AltHost = prefillServer.AltHostname
|
||||||
a.Username = prefillServer.Username
|
a.Username = prefillServer.Username
|
||||||
a.LegacyAuth = prefillServer.LegacyAuth
|
a.LegacyAuth = prefillServer.LegacyAuth
|
||||||
}
|
}
|
||||||
@@ -44,6 +46,8 @@ func NewAddEditServerDialog(title string, prefillServer *backend.ServerConfig) *
|
|||||||
nickField.SetPlaceHolder("My Server")
|
nickField.SetPlaceHolder("My Server")
|
||||||
hostField := widget.NewEntryWithData(binding.BindString(&a.Host))
|
hostField := widget.NewEntryWithData(binding.BindString(&a.Host))
|
||||||
hostField.SetPlaceHolder("http://localhost:4533")
|
hostField.SetPlaceHolder("http://localhost:4533")
|
||||||
|
altHostField := widget.NewEntryWithData(binding.BindString(&a.AltHost))
|
||||||
|
altHostField.SetPlaceHolder("(optional) https://my-external-domain.net/music")
|
||||||
userField := widget.NewEntryWithData(binding.BindString(&a.Username))
|
userField := widget.NewEntryWithData(binding.BindString(&a.Username))
|
||||||
passField := widget.NewPasswordEntry()
|
passField := widget.NewPasswordEntry()
|
||||||
a.submitBtn = widget.NewButton("Enter", func() {
|
a.submitBtn = widget.NewButton("Enter", func() {
|
||||||
@@ -64,6 +68,8 @@ func NewAddEditServerDialog(title string, prefillServer *backend.ServerConfig) *
|
|||||||
nickField,
|
nickField,
|
||||||
widget.NewLabel("Hostname"),
|
widget.NewLabel("Hostname"),
|
||||||
hostField,
|
hostField,
|
||||||
|
widget.NewLabel("Alt. Hostname"),
|
||||||
|
altHostField,
|
||||||
widget.NewLabel("Username"),
|
widget.NewLabel("Username"),
|
||||||
userField,
|
userField,
|
||||||
widget.NewLabel("Password"),
|
widget.NewLabel("Password"),
|
||||||
@@ -111,7 +117,7 @@ func (a *AddEditServerDialog) doSetPromptText(text string, color fyne.ThemeColor
|
|||||||
|
|
||||||
func (a *AddEditServerDialog) MinSize() fyne.Size {
|
func (a *AddEditServerDialog) MinSize() fyne.Size {
|
||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
return fyne.NewSize(450, a.container.MinSize().Height)
|
return fyne.NewSize(475, a.container.MinSize().Height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AddEditServerDialog) CreateRenderer() fyne.WidgetRenderer {
|
func (a *AddEditServerDialog) CreateRenderer() fyne.WidgetRenderer {
|
||||||
|
|||||||
Reference in New Issue
Block a user