/
widget.go
57 lines (44 loc) · 1.08 KB
/
widget.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package gcal
import (
"github.com/rivo/tview"
"github.com/wtfutil/wtf/view"
)
type Widget struct {
view.TextWidget
calEvents []*CalEvent
err error
settings *Settings
tviewApp *tview.Application
}
func NewWidget(tviewApp *tview.Application, redrawChan chan bool, settings *Settings) *Widget {
widget := Widget{
TextWidget: view.NewTextWidget(tviewApp, redrawChan, nil, settings.Common),
tviewApp: tviewApp,
settings: settings,
}
return &widget
}
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Disable() {
widget.TextWidget.Disable()
}
func (widget *Widget) Refresh() {
if isAuthenticated(widget.settings.email) {
widget.fetchAndDisplayEvents()
return
}
widget.tviewApp.Suspend(widget.authenticate)
widget.Refresh()
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) fetchAndDisplayEvents() {
calEvents, err := widget.Fetch()
if err != nil {
widget.err = err
widget.calEvents = []*CalEvent{}
} else {
widget.err = nil
widget.calEvents = calEvents
}
widget.display()
}