mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Merge branch 'baustinanki-gcal-until-update'
This commit is contained in:
commit
4fe9a73b14
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/senorprogrammer/wtf/wtf"
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
@ -12,13 +13,20 @@ import (
|
|||||||
|
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
|
events *calendar.Events
|
||||||
|
ch chan struct{}
|
||||||
|
mutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget() *Widget {
|
func NewWidget() *Widget {
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(" Calendar ", "gcal", false),
|
TextWidget: wtf.NewTextWidget(" Calendar ", "gcal", false),
|
||||||
|
ch: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go updateLoop(&widget)
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,14 +34,30 @@ func NewWidget() *Widget {
|
|||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
events, _ := Fetch()
|
events, _ := Fetch()
|
||||||
|
widget.events = events
|
||||||
|
|
||||||
widget.UpdateRefreshedAt()
|
widget.UpdateRefreshedAt()
|
||||||
|
|
||||||
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(events)))
|
widget.display()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) Disable() {
|
||||||
|
close(widget.ch)
|
||||||
|
widget.TextWidget.Disable()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
|
func (widget *Widget) display() {
|
||||||
|
if widget.events == nil || len(widget.events.Items) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
widget.mutex.Lock()
|
||||||
|
defer widget.mutex.Unlock()
|
||||||
|
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(widget.events)))
|
||||||
|
}
|
||||||
|
|
||||||
// conflicts returns TRUE if this event conflicts with another, FALSE if it does not
|
// conflicts returns TRUE if this event conflicts with another, FALSE if it does not
|
||||||
func (widget *Widget) conflicts(event *calendar.Event, events *calendar.Events) bool {
|
func (widget *Widget) conflicts(event *calendar.Event, events *calendar.Events) bool {
|
||||||
conflict := false
|
conflict := false
|
||||||
@ -254,3 +278,22 @@ func (widget *Widget) until(event *calendar.Event) string {
|
|||||||
|
|
||||||
return "[lightblue]" + untilStr + "[white]"
|
return "[lightblue]" + untilStr + "[white]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1
wtf.go
1
wtf.go
@ -134,6 +134,7 @@ func watchForConfigChanges(app *tview.Application, configFilePath string, grid *
|
|||||||
loadConfigFile(configFilePath)
|
loadConfigFile(configFilePath)
|
||||||
// Disable all widgets to stop scheduler goroutines and rmeove widgets from memory.
|
// Disable all widgets to stop scheduler goroutines and rmeove widgets from memory.
|
||||||
disableAllWidgets()
|
disableAllWidgets()
|
||||||
|
Widgets = nil
|
||||||
makeWidgets(app, pages)
|
makeWidgets(app, pages)
|
||||||
initializeFocusTracker(app)
|
initializeFocusTracker(app)
|
||||||
display := wtf.NewDisplay(Widgets)
|
display := wtf.NewDisplay(Widgets)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user