1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Remove the common refresher() code into BaseWidget

This commit is contained in:
Chris Cummer
2018-04-02 04:38:55 -07:00
committed by Chris Cummer
parent 35e7fa0128
commit 278bf583c4
8 changed files with 32 additions and 152 deletions

View File

@@ -18,14 +18,14 @@ type Widget struct {
func NewWidget() *Widget {
widget := Widget{
BaseWidget: wtf.BaseWidget{
Name: "Calendar",
RefreshedAt: time.Now(),
RefreshInterval: 3,
Name: "Calendar",
RefreshedAt: time.Now(),
RefreshInt: 180,
},
}
widget.addView()
go widget.refresher()
go wtf.Refresh(&widget)
return &widget
}
@@ -95,21 +95,6 @@ func descriptionColor(item *calendar.Event) string {
return color
}
func (widget *Widget) refresher() {
tick := time.NewTicker(time.Duration(widget.RefreshInterval) * time.Minute)
quit := make(chan struct{})
for {
select {
case <-tick.C:
widget.Refresh()
case <-quit:
tick.Stop()
return
}
}
}
// until returns the number of hours or days until the event
// If the event is in the past, returns nil
func (widget *Widget) until(start time.Time) string {