Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 52 additions & 30 deletions client/ui/client_ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@

client.setupSignalHandler(client.ctx)

client.setDefaultFonts()

Check failure on line 125 in client/ui/client_ui.go

View workflow job for this annotation

GitHub Actions / JS / Lint

client.setDefaultFonts undefined (type *serviceClient has no field or method setDefaultFonts) (typecheck)
systray.Run(client.onTrayReady, client.onTrayExit)
}

Expand Down Expand Up @@ -318,7 +318,8 @@
logFile string
wLoginURL fyne.Window

connectCancel context.CancelFunc
connectCancel context.CancelFunc
updateStatusChan chan struct{}
}

type menuHandler struct {
Expand Down Expand Up @@ -354,6 +355,7 @@
showAdvancedSettings: args.showSettings,
showNetworks: args.showNetworks,
update: version.NewUpdate("nb/client-ui"),
updateStatusChan: make(chan struct{}, 1),
}

s.eventHandler = newEventHandler(s)
Expand Down Expand Up @@ -892,20 +894,7 @@

switch {
case status.Status == string(internal.StatusConnected):
s.connected = true
s.sendNotification = true
if s.isUpdateIconActive {
systray.SetTemplateIcon(iconUpdateConnectedMacOS, s.icUpdateConnected)
} else {
systray.SetTemplateIcon(iconConnectedMacOS, s.icConnected)
}
systray.SetTooltip("NetBird (Connected)")
s.mStatus.SetTitle("Connected")
s.mStatus.SetIcon(s.icConnectedDot)
s.mUp.Disable()
s.mDown.Enable()
s.mNetworks.Enable()
go s.updateExitNodes()
s.setConnectedStatus()
systrayIconState = true
case status.Status == string(internal.StatusConnecting):
s.setConnectingStatus()
Expand Down Expand Up @@ -969,6 +958,23 @@
go s.updateExitNodes()
}

func (s *serviceClient) setConnectedStatus() {
s.connected = true
s.sendNotification = true
if s.isUpdateIconActive {
systray.SetTemplateIcon(iconUpdateConnectedMacOS, s.icUpdateConnected)
} else {
systray.SetTemplateIcon(iconConnectedMacOS, s.icConnected)
}
systray.SetTooltip("NetBird (Connected)")
s.mStatus.SetTitle("Connected")
s.mStatus.SetIcon(s.icConnectedDot)
s.mUp.Disable()
s.mDown.Enable()
s.mNetworks.Enable()
go s.updateExitNodes()
}

func (s *serviceClient) setConnectingStatus() {
s.connected = false
systray.SetTemplateIcon(iconConnectingMacOS, s.icConnecting)
Expand All @@ -980,6 +986,36 @@
s.mExitNode.Disable()
}

func (s *serviceClient) statusUpdateLoop() {
s.getSrvConfig()
time.Sleep(100 * time.Millisecond)
ticker := time.NewTicker(2 * time.Second)
defer ticker.Stop()

for {
select {
case <-s.ctx.Done():
return
case <-s.updateStatusChan:
case <-ticker.C:
}

err := s.updateStatus()
if err != nil {
log.Errorf("error while updating status: %v", err)
}

s.checkAndUpdateFeatures()
}
}

func (s *serviceClient) triggerStatusUpdate() {
select {
case s.updateStatusChan <- struct{}{}:
default:
}
}

func (s *serviceClient) onTrayReady() {
systray.SetTemplateIcon(iconDisconnectedMacOS, s.icDisconnected)
systray.SetTooltip("NetBird")
Expand Down Expand Up @@ -1072,21 +1108,7 @@
go s.updateExitNodes()

s.update.SetOnUpdateListener(s.onUpdateAvailable)
go func() {
s.getSrvConfig()
time.Sleep(100 * time.Millisecond) // To prevent race condition caused by systray not being fully initialized and ignoring setIcon
for {
err := s.updateStatus()
if err != nil {
log.Errorf("error while updating status: %v", err)
}

// Check features periodically to handle daemon restarts
s.checkAndUpdateFeatures()

time.Sleep(2 * time.Second)
}
}()
go s.statusUpdateLoop()

s.eventManager = event.NewManager(s.app, s.addr)
s.eventManager.SetNotificationsEnabled(s.mNotifications.Checked())
Expand Down
8 changes: 2 additions & 6 deletions client/ui/event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@
}
}

if err := h.client.updateStatus(); err != nil {
log.Debugf("failed to update status after connect: %v", err)
}
h.client.triggerStatusUpdate()
}()
}

Expand All @@ -116,9 +114,7 @@
}
}

if err := h.client.updateStatus(); err != nil {
log.Debugf("failed to update status after disconnect: %v", err)
}
h.client.triggerStatusUpdate()
}()
}

Expand Down Expand Up @@ -208,7 +204,7 @@
}

func (h *eventHandler) handleUpdateClick() {
if err := openURL(version.DownloadUrl()); err != nil {

Check failure on line 207 in client/ui/event_handler.go

View workflow job for this annotation

GitHub Actions / JS / Lint

undefined: version.DownloadUrl (typecheck)
log.Errorf("failed to open download URL: %v", err)
}
}
Expand Down
Loading