Skip to content

Commit

Permalink
fix(agent/ui): remove broken HA version display
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuar committed Oct 12, 2023
1 parent 5a1a99b commit 4705a35
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 30 deletions.
6 changes: 2 additions & 4 deletions internal/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func Run(options AgentOptions) {

agent.handleSignals()
agent.handleShutdown()
agent.ui.DisplayTrayIcon(ctx, agent)
agent.ui.DisplayTrayIcon(agent)
agent.ui.Run()
defer cancelFunc()

Expand All @@ -135,8 +135,6 @@ func Run(options AgentOptions) {
// request to Home Assistant and handles the response. It will handle either a
// UI or non-UI registration flow.
func Register(options AgentOptions, server, token string) {
var ctx context.Context

agent := newAgent(&options)
defer close(agent.done)

Expand All @@ -149,7 +147,7 @@ func Register(options AgentOptions, server, token string) {

agent.handleSignals()
agent.handleShutdown()
agent.ui.DisplayTrayIcon(ctx, agent)
agent.ui.DisplayTrayIcon(agent)
agent.ui.Run()

regWait.Wait()
Expand Down
16 changes: 5 additions & 11 deletions internal/agent/ui/fyneUI/fyneUI.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func NewFyneUI(agent ui.Agent) *fyneUI {

// DisplayTrayIcon displays an icon in the desktop tray with a menu for
// controlling the agent and showing other informational windows.
func (i *fyneUI) DisplayTrayIcon(ctx context.Context, agent ui.Agent) {
func (i *fyneUI) DisplayTrayIcon(agent ui.Agent) {
if agent.IsHeadless() {
log.Warn().Msg("No UI. Will not display tray icon.")
return
Expand All @@ -103,7 +103,7 @@ func (i *fyneUI) DisplayTrayIcon(ctx context.Context, agent ui.Agent) {
menu := fyne.NewMenu("Main",
fyne.NewMenuItem(i.text.Translate("About"),
func() {
w := i.aboutWindow(ctx, agent, i.text)
w := i.aboutWindow(agent, i.text)
if w != nil {
w.Show()
}
Expand Down Expand Up @@ -171,16 +171,10 @@ func (i *fyneUI) DisplayRegistrationWindow(ctx context.Context, agent ui.Agent,

// aboutWindow creates a window that will show some interesting information
// about the agent, such as version numbers.
func (i *fyneUI) aboutWindow(ctx context.Context, agent ui.Agent, t *translations.Translator) fyne.Window {
func (i *fyneUI) aboutWindow(agent ui.Agent, t *translations.Translator) fyne.Window {
var widgets []fyne.CanvasObject
if hassConfig, err := hass.GetHassConfig(ctx); err != nil {
widgets = append(widgets, widget.NewLabel(t.Translate(
"App Version: %s", agent.AppVersion())))
} else {
haVersion := hassConfig.GetVersion()
widgets = append(widgets, widget.NewLabel(t.Translate(
"App Version: %s\tHA Version: %s", agent.AppVersion(), haVersion)))
}
widgets = append(widgets, widget.NewLabel(t.Translate(
"App Version: %s", agent.AppVersion())))
var deviceName, deviceID string
if err := agent.GetConfig(config.PrefDeviceName, &deviceName); err == nil && deviceName != "" {
widgets = append(widgets,
Expand Down
22 changes: 8 additions & 14 deletions internal/agent/ui/mockAgentUI_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/agent/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Agent interface {
//go:generate moq -out mockAgentUI_test.go . AgentUI
type AgentUI interface {
DisplayNotification(string, string)
DisplayTrayIcon(context.Context, Agent)
DisplayTrayIcon(Agent)
DisplayRegistrationWindow(context.Context, Agent, chan struct{})
Run()
}
Expand Down

0 comments on commit 4705a35

Please sign in to comment.