mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
* Upgrade godo to latest * Fix a bunch of issues found by * Running staticcheck on a codebase for the first time is a sobering experience * go mod tidy * More static improvements Signed-off-by: Chris Cummer <chriscummer@me.com>
39 lines
594 B
Go
39 lines
594 B
Go
package app
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/wtfutil/wtf/wtf"
|
|
)
|
|
|
|
// Schedule kicks off the first refresh of a module's data and then queues the rest of the
|
|
// data refreshes on a timer
|
|
func Schedule(widget wtf.Wtfable) {
|
|
widget.Refresh()
|
|
|
|
interval := time.Duration(widget.RefreshInterval()) * time.Second
|
|
|
|
if interval <= 0 {
|
|
return
|
|
}
|
|
|
|
timer := time.NewTicker(interval)
|
|
|
|
for {
|
|
select {
|
|
case <-timer.C:
|
|
if widget.Enabled() {
|
|
widget.Refresh()
|
|
} else {
|
|
timer.Stop()
|
|
return
|
|
}
|
|
case quit := <-widget.QuitChan():
|
|
if quit {
|
|
timer.Stop()
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|