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:
parent
35e7fa0128
commit
278bf583c4
@ -18,12 +18,12 @@ func NewWidget() *Widget {
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "BambooHR",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInterval: 15,
|
||||
RefreshInt: 15,
|
||||
},
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
go widget.refresher()
|
||||
go wtf.Refresh(&widget)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@ -82,18 +82,3 @@ func (widget *Widget) display(item Item) string {
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,12 @@ func NewWidget() *Widget {
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "Calendar",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInterval: 3,
|
||||
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 {
|
||||
|
@ -20,12 +20,12 @@ func NewWidget() *Widget {
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "Git",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInterval: 10,
|
||||
RefreshInt: 10,
|
||||
},
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
go widget.refresher()
|
||||
go wtf.Refresh(&widget)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@ -116,18 +116,3 @@ func (widget *Widget) formatCommits(data []string) string {
|
||||
func (widget *Widget) formatCommit(line string) string {
|
||||
return fmt.Sprintf(" %s\n", strings.Replace(line, "\"", "", -1))
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,12 +18,12 @@ func NewWidget() *Widget {
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "JIRA",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInterval: 8,
|
||||
RefreshInt: 900,
|
||||
},
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
go widget.refresher()
|
||||
go wtf.Refresh(&widget)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@ -49,18 +49,3 @@ func (widget *Widget) addView() {
|
||||
|
||||
widget.View = view
|
||||
}
|
||||
|
||||
func (widget *Widget) refresher() {
|
||||
tick := time.NewTicker(time.Duration(widget.RefreshInterval) * time.Hour)
|
||||
quit := make(chan struct{})
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-tick.C:
|
||||
widget.Refresh()
|
||||
case <-quit:
|
||||
tick.Stop()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,12 +18,12 @@ func NewWidget() *Widget {
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "OpsGenie",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInterval: 8,
|
||||
RefreshInt: 28800,
|
||||
},
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
go widget.refresher()
|
||||
go wtf.Refresh(&widget)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@ -49,18 +49,3 @@ func (widget *Widget) addView() {
|
||||
|
||||
widget.View = view
|
||||
}
|
||||
|
||||
func (widget *Widget) refresher() {
|
||||
tick := time.NewTicker(time.Duration(widget.RefreshInterval) * time.Hour)
|
||||
quit := make(chan struct{})
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-tick.C:
|
||||
widget.Refresh()
|
||||
case <-quit:
|
||||
tick.Stop()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ func NewWidget() *Widget {
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "Security",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInterval: 60,
|
||||
RefreshInt: 3600,
|
||||
},
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
go widget.refresher()
|
||||
go wtf.Refresh(&widget)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@ -70,18 +70,3 @@ func (widget *Widget) contentFrom(data map[string]string) string {
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ func NewWidget() *Widget {
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "Status",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInterval: 1,
|
||||
RefreshInt: 1,
|
||||
},
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
go widget.refresher()
|
||||
go wtf.Refresh(&widget)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@ -54,18 +54,3 @@ func (widget *Widget) addView() {
|
||||
func (widget *Widget) contentFrom() string {
|
||||
return fmt.Sprint(rand.Intn(100))
|
||||
}
|
||||
|
||||
func (widget *Widget) refresher() {
|
||||
tick := time.NewTicker(time.Duration(widget.RefreshInterval) * time.Second)
|
||||
quit := make(chan struct{})
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-tick.C:
|
||||
widget.Refresh()
|
||||
case <-quit:
|
||||
tick.Stop()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,12 @@ func NewWidget() *Widget {
|
||||
BaseWidget: wtf.BaseWidget{
|
||||
Name: "Weather",
|
||||
RefreshedAt: time.Now(),
|
||||
RefreshInterval: 15,
|
||||
RefreshInt: 900,
|
||||
},
|
||||
}
|
||||
|
||||
widget.addView()
|
||||
go widget.refresher()
|
||||
go wtf.Refresh(&widget)
|
||||
|
||||
return &widget
|
||||
}
|
||||
@ -132,21 +132,6 @@ func icon(data *owm.CurrentWeatherData) string {
|
||||
return icon
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (widget *Widget) refreshedAt() string {
|
||||
return widget.RefreshedAt.Format("15:04:05")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user