diff --git a/modules/cmdrunner/widget.go b/modules/cmdrunner/widget.go index edb6fa13..1742234e 100644 --- a/modules/cmdrunner/widget.go +++ b/modules/cmdrunner/widget.go @@ -12,6 +12,7 @@ import ( type Widget struct { wtf.TextWidget + app *tview.Application args []string cmd string result string @@ -22,6 +23,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), + app: app, args: settings.args, cmd: settings.cmd, settings: settings, @@ -36,9 +38,11 @@ func (widget *Widget) Refresh() { widget.execute() widget.CommonSettings.Title = widget.String() - widget.View.SetTitle(tview.TranslateANSI(widget.CommonSettings.Title)) - widget.View.SetText(widget.result) + widget.app.QueueUpdateDraw(func() { + widget.View.SetTitle(tview.TranslateANSI(widget.CommonSettings.Title)) + widget.View.SetText(widget.result) + }) } func (widget *Widget) String() string { diff --git a/modules/gcal/widget.go b/modules/gcal/widget.go index ecc40cd7..67fc4aec 100644 --- a/modules/gcal/widget.go +++ b/modules/gcal/widget.go @@ -44,6 +44,7 @@ func (widget *Widget) Refresh() { widget.fetchAndDisplayEvents() return } + widget.app.Suspend(widget.authenticate) widget.Refresh() } @@ -57,7 +58,10 @@ func (widget *Widget) fetchAndDisplayEvents() { } else { widget.calEvents = calEvents } - widget.display() + + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } func updateLoop(widget *Widget) { diff --git a/modules/git/widget.go b/modules/git/widget.go index f63952c7..855a44b6 100644 --- a/modules/git/widget.go +++ b/modules/git/widget.go @@ -92,7 +92,10 @@ func (widget *Widget) Refresh() { sort.Slice(widget.GitRepos, func(i, j int) bool { return widget.GitRepos[i].Path < widget.GitRepos[j].Path }) - widget.display() + + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/github/widget.go b/modules/github/widget.go index 8021183b..be998dc0 100644 --- a/modules/github/widget.go +++ b/modules/github/widget.go @@ -26,7 +26,9 @@ type Widget struct { GithubRepos []*GithubRepo Idx int - settings *Settings + + app *tview.Application + settings *Settings } func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { @@ -34,7 +36,9 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), TextWidget: wtf.NewTextWidget(app, settings.common, true), - Idx: 0, + Idx: 0, + + app: app, settings: settings, } @@ -53,7 +57,9 @@ func (widget *Widget) Refresh() { repo.Refresh() } - widget.display() + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } func (widget *Widget) Next() { diff --git a/modules/hackernews/widget.go b/modules/hackernews/widget.go index f682230b..5bcf3473 100644 --- a/modules/hackernews/widget.go +++ b/modules/hackernews/widget.go @@ -30,6 +30,7 @@ type Widget struct { wtf.HelpfulWidget wtf.TextWidget + app *tview.Application stories []Story selected int settings *Settings @@ -40,6 +41,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), TextWidget: wtf.NewTextWidget(app, settings.common, true), + app: app, settings: settings, } @@ -83,7 +85,9 @@ func (widget *Widget) Refresh() { widget.stories = stories } - widget.display() + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/nbascore/widget.go b/modules/nbascore/widget.go index d506fcee..9596df21 100644 --- a/modules/nbascore/widget.go +++ b/modules/nbascore/widget.go @@ -23,6 +23,7 @@ type Widget struct { wtf.HelpfulWidget wtf.TextWidget + app *tview.Application language string result string settings *Settings @@ -35,6 +36,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), TextWidget: wtf.NewTextWidget(app, settings.common, true), + app: app, settings: settings, } @@ -46,9 +48,10 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * } func (widget *Widget) Refresh() { - widget.nbascore() - - widget.View.SetTitle(widget.ContextualTitle(widget.Name())) + widget.app.QueueUpdateDraw(func() { + widget.nbascore() + widget.View.SetTitle(widget.ContextualTitle(widget.Name())) + }) } func (widget *Widget) nbascore() { diff --git a/modules/power/widget.go b/modules/power/widget.go index db25265e..5ef57f08 100644 --- a/modules/power/widget.go +++ b/modules/power/widget.go @@ -10,7 +10,9 @@ import ( type Widget struct { wtf.TextWidget - Battery *Battery + Battery *Battery + + app *tview.Application settings *Settings } @@ -18,7 +20,9 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), - Battery: NewBattery(), + Battery: NewBattery(), + + app: app, settings: settings, } @@ -35,5 +39,7 @@ func (widget *Widget) Refresh() { content = content + "\n" content = content + widget.Battery.String() - widget.View.SetText(content) + widget.app.QueueUpdateDraw(func() { + widget.View.SetText(content) + }) } diff --git a/modules/system/widget.go b/modules/system/widget.go index 4bf5b32d..113cfbc8 100644 --- a/modules/system/widget.go +++ b/modules/system/widget.go @@ -11,8 +11,10 @@ import ( type Widget struct { wtf.TextWidget - Date string - Version string + Date string + Version string + + app *tview.App settings *Settings systemInfo *SystemInfo } @@ -21,7 +23,9 @@ func NewWidget(app *tview.Application, date, version string, settings *Settings) widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), - Date: date, + Date: date, + + app: app, settings: settings, Version: version, } @@ -32,19 +36,21 @@ func NewWidget(app *tview.Application, date, version string, settings *Settings) } func (widget *Widget) Refresh() { - widget.View.SetText( - fmt.Sprintf( - "%8s: %s\n%8s: %s\n\n%8s: %s\n%8s: %s", - "Built", - widget.prettyDate(), - "Vers", - widget.Version, - "OS", - widget.systemInfo.ProductVersion, - "Build", - widget.systemInfo.BuildVersion, - ), - ) + widget.app.QueueUpdateDraw(func() { + widget.View.SetText( + fmt.Sprintf( + "%8s: %s\n%8s: %s\n\n%8s: %s\n%8s: %s", + "Built", + widget.prettyDate(), + "Vers", + widget.Version, + "OS", + widget.systemInfo.ProductVersion, + "Build", + widget.systemInfo.BuildVersion, + ), + ) + }) } func (widget *Widget) prettyDate() string { diff --git a/modules/textfile/widget.go b/modules/textfile/widget.go index c4e29f80..78167031 100644 --- a/modules/textfile/widget.go +++ b/modules/textfile/widget.go @@ -35,6 +35,7 @@ type Widget struct { wtf.MultiSourceWidget wtf.TextWidget + app *tview.Application settings *Settings } @@ -44,6 +45,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common.ConfigKey, "filePath", "filePaths"), TextWidget: wtf.NewTextWidget(app, settings.common, true), + app: app, settings: settings, } @@ -67,7 +69,9 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * // Refresh is only called once on start-up. Its job is to display the // text files that first time. After that, the watcher takes over func (widget *Widget) Refresh() { - widget.display() + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/todoist/widget.go b/modules/todoist/widget.go index 0a57c22e..98b9e626 100644 --- a/modules/todoist/widget.go +++ b/modules/todoist/widget.go @@ -29,6 +29,7 @@ type Widget struct { wtf.HelpfulWidget wtf.TextWidget + app *tview.Application idx int projects []*Project settings *Settings @@ -39,6 +40,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), TextWidget: wtf.NewTextWidget(app, settings.common, true), + app: app, settings: settings, } @@ -88,7 +90,9 @@ func (w *Widget) Refresh() { return } - w.display() + w.app.QueueUpdateDraw(func() { + w.display() + }) } /* -------------------- Keyboard Movement -------------------- */ diff --git a/modules/twitter/widget.go b/modules/twitter/widget.go index 16383ac1..4c6adcfd 100644 --- a/modules/twitter/widget.go +++ b/modules/twitter/widget.go @@ -27,6 +27,7 @@ type Widget struct { wtf.MultiSourceWidget wtf.TextWidget + app *tview.Application client *Client idx int settings *Settings @@ -39,6 +40,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common.ConfigKey, "screenName", "screenNames"), TextWidget: wtf.NewTextWidget(app, settings.common, true), + app: app, idx: 0, settings: settings, } @@ -62,7 +64,9 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * // Refresh is called on the interval and refreshes the data func (widget *Widget) Refresh() { - widget.display() + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/weatherservices/prettyweather/widget.go b/modules/weatherservices/prettyweather/widget.go index 3107db35..f7b7a500 100644 --- a/modules/weatherservices/prettyweather/widget.go +++ b/modules/weatherservices/prettyweather/widget.go @@ -12,6 +12,7 @@ import ( type Widget struct { wtf.TextWidget + app *tview.Application result string settings *Settings } @@ -20,6 +21,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, false), + app: app, settings: settings, } @@ -29,7 +31,9 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { func (widget *Widget) Refresh() { widget.prettyWeather() - widget.View.SetText(widget.result) + widget.app.QueueUpdateDraw(func() { + widget.View.SetText(widget.result) + }) } //this method reads the config and calls wttr.in for pretty weather diff --git a/modules/weatherservices/weather/widget.go b/modules/weatherservices/weather/widget.go index c4017b36..4484a9cc 100644 --- a/modules/weatherservices/weather/widget.go +++ b/modules/weatherservices/weather/widget.go @@ -24,8 +24,10 @@ type Widget struct { wtf.TextWidget // APIKey string - Data []*owm.CurrentWeatherData - Idx int + Data []*owm.CurrentWeatherData + Idx int + + app *tview.Application settings *Settings } @@ -35,13 +37,12 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) * HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), TextWidget: wtf.NewTextWidget(app, settings.common, true), - Idx: 0, + Idx: 0, + + app: app, settings: settings, } - // widget.loadAPICredentials() - // widget.APIKey - widget.HelpfulWidget.SetView(widget.View) widget.View.SetInputCapture(widget.keyboardIntercept) @@ -73,7 +74,9 @@ func (widget *Widget) Refresh() { widget.Data = widget.Fetch(wtf.ToInts(widget.settings.cityIDs)) } - widget.display() + widget.app.QueueUpdateDraw(func() { + widget.display() + }) } // Next displays data for the next city data in the list. If the current city is the last