add Logout, OnLogout to server manager and hook up OnLogout callbacks
This commit is contained in:
@@ -13,6 +13,7 @@ type ServerManager struct {
|
||||
Server *subsonic.Client
|
||||
|
||||
onServerConnected []func()
|
||||
onLogout []func()
|
||||
}
|
||||
|
||||
func NewServerManager() *ServerManager {
|
||||
@@ -37,10 +38,25 @@ func (s *ServerManager) ConnectToServer(conf *ServerConfig, password string) err
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *ServerManager) Logout() {
|
||||
if s.Server != nil {
|
||||
keyring.Delete(AppName, s.ServerID.String())
|
||||
for _, cb := range s.onLogout {
|
||||
cb()
|
||||
}
|
||||
s.Server = nil
|
||||
s.ServerID = uuid.UUID{}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ServerManager) OnServerConnected(cb func()) {
|
||||
s.onServerConnected = append(s.onServerConnected, cb)
|
||||
}
|
||||
|
||||
func (s *ServerManager) OnLogout(cb func()) {
|
||||
s.onLogout = append(s.onLogout, cb)
|
||||
}
|
||||
|
||||
func (s *ServerManager) GetServerPassword(server *ServerConfig) (string, error) {
|
||||
return keyring.Get(AppName, server.ID.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user