Skip to content

Commit

Permalink
fix systray fast looping
Browse files Browse the repository at this point in the history
  • Loading branch information
Son Roy Almerol committed Nov 11, 2024
1 parent 45abc06 commit bd6205a
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions cmd/windows_agent/systray.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,54 @@ func (p *agentTray) onReady(url string) func() {
serverIP.Disable()

go func(ctx context.Context, serverIP *systray.MenuItem, url *string) {
setIP := func() {
if url != nil && *url != "" {
serverIP.SetTitle(fmt.Sprintf("Server: %s", *url))
} else {
serverIP.SetTitle("Server: N/A")
}
}

setIP()
for {
retryWait := utils.WaitChan(time.Second * 2)
select {
case <-ctx.Done():
return
default:
if url != nil && *url != "" {
serverIP.SetTitle(fmt.Sprintf("Server: %s", *url))
case <-retryWait:
setIP()
}
}
}(p.ctx, serverIP, &url)

status := systray.AddMenuItem("Status: Connecting...", "Connectivity status")
status.Disable()

go func(ctx context.Context, status *systray.MenuItem, url *string) {
setStatus := func() {
if url != nil && *url != "" {
svcStatus, ok := os.LookupEnv("PBS_AGENT_STATUS")
if !ok {
status.SetTitle("Status: Agent service not running")
} else {
serverIP.SetTitle("Server: N/A")
status.SetTitle(fmt.Sprintf("Status: %s", svcStatus))
}
time.Sleep(time.Second)
} else {
status.SetTitle("Status: Server URL needs to be set.")
}
}
}(p.ctx, serverIP, &url)
setStatus()

for {
retryWait := utils.WaitChan(time.Second * 2)
select {
case <-ctx.Done():
return
case <-retryWait:
setStatus()
}
}
}(p.ctx, status, &url)

systray.AddSeparator()

Expand Down

0 comments on commit bd6205a

Please sign in to comment.