Skip to content

Commit

Permalink
Eliminate unnecessary inactivity timer work
Browse files Browse the repository at this point in the history
Termshark has an inactivity timer which fires periodically in its main
select loop. One use is to show the shark-fin easter egg ;-) But this
timer is firing too often - if the system is "inactive", the timer can
be suppressed until it's active again i.e. via user input.
  • Loading branch information
gcla committed May 30, 2022
1 parent ba7c647 commit 17ef1a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions cmd/termshark/termshark.go
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ func cmain() int {

inactiveDuration := 60 * time.Second
inactivityTimer := time.NewTimer(inactiveDuration)
currentlyInactive := false // True if the timer has fired and termshark is in "inactive" state

var progCancelTimer *time.Timer

Expand Down Expand Up @@ -1074,7 +1075,7 @@ Loop:
}
}

if ui.Loader.InterfaceLoader.IsLoading() {
if ui.Loader.InterfaceLoader.IsLoading() && !currentlyInactive {
inactivityChan = inactivityTimer.C
}

Expand Down Expand Up @@ -1118,8 +1119,10 @@ Loop:
checkedPcapCache = true

case <-inactivityChan:
ui.Fin.Activate()
app.Redraw()
if ui.Fin != nil {
ui.Fin.Activate()
}
currentlyInactive = true

case <-finChan:
ui.Fin.Advance()
Expand Down Expand Up @@ -1312,6 +1315,7 @@ Loop:
case ev := <-tcellEvents:
app.HandleTCellEvent(ev, gowid.IgnoreUnhandledInput)
inactivityTimer.Reset(inactiveDuration)
currentlyInactive = false
checkPcapCacheTimer.Reset(checkPcapCacheDuration)

case ev, ok := <-afterRenderEvents:
Expand All @@ -1321,7 +1325,10 @@ Loop:
if !ok {
break Loop
}
app.RunThenRenderEvent(ev)
ev.RunThenRenderEvent(app)
if ui.Running {
app.RedrawTerminal()
}

case <-watcher.ConfigChanged():
// Re-read so changes that can take effect immediately do so
Expand Down
4 changes: 2 additions & 2 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -3887,9 +3887,9 @@ func Build() (*gowid.App, error) {
// For minibuffer
mbView = holder.New(appViewWithKeys)

Fin = rossshark.New(mbView)

if !termshark.ConfBool("main.disable-shark-fin", false) {
Fin = rossshark.New(mbView)

steerableFin := appkeys.NewMouse(
appkeys.New(
Fin,
Expand Down

0 comments on commit 17ef1a1

Please sign in to comment.