mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
When there are lot of events, the content in teh widget is hidden and there is no way to view the upcoming events. Making the widget focussable allows for one to scroll through the list of calendar events using the arrow keys
68 lines
1.1 KiB
Go
68 lines
1.1 KiB
Go
package gcal
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/senorprogrammer/wtf/wtf"
|
|
)
|
|
|
|
type Widget struct {
|
|
wtf.TextWidget
|
|
|
|
calEvents []*CalEvent
|
|
ch chan struct{}
|
|
mutex sync.Mutex
|
|
}
|
|
|
|
func NewWidget() *Widget {
|
|
widget := Widget{
|
|
TextWidget: wtf.NewTextWidget("Calendar", "gcal", true),
|
|
ch: make(chan struct{}),
|
|
}
|
|
|
|
go updateLoop(&widget)
|
|
|
|
return &widget
|
|
}
|
|
|
|
/* -------------------- Exported Functions -------------------- */
|
|
|
|
func (widget *Widget) Disable() {
|
|
close(widget.ch)
|
|
widget.TextWidget.Disable()
|
|
}
|
|
|
|
func (widget *Widget) Refresh() {
|
|
calEvents, err := Fetch()
|
|
if err != nil {
|
|
widget.calEvents = []*CalEvent{}
|
|
} else {
|
|
widget.calEvents = calEvents
|
|
}
|
|
|
|
widget.UpdateRefreshedAt()
|
|
widget.display()
|
|
}
|
|
|
|
/* -------------------- Unexported Functions -------------------- */
|
|
|
|
func updateLoop(widget *Widget) {
|
|
interval := wtf.Config.UInt("wtf.mods.gcal.textInterval", 30)
|
|
if interval == 0 {
|
|
return
|
|
}
|
|
|
|
tick := time.NewTicker(time.Duration(interval) * time.Second)
|
|
defer tick.Stop()
|
|
outer:
|
|
for {
|
|
select {
|
|
case <-tick.C:
|
|
widget.display()
|
|
case <-widget.ch:
|
|
break outer
|
|
}
|
|
}
|
|
}
|