add Logout, OnLogout to server manager and hook up OnLogout callbacks

This commit is contained in:
Drew Weymouth
2023-02-12 15:47:15 -08:00
parent c3fcf5955e
commit 198b84b9c1
5 changed files with 76 additions and 0 deletions
+16
View File
@@ -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())
}