Fix #696: Save and use last selected library when re-connecting to server
This commit is contained in:
+4
-3
@@ -25,9 +25,10 @@ type ServerConnection struct {
|
|||||||
|
|
||||||
type ServerConfig struct {
|
type ServerConfig struct {
|
||||||
ServerConnection
|
ServerConnection
|
||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
Nickname string
|
Nickname string
|
||||||
Default bool
|
Default bool
|
||||||
|
SelectedLibrary string
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppConfig struct {
|
type AppConfig struct {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ type ServerManager struct {
|
|||||||
appName string
|
appName string
|
||||||
appVersion string
|
appVersion string
|
||||||
config *Config
|
config *Config
|
||||||
onServerConnected []func()
|
onServerConnected []func(*ServerConfig)
|
||||||
onLogout []func()
|
onLogout []func()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ func (s *ServerManager) ConnectToServer(conf *ServerConfig, password string) err
|
|||||||
s.ServerID = conf.ID
|
s.ServerID = conf.ID
|
||||||
s.SetDefaultServer(s.ServerID)
|
s.SetDefaultServer(s.ServerID)
|
||||||
for _, cb := range s.onServerConnected {
|
for _, cb := range s.onServerConnected {
|
||||||
cb()
|
cb(conf)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -152,7 +152,7 @@ func (s *ServerManager) deleteServerPassword(serverID uuid.UUID) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sets a callback that is invoked when a server is connected to.
|
// Sets a callback that is invoked when a server is connected to.
|
||||||
func (s *ServerManager) OnServerConnected(cb func()) {
|
func (s *ServerManager) OnServerConnected(cb func(*ServerConfig)) {
|
||||||
s.onServerConnected = append(s.onServerConnected, cb)
|
s.onServerConnected = append(s.onServerConnected, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
-4
@@ -94,8 +94,8 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string,
|
|||||||
app.PlaybackManager.OnSongChange(func(item mediaprovider.MediaItem, _ *mediaprovider.Track) {
|
app.PlaybackManager.OnSongChange(func(item mediaprovider.MediaItem, _ *mediaprovider.Track) {
|
||||||
fyne.Do(func() { m.UpdateOnTrackChange(item) })
|
fyne.Do(func() { m.UpdateOnTrackChange(item) })
|
||||||
})
|
})
|
||||||
app.ServerManager.OnServerConnected(func() {
|
app.ServerManager.OnServerConnected(func(conf *backend.ServerConfig) {
|
||||||
go m.RunOnServerConnectedTasks(app, displayAppName)
|
go m.RunOnServerConnectedTasks(conf, app, displayAppName)
|
||||||
})
|
})
|
||||||
app.ServerManager.OnLogout(func() {
|
app.ServerManager.OnLogout(func() {
|
||||||
m.BrowsingPane.DisableNavigationButtons()
|
m.BrowsingPane.DisableNavigationButtons()
|
||||||
@@ -225,7 +225,7 @@ func (m *MainWindow) StartupPage() controller.Route {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MainWindow) RunOnServerConnectedTasks(app *backend.App, displayAppName string) {
|
func (m *MainWindow) RunOnServerConnectedTasks(serverConf *backend.ServerConfig, app *backend.App, displayAppName string) {
|
||||||
time.Sleep(1 * time.Millisecond) // ensure this runs after sync tasks
|
time.Sleep(1 * time.Millisecond) // ensure this runs after sync tasks
|
||||||
|
|
||||||
if app.Config.Application.SavePlayQueue {
|
if app.Config.Application.SavePlayQueue {
|
||||||
@@ -237,6 +237,7 @@ func (m *MainWindow) RunOnServerConnectedTasks(app *backend.App, displayAppName
|
|||||||
}
|
}
|
||||||
|
|
||||||
doSetLibrary := func(libraryID string, menuIdx int) {
|
doSetLibrary := func(libraryID string, menuIdx int) {
|
||||||
|
serverConf.SelectedLibrary = libraryID
|
||||||
fyne.Do(func() {
|
fyne.Do(func() {
|
||||||
m.App.ServerManager.Server.SetLibrary(libraryID)
|
m.App.ServerManager.Server.SetLibrary(libraryID)
|
||||||
// Pages in the history could contain content
|
// Pages in the history could contain content
|
||||||
@@ -267,6 +268,9 @@ func (m *MainWindow) RunOnServerConnectedTasks(app *backend.App, displayAppName
|
|||||||
}))
|
}))
|
||||||
libraryMenuItemOffset = 1
|
libraryMenuItemOffset = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initialLibraryMenuIdx := 0
|
||||||
|
initialLibraryID := ""
|
||||||
for i, l := range libraries {
|
for i, l := range libraries {
|
||||||
_l := l
|
_l := l
|
||||||
_i := i + libraryMenuItemOffset
|
_i := i + libraryMenuItemOffset
|
||||||
@@ -274,11 +278,19 @@ func (m *MainWindow) RunOnServerConnectedTasks(app *backend.App, displayAppName
|
|||||||
fyne.NewMenuItem(_l.Name, func() {
|
fyne.NewMenuItem(_l.Name, func() {
|
||||||
doSetLibrary(_l.ID, _i)
|
doSetLibrary(_l.ID, _i)
|
||||||
}))
|
}))
|
||||||
|
if _l.ID == serverConf.SelectedLibrary {
|
||||||
|
initialLibraryMenuIdx = _i
|
||||||
|
initialLibraryID = _l.ID
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m.librarySubmenu = libraryMenu
|
m.librarySubmenu = libraryMenu
|
||||||
m.librarySubmenu.Items[0].Checked = true
|
m.librarySubmenu.Items[initialLibraryMenuIdx].Checked = true
|
||||||
m.BrowsingPane.SetSubmenuForMenuItem(lang.L("Select Library"), libraryMenu)
|
m.BrowsingPane.SetSubmenuForMenuItem(lang.L("Select Library"), libraryMenu)
|
||||||
|
|
||||||
|
if initialLibraryID != "" {
|
||||||
|
m.App.ServerManager.Server.SetLibrary(initialLibraryID)
|
||||||
|
}
|
||||||
|
|
||||||
fyne.Do(func() {
|
fyne.Do(func() {
|
||||||
m.BrowsingPane.EnableNavigationButtons()
|
m.BrowsingPane.EnableNavigationButtons()
|
||||||
m.Router.NavigateTo(m.StartupPage())
|
m.Router.NavigateTo(m.StartupPage())
|
||||||
|
|||||||
Reference in New Issue
Block a user