mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-24 15:48:52 +01:00
Make systray connected/disconnected icon switch faster (#299)
This commit is contained in:
parent
17fbbbea2a
commit
70ffc9d625
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -32,8 +33,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
defaulFailTimeout = time.Duration(3 * time.Second)
|
||||
fastFailTimeout = time.Second
|
||||
defaultFailTimeout = 3 * time.Second
|
||||
failFastTimeout = time.Second
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -188,7 +189,7 @@ func (s *serviceClient) getSettingsForm() *widget.Form {
|
||||
s.preSharedKey = s.iPreSharedKey.Text
|
||||
s.adminURL = s.iAdminURL.Text
|
||||
|
||||
client, err := s.getSrvClient(fastFailTimeout)
|
||||
client, err := s.getSrvClient(failFastTimeout)
|
||||
if err != nil {
|
||||
log.Errorf("get daemon client: %v", err)
|
||||
return
|
||||
@ -219,7 +220,7 @@ func (s *serviceClient) getSettingsForm() *widget.Form {
|
||||
}
|
||||
|
||||
func (s *serviceClient) menuUpClick() error {
|
||||
conn, err := s.getSrvClient(defaulFailTimeout)
|
||||
conn, err := s.getSrvClient(defaultFailTimeout)
|
||||
if err != nil {
|
||||
log.Errorf("get client: %v", err)
|
||||
return err
|
||||
@ -245,7 +246,7 @@ func (s *serviceClient) menuUpClick() error {
|
||||
}
|
||||
|
||||
func (s *serviceClient) menuDownClick() error {
|
||||
conn, err := s.getSrvClient(defaulFailTimeout)
|
||||
conn, err := s.getSrvClient(defaultFailTimeout)
|
||||
if err != nil {
|
||||
log.Errorf("get client: %v", err)
|
||||
return err
|
||||
@ -270,17 +271,16 @@ func (s *serviceClient) menuDownClick() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *serviceClient) updateStatus() {
|
||||
conn, err := s.getSrvClient(defaulFailTimeout)
|
||||
func (s *serviceClient) updateStatus() error {
|
||||
conn, err := s.getSrvClient(defaultFailTimeout)
|
||||
if err != nil {
|
||||
log.Errorf("get client: %v", err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
err = backoff.Retry(func() error {
|
||||
status, err := conn.Status(s.ctx, &proto.StatusRequest{})
|
||||
if err != nil {
|
||||
log.Errorf("get service status: %v", err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
if status.Status == string(internal.StatusConnected) {
|
||||
@ -294,6 +294,22 @@ func (s *serviceClient) updateStatus() {
|
||||
s.mDown.Disable()
|
||||
s.mUp.Enable()
|
||||
}
|
||||
return nil
|
||||
}, &backoff.ExponentialBackOff{
|
||||
InitialInterval: time.Second,
|
||||
RandomizationFactor: backoff.DefaultRandomizationFactor,
|
||||
Multiplier: backoff.DefaultMultiplier,
|
||||
MaxInterval: 300 * time.Millisecond,
|
||||
MaxElapsedTime: 2 * time.Second,
|
||||
Stop: backoff.Stop,
|
||||
Clock: backoff.SystemClock,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *serviceClient) onTrayReady() {
|
||||
@ -315,8 +331,11 @@ func (s *serviceClient) onTrayReady() {
|
||||
go func() {
|
||||
s.getSrvConfig()
|
||||
for {
|
||||
s.updateStatus()
|
||||
time.Sleep(time.Second * 3)
|
||||
err := s.updateStatus()
|
||||
if err != nil {
|
||||
log.Errorf("error while updating status: %v", err)
|
||||
}
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
||||
}()
|
||||
|
||||
@ -400,7 +419,7 @@ func (s *serviceClient) getSrvConfig() {
|
||||
s.managementURL = "https://api.wiretrustee.com:33073"
|
||||
s.adminURL = "https://app.netbird.io"
|
||||
|
||||
conn, err := s.getSrvClient(fastFailTimeout)
|
||||
conn, err := s.getSrvClient(failFastTimeout)
|
||||
if err != nil {
|
||||
log.Errorf("get client: %v", err)
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user