Unblock menu when login (#340)

* GetClientID method and increase interval on slow_down err

* Reuse existing authentication flow if is not expired

Created a new struct to hold additional info
 about the flow

 If there is a waiting sso running, we cancel its context

* Run the up command on a goroutine

* Use time.Until

* Use proper ctx and consistently use goroutine for up/down
This commit is contained in:
Maycon Santos
2022-05-28 18:37:08 +02:00
committed by GitHub
parent 59a964eed8
commit c86bacb5c3
3 changed files with 73 additions and 22 deletions

View File

@ -261,7 +261,7 @@ func (s *serviceClient) menuUpClick() error {
err = s.login()
if err != nil {
log.Errorf("get service status: %v", err)
log.Errorf("login failed with: %v", err)
return err
}
@ -271,16 +271,15 @@ func (s *serviceClient) menuUpClick() error {
return err
}
if status.Status != string(internal.StatusIdle) {
if status.Status == string(internal.StatusConnected) {
log.Warnf("already connected")
return nil
return err
}
if _, err := s.conn.Up(s.ctx, &proto.UpRequest{}); err != nil {
log.Errorf("up service: %v", err)
return err
}
return nil
}
@ -388,15 +387,19 @@ func (s *serviceClient) onTrayReady() {
case <-s.mAdminPanel.ClickedCh:
err = open.Run(s.adminURL)
case <-s.mUp.ClickedCh:
s.mUp.Disable()
if err = s.menuUpClick(); err != nil {
s.mUp.Enable()
}
go func() {
err := s.menuUpClick()
if err != nil {
return
}
}()
case <-s.mDown.ClickedCh:
s.mDown.Disable()
if err = s.menuDownClick(); err != nil {
s.mDown.Enable()
}
go func() {
err := s.menuDownClick()
if err != nil {
return
}
}()
case <-s.mSettings.ClickedCh:
s.mSettings.Disable()
go func() {