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
@ -16,14 +16,14 @@ type Widget struct {
|
|||||||
func NewWidget() *Widget {
|
func NewWidget() *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
BaseWidget: wtf.BaseWidget{
|
BaseWidget: wtf.BaseWidget{
|
||||||
Name: "BambooHR",
|
Name: "BambooHR",
|
||||||
RefreshedAt: time.Now(),
|
RefreshedAt: time.Now(),
|
||||||
RefreshInterval: 15,
|
RefreshInt: 15,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.addView()
|
widget.addView()
|
||||||
go widget.refresher()
|
go wtf.Refresh(&widget)
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
@ -82,18 +82,3 @@ func (widget *Widget) display(item Item) string {
|
|||||||
|
|
||||||
return str
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -18,14 +18,14 @@ type Widget struct {
|
|||||||
func NewWidget() *Widget {
|
func NewWidget() *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
BaseWidget: wtf.BaseWidget{
|
BaseWidget: wtf.BaseWidget{
|
||||||
Name: "Calendar",
|
Name: "Calendar",
|
||||||
RefreshedAt: time.Now(),
|
RefreshedAt: time.Now(),
|
||||||
RefreshInterval: 3,
|
RefreshInt: 180,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.addView()
|
widget.addView()
|
||||||
go widget.refresher()
|
go wtf.Refresh(&widget)
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
@ -95,21 +95,6 @@ func descriptionColor(item *calendar.Event) string {
|
|||||||
return color
|
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
|
// until returns the number of hours or days until the event
|
||||||
// If the event is in the past, returns nil
|
// If the event is in the past, returns nil
|
||||||
func (widget *Widget) until(start time.Time) string {
|
func (widget *Widget) until(start time.Time) string {
|
||||||
|
@ -18,14 +18,14 @@ type Widget struct {
|
|||||||
func NewWidget() *Widget {
|
func NewWidget() *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
BaseWidget: wtf.BaseWidget{
|
BaseWidget: wtf.BaseWidget{
|
||||||
Name: "Git",
|
Name: "Git",
|
||||||
RefreshedAt: time.Now(),
|
RefreshedAt: time.Now(),
|
||||||
RefreshInterval: 10,
|
RefreshInt: 10,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.addView()
|
widget.addView()
|
||||||
go widget.refresher()
|
go wtf.Refresh(&widget)
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
@ -116,18 +116,3 @@ func (widget *Widget) formatCommits(data []string) string {
|
|||||||
func (widget *Widget) formatCommit(line string) string {
|
func (widget *Widget) formatCommit(line string) string {
|
||||||
return fmt.Sprintf(" %s\n", strings.Replace(line, "\"", "", -1))
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -16,14 +16,14 @@ type Widget struct {
|
|||||||
func NewWidget() *Widget {
|
func NewWidget() *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
BaseWidget: wtf.BaseWidget{
|
BaseWidget: wtf.BaseWidget{
|
||||||
Name: "JIRA",
|
Name: "JIRA",
|
||||||
RefreshedAt: time.Now(),
|
RefreshedAt: time.Now(),
|
||||||
RefreshInterval: 8,
|
RefreshInt: 900,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.addView()
|
widget.addView()
|
||||||
go widget.refresher()
|
go wtf.Refresh(&widget)
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
@ -49,18 +49,3 @@ func (widget *Widget) addView() {
|
|||||||
|
|
||||||
widget.View = view
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -16,14 +16,14 @@ type Widget struct {
|
|||||||
func NewWidget() *Widget {
|
func NewWidget() *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
BaseWidget: wtf.BaseWidget{
|
BaseWidget: wtf.BaseWidget{
|
||||||
Name: "OpsGenie",
|
Name: "OpsGenie",
|
||||||
RefreshedAt: time.Now(),
|
RefreshedAt: time.Now(),
|
||||||
RefreshInterval: 8,
|
RefreshInt: 28800,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.addView()
|
widget.addView()
|
||||||
go widget.refresher()
|
go wtf.Refresh(&widget)
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
@ -49,18 +49,3 @@ func (widget *Widget) addView() {
|
|||||||
|
|
||||||
widget.View = view
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -17,14 +17,14 @@ type Widget struct {
|
|||||||
func NewWidget() *Widget {
|
func NewWidget() *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
BaseWidget: wtf.BaseWidget{
|
BaseWidget: wtf.BaseWidget{
|
||||||
Name: "Security",
|
Name: "Security",
|
||||||
RefreshedAt: time.Now(),
|
RefreshedAt: time.Now(),
|
||||||
RefreshInterval: 60,
|
RefreshInt: 3600,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.addView()
|
widget.addView()
|
||||||
go widget.refresher()
|
go wtf.Refresh(&widget)
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
@ -70,18 +70,3 @@ func (widget *Widget) contentFrom(data map[string]string) string {
|
|||||||
|
|
||||||
return str
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -17,14 +17,14 @@ type Widget struct {
|
|||||||
func NewWidget() *Widget {
|
func NewWidget() *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
BaseWidget: wtf.BaseWidget{
|
BaseWidget: wtf.BaseWidget{
|
||||||
Name: "Status",
|
Name: "Status",
|
||||||
RefreshedAt: time.Now(),
|
RefreshedAt: time.Now(),
|
||||||
RefreshInterval: 1,
|
RefreshInt: 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.addView()
|
widget.addView()
|
||||||
go widget.refresher()
|
go wtf.Refresh(&widget)
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
@ -54,18 +54,3 @@ func (widget *Widget) addView() {
|
|||||||
func (widget *Widget) contentFrom() string {
|
func (widget *Widget) contentFrom() string {
|
||||||
return fmt.Sprint(rand.Intn(100))
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -18,14 +18,14 @@ type Widget struct {
|
|||||||
func NewWidget() *Widget {
|
func NewWidget() *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
BaseWidget: wtf.BaseWidget{
|
BaseWidget: wtf.BaseWidget{
|
||||||
Name: "Weather",
|
Name: "Weather",
|
||||||
RefreshedAt: time.Now(),
|
RefreshedAt: time.Now(),
|
||||||
RefreshInterval: 15,
|
RefreshInt: 900,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.addView()
|
widget.addView()
|
||||||
go widget.refresher()
|
go wtf.Refresh(&widget)
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
@ -132,21 +132,6 @@ func icon(data *owm.CurrentWeatherData) string {
|
|||||||
return icon
|
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 {
|
func (widget *Widget) refreshedAt() string {
|
||||||
return widget.RefreshedAt.Format("15:04:05")
|
return widget.RefreshedAt.Format("15:04:05")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user