1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/modules/gcal/widget.go
Sean Smith 018d2af3ae Add a global Redraw method for TextWidget
Partially addresses #429, by centralizing widget drawing
2019-05-10 08:42:37 -07:00

55 lines
977 B
Go

package gcal
import (
"github.com/rivo/tview"
"github.com/wtfutil/wtf/wtf"
)
type Widget struct {
wtf.TextWidget
app *tview.Application
calEvents []*CalEvent
settings *Settings
}
func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(app, settings.common, true),
app: app,
settings: settings,
}
return &widget
}
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Disable() {
widget.TextWidget.Disable()
}
func (widget *Widget) Refresh() {
if isAuthenticated() {
widget.fetchAndDisplayEvents()
return
}
widget.app.Suspend(widget.authenticate)
widget.Refresh()
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) fetchAndDisplayEvents() {
calEvents, err := widget.Fetch()
if err != nil {
widget.calEvents = []*CalEvent{}
} else {
widget.calEvents = calEvents
}
widget.display()
}