mirror of
				https://github.com/taigrr/wtf
				synced 2025-01-18 04:03:14 -08:00 
			
		
		
		
	
		
			
				
	
	
		
			55 lines
		
	
	
		
			977 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			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()
 | 
						|
}
 |