From b91e1be8dfd9eb4bd15ba422a937efb267aa4438 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Tue, 3 Apr 2018 18:03:34 -0700 Subject: [PATCH] refreshInterval config added to BambooHR and Status --- bamboohr/widget.go | 14 +++++++++++--- config.yml | 4 ++++ status/widget.go | 13 +++++++++++-- wtf.go | 7 +++---- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/bamboohr/widget.go b/bamboohr/widget.go index d9b8f7f6..c28d0f58 100644 --- a/bamboohr/widget.go +++ b/bamboohr/widget.go @@ -5,21 +5,29 @@ import ( "time" "github.com/gdamore/tcell" + "github.com/olebedev/config" "github.com/rivo/tview" "github.com/senorprogrammer/wtf/wtf" ) type Widget struct { wtf.BaseWidget - View *tview.TextView + + Config *config.Config + View *tview.TextView } -func NewWidget() *Widget { +func NewWidget(config *config.Config) *Widget { + refreshInterval, err := config.Int("wtf.bamboohr.refreshInterval") + if err != nil { + refreshInterval = 1 + } + widget := Widget{ BaseWidget: wtf.BaseWidget{ Name: "BambooHR", RefreshedAt: time.Now(), - RefreshInt: 15, + RefreshInt: refreshInterval, }, } diff --git a/config.yml b/config.yml index e6688a19..92530864 100644 --- a/config.yml +++ b/config.yml @@ -1,2 +1,6 @@ wtf: refreshInterval: 1 + bamboohr: + refreshInterval: 900 + status: + refreshInterval: 1 diff --git a/status/widget.go b/status/widget.go index 7b99d909..439655be 100644 --- a/status/widget.go +++ b/status/widget.go @@ -5,23 +5,32 @@ import ( "time" "github.com/gdamore/tcell" + "github.com/olebedev/config" "github.com/rivo/tview" "github.com/senorprogrammer/wtf/wtf" ) type Widget struct { wtf.BaseWidget + + Config *config.Config Current int View *tview.TextView } -func NewWidget() *Widget { +func NewWidget(config *config.Config) *Widget { + refreshInterval, err := config.Int("wtf.status.refreshInterval") + if err != nil { + refreshInterval = 1 + } + widget := Widget{ BaseWidget: wtf.BaseWidget{ Name: "Status", RefreshedAt: time.Now(), - RefreshInt: 1, + RefreshInt: refreshInterval, }, + Config: config, Current: 0, } diff --git a/wtf.go b/wtf.go index d259e7d3..9b16846c 100644 --- a/wtf.go +++ b/wtf.go @@ -1,7 +1,6 @@ package main import ( - //"fmt" "time" "github.com/olebedev/config" @@ -28,7 +27,7 @@ func loadConfig() *config.Config { } func refresher(stat *status.Widget, app *tview.Application) { - refreshInterval, err := Config.Int("wtf.refresh_interval") + refreshInterval, err := Config.Int("wtf.refreshInterval") if err != nil { refreshInterval = 1 } @@ -48,7 +47,7 @@ func refresher(stat *status.Widget, app *tview.Application) { } func main() { - bamboo := bamboohr.NewWidget() + bamboo := bamboohr.NewWidget(Config) bamboo.Refresh() cal := gcal.NewWidget() @@ -66,7 +65,7 @@ func main() { sec := security.NewWidget() sec.Refresh() - stat := status.NewWidget() + stat := status.NewWidget(Config) stat.Refresh() weather := weather.NewWidget()