diff --git a/internal/ui/live.go b/internal/ui/live.go index ce4655d..f0b4077 100644 --- a/internal/ui/live.go +++ b/internal/ui/live.go @@ -13,12 +13,13 @@ func (s *UIState) checkLive() { return } case isLive: - s.changes <- liveNode - return + s.addLiveNode(liveNode) + s.logger.Info("found live event") case s.cfg.LiveRetryTimeout <= 0: s.logger.Info("no live session found") return default: + s.addLiveNode(nil) // remove live node s.logger.Info("no live session found") } time.Sleep(time.Second * time.Duration(s.cfg.LiveRetryTimeout)) diff --git a/internal/ui/state.go b/internal/ui/state.go index d767f89..f98c990 100644 --- a/internal/ui/state.go +++ b/internal/ui/state.go @@ -57,13 +57,13 @@ type UIState struct { textWindow *tview.TextView treeView *tview.TreeView + LiveNode *tview.TreeNode + logger util.Logger // TODO: replace activeTheme // theme config.Theme - changes chan *tview.TreeNode - v2 *f1tv.F1TV cmd *cmd.Store @@ -73,7 +73,6 @@ func NewUI(cfg config.Config, version string) *UIState { ui := UIState{ version: version, cfg: cfg, - changes: make(chan *tview.TreeNode), v2: f1tv.NewF1TV(version), } ui.applyTheme(cfg.Theme) @@ -158,7 +157,6 @@ func (ui *UIState) Run() error { done <- ui.app.Run() }() - go ui.handleEvents() go ui.checkLive() go ui.loadUpdate() @@ -307,11 +305,17 @@ func (s *UIState) blinkNode(node *tview.TreeNode, done chan struct{}) { } } -func (ui *UIState) handleEvents() { - for node := range ui.changes { - insertNodeAtTop(ui.treeView.GetRoot(), node) - ui.app.Draw() +func (ui *UIState) addLiveNode(newNode *tview.TreeNode) { + if ui.LiveNode != nil { + ui.treeView.GetRoot().RemoveChild(ui.LiveNode) + } + + // newNode if nil if the previous session is no longer live and there is no new live session + if newNode != nil { + ui.LiveNode = newNode + insertNodeAtTop(ui.treeView.GetRoot(), newNode) } + ui.app.Draw() } func (ui *UIState) loadUpdate() { @@ -341,5 +345,5 @@ func (ui *UIState) loadUpdate() { }) appendNodes(updateNode, getUpdateNode) - ui.changes <- updateNode + insertNodeAtTop(ui.treeView.GetRoot(), updateNode) }