Skip to content

Commit

Permalink
wait until active window for first heart beat
Browse files Browse the repository at this point in the history
  • Loading branch information
gferraro committed Nov 23, 2021
1 parent d9afb1b commit 0afe649
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
16 changes: 10 additions & 6 deletions heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@ type Heartbeat struct {
}

func heartBeatLoop(window *window.Window) {
if !window.Active() {
log.Printf("After active window not sending heart beat")
return
}

hb, err := NewHeartbeat(window)
if err != nil {
log.Printf("Error starting up heart beat %v", err)
return
}
log.Printf("Sending initial heart beat in %v", heartBeatDelay)
time.Sleep(heartBeatDelay)
initialDelay := heartBeatDelay

if !window.Active() {
until := window.Until()
if until > initialDelay {
initialDelay = until
}
}
log.Printf("Sending initial heart beat in %v", initialDelay)
time.Sleep(initialDelay)

for {
attempt := 0
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ func runMain() error {
log.Println("started D-Bus service")

go heartBeatLoop(conf.OnWindow)

go updateWatchdogTimer(attiny)
if err := attiny.UpdateWifiState(); err != nil {
log.Println("failed to update wifi state:", err)
Expand All @@ -155,7 +154,7 @@ func runMain() error {
log.Printf("on window: %s", conf.OnWindow)

if conf.OnWindow.NoWindow {
log.Printf("no window active so pinging watchdog only")
log.Printf("no window so pinging watchdog only")
runtime.Goexit()
}

Expand Down

0 comments on commit 0afe649

Please sign in to comment.