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

Commit

Permalink
improve live session check
Browse files Browse the repository at this point in the history
 * keep checking for new live sessions
 * remove sessions that are no longer live

 closes  #147
  • Loading branch information
SoMuchForSubtlety committed Oct 26, 2021
1 parent fc9e3e9 commit 14868ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
5 changes: 3 additions & 2 deletions internal/ui/live.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
22 changes: 13 additions & 9 deletions internal/ui/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -158,7 +157,6 @@ func (ui *UIState) Run() error {
done <- ui.app.Run()
}()

go ui.handleEvents()
go ui.checkLive()
go ui.loadUpdate()

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -341,5 +345,5 @@ func (ui *UIState) loadUpdate() {
})

appendNodes(updateNode, getUpdateNode)
ui.changes <- updateNode
insertNodeAtTop(ui.treeView.GetRoot(), updateNode)
}

0 comments on commit 14868ad

Please sign in to comment.