diff --git a/cmd/windows_agent/systray.go b/cmd/windows_agent/systray.go index 1c18e69..4fb995f 100644 --- a/cmd/windows_agent/systray.go +++ b/cmd/windows_agent/systray.go @@ -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()