Skip to content
This repository was archived by the owner on Feb 10, 2023. It is now read-only.

Commit 14868ad

Browse files
improve live session check
* keep checking for new live sessions * remove sessions that are no longer live closes #147
1 parent fc9e3e9 commit 14868ad

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

internal/ui/live.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ func (s *UIState) checkLive() {
1313
return
1414
}
1515
case isLive:
16-
s.changes <- liveNode
17-
return
16+
s.addLiveNode(liveNode)
17+
s.logger.Info("found live event")
1818
case s.cfg.LiveRetryTimeout <= 0:
1919
s.logger.Info("no live session found")
2020
return
2121
default:
22+
s.addLiveNode(nil) // remove live node
2223
s.logger.Info("no live session found")
2324
}
2425
time.Sleep(time.Second * time.Duration(s.cfg.LiveRetryTimeout))

internal/ui/state.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ type UIState struct {
5757
textWindow *tview.TextView
5858
treeView *tview.TreeView
5959

60+
LiveNode *tview.TreeNode
61+
6062
logger util.Logger
6163

6264
// TODO: replace activeTheme
6365
// theme config.Theme
6466

65-
changes chan *tview.TreeNode
66-
6767
v2 *f1tv.F1TV
6868

6969
cmd *cmd.Store
@@ -73,7 +73,6 @@ func NewUI(cfg config.Config, version string) *UIState {
7373
ui := UIState{
7474
version: version,
7575
cfg: cfg,
76-
changes: make(chan *tview.TreeNode),
7776
v2: f1tv.NewF1TV(version),
7877
}
7978
ui.applyTheme(cfg.Theme)
@@ -158,7 +157,6 @@ func (ui *UIState) Run() error {
158157
done <- ui.app.Run()
159158
}()
160159

161-
go ui.handleEvents()
162160
go ui.checkLive()
163161
go ui.loadUpdate()
164162

@@ -307,11 +305,17 @@ func (s *UIState) blinkNode(node *tview.TreeNode, done chan struct{}) {
307305
}
308306
}
309307

310-
func (ui *UIState) handleEvents() {
311-
for node := range ui.changes {
312-
insertNodeAtTop(ui.treeView.GetRoot(), node)
313-
ui.app.Draw()
308+
func (ui *UIState) addLiveNode(newNode *tview.TreeNode) {
309+
if ui.LiveNode != nil {
310+
ui.treeView.GetRoot().RemoveChild(ui.LiveNode)
311+
}
312+
313+
// newNode if nil if the previous session is no longer live and there is no new live session
314+
if newNode != nil {
315+
ui.LiveNode = newNode
316+
insertNodeAtTop(ui.treeView.GetRoot(), newNode)
314317
}
318+
ui.app.Draw()
315319
}
316320

317321
func (ui *UIState) loadUpdate() {
@@ -341,5 +345,5 @@ func (ui *UIState) loadUpdate() {
341345
})
342346

343347
appendNodes(updateNode, getUpdateNode)
344-
ui.changes <- updateNode
348+
insertNodeAtTop(ui.treeView.GetRoot(), updateNode)
345349
}

0 commit comments

Comments
 (0)