Skip to content

Commit

Permalink
fix(agent): broken registration flow after recent changes
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuar committed Sep 26, 2023
1 parent c47829b commit c227220
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
37 changes: 23 additions & 14 deletions internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ const (
// This includes the data structure for the UI elements and tray and some
// strings such as app name and version.
type Agent struct {
ui AgentUI
config AgentConfig
sensors *tracker.SensorTracker
done chan struct{}
name string
id string
version string
ui AgentUI
config AgentConfig
sensors *tracker.SensorTracker
done chan struct{}
name string
id string
version string
headless bool
}

//go:generate moq -out mock_AgentUI_test.go . AgentUI
Expand All @@ -64,9 +65,10 @@ type AgentOptions struct {

func newAgent(appID string, headless bool) *Agent {
a := &Agent{
id: appID,
version: version,
done: make(chan struct{}),
id: appID,
version: version,
done: make(chan struct{}),
headless: headless,
}
a.ui = ui.NewFyneUI(a, headless)
a.config = config.NewFyneConfig()
Expand Down Expand Up @@ -109,6 +111,7 @@ func Run(options AgentOptions) {

workerWg.Add(1)
go func() {
defer workerWg.Done()
device.StartWorkers(ctx, agent.sensors, sensorWorkers...)
}()
workerWg.Add(1)
Expand All @@ -118,13 +121,15 @@ func Run(options AgentOptions) {
}()
}()

<-configDone
agent.handleSignals(cancelFunc)
agent.handleShutdown(ctx)
go func() {
<-configDone
agent.handleSignals(cancelFunc)
agent.handleShutdown(ctx)
agent.ui.DisplayTrayIcon(ctx, agent)
}()

// If we are not running in headless mode, show a tray icon
if !options.Headless {
agent.ui.DisplayTrayIcon(ctx, agent)
agent.ui.Run()
}
workerWg.Wait()
Expand Down Expand Up @@ -241,6 +246,10 @@ func (agent *Agent) handleShutdown(ctx context.Context) {

// Agent satisfies ui.Agent, tracker.Agent and api.Agent interfaces

func (agent *Agent) IsHeadless() bool {
return agent.headless
}

func (agent *Agent) AppName() string {
return agent.name
}
Expand Down
3 changes: 3 additions & 0 deletions internal/agent/ui/fyneUI.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ func NewFyneUI(agent Agent, headless bool) *fyneUI {
// DisplayTrayIcon displays an icon in the desktop tray with a menu for
// controlling the agent and showing other informational windows.
func (ui *fyneUI) DisplayTrayIcon(ctx context.Context, agent Agent) {
if agent.IsHeadless() {
return
}
if desk, ok := ui.app.(desktop.App); ok {
menuItemQuit := fyne.NewMenuItem(ui.text.Translate("Quit"), func() {
agent.Stop()
Expand Down
1 change: 1 addition & 0 deletions internal/agent/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

//go:generate moq -out mock_Agent_test.go . Agent
type Agent interface {
IsHeadless() bool
AppVersion() string
AppName() string
AppID() string
Expand Down

0 comments on commit c227220

Please sign in to comment.