1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Fix race conditions caused by writing to view

This commit is contained in:
Chris Cummer 2019-04-24 23:54:45 -07:00
parent b7be868798
commit a1aae6206f
13 changed files with 96 additions and 41 deletions

View File

@ -12,6 +12,7 @@ import (
type Widget struct { type Widget struct {
wtf.TextWidget wtf.TextWidget
app *tview.Application
args []string args []string
cmd string cmd string
result string result string
@ -22,6 +23,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{ widget := Widget{
TextWidget: wtf.NewTextWidget(app, settings.common, false), TextWidget: wtf.NewTextWidget(app, settings.common, false),
app: app,
args: settings.args, args: settings.args,
cmd: settings.cmd, cmd: settings.cmd,
settings: settings, settings: settings,
@ -36,9 +38,11 @@ func (widget *Widget) Refresh() {
widget.execute() widget.execute()
widget.CommonSettings.Title = widget.String() 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 { func (widget *Widget) String() string {

View File

@ -44,6 +44,7 @@ func (widget *Widget) Refresh() {
widget.fetchAndDisplayEvents() widget.fetchAndDisplayEvents()
return return
} }
widget.app.Suspend(widget.authenticate) widget.app.Suspend(widget.authenticate)
widget.Refresh() widget.Refresh()
} }
@ -57,7 +58,10 @@ func (widget *Widget) fetchAndDisplayEvents() {
} else { } else {
widget.calEvents = calEvents widget.calEvents = calEvents
} }
widget.display()
widget.app.QueueUpdateDraw(func() {
widget.display()
})
} }
func updateLoop(widget *Widget) { func updateLoop(widget *Widget) {

View File

@ -92,7 +92,10 @@ func (widget *Widget) Refresh() {
sort.Slice(widget.GitRepos, func(i, j int) bool { sort.Slice(widget.GitRepos, func(i, j int) bool {
return widget.GitRepos[i].Path < widget.GitRepos[j].Path return widget.GitRepos[i].Path < widget.GitRepos[j].Path
}) })
widget.display()
widget.app.QueueUpdateDraw(func() {
widget.display()
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -26,7 +26,9 @@ type Widget struct {
GithubRepos []*GithubRepo GithubRepos []*GithubRepo
Idx int Idx int
settings *Settings
app *tview.Application
settings *Settings
} }
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { 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), HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
TextWidget: wtf.NewTextWidget(app, settings.common, true), TextWidget: wtf.NewTextWidget(app, settings.common, true),
Idx: 0, Idx: 0,
app: app,
settings: settings, settings: settings,
} }
@ -53,7 +57,9 @@ func (widget *Widget) Refresh() {
repo.Refresh() repo.Refresh()
} }
widget.display() widget.app.QueueUpdateDraw(func() {
widget.display()
})
} }
func (widget *Widget) Next() { func (widget *Widget) Next() {

View File

@ -30,6 +30,7 @@ type Widget struct {
wtf.HelpfulWidget wtf.HelpfulWidget
wtf.TextWidget wtf.TextWidget
app *tview.Application
stories []Story stories []Story
selected int selected int
settings *Settings settings *Settings
@ -40,6 +41,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
TextWidget: wtf.NewTextWidget(app, settings.common, true), TextWidget: wtf.NewTextWidget(app, settings.common, true),
app: app,
settings: settings, settings: settings,
} }
@ -83,7 +85,9 @@ func (widget *Widget) Refresh() {
widget.stories = stories widget.stories = stories
} }
widget.display() widget.app.QueueUpdateDraw(func() {
widget.display()
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -23,6 +23,7 @@ type Widget struct {
wtf.HelpfulWidget wtf.HelpfulWidget
wtf.TextWidget wtf.TextWidget
app *tview.Application
language string language string
result string result string
settings *Settings settings *Settings
@ -35,6 +36,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
TextWidget: wtf.NewTextWidget(app, settings.common, true), TextWidget: wtf.NewTextWidget(app, settings.common, true),
app: app,
settings: settings, settings: settings,
} }
@ -46,9 +48,10 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
} }
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
widget.nbascore() widget.app.QueueUpdateDraw(func() {
widget.nbascore()
widget.View.SetTitle(widget.ContextualTitle(widget.Name())) widget.View.SetTitle(widget.ContextualTitle(widget.Name()))
})
} }
func (widget *Widget) nbascore() { func (widget *Widget) nbascore() {

View File

@ -10,7 +10,9 @@ import (
type Widget struct { type Widget struct {
wtf.TextWidget wtf.TextWidget
Battery *Battery Battery *Battery
app *tview.Application
settings *Settings settings *Settings
} }
@ -18,7 +20,9 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{ widget := Widget{
TextWidget: wtf.NewTextWidget(app, settings.common, false), TextWidget: wtf.NewTextWidget(app, settings.common, false),
Battery: NewBattery(), Battery: NewBattery(),
app: app,
settings: settings, settings: settings,
} }
@ -35,5 +39,7 @@ func (widget *Widget) Refresh() {
content = content + "\n" content = content + "\n"
content = content + widget.Battery.String() content = content + widget.Battery.String()
widget.View.SetText(content) widget.app.QueueUpdateDraw(func() {
widget.View.SetText(content)
})
} }

View File

@ -11,8 +11,10 @@ import (
type Widget struct { type Widget struct {
wtf.TextWidget wtf.TextWidget
Date string Date string
Version string Version string
app *tview.App
settings *Settings settings *Settings
systemInfo *SystemInfo systemInfo *SystemInfo
} }
@ -21,7 +23,9 @@ func NewWidget(app *tview.Application, date, version string, settings *Settings)
widget := Widget{ widget := Widget{
TextWidget: wtf.NewTextWidget(app, settings.common, false), TextWidget: wtf.NewTextWidget(app, settings.common, false),
Date: date, Date: date,
app: app,
settings: settings, settings: settings,
Version: version, Version: version,
} }
@ -32,19 +36,21 @@ func NewWidget(app *tview.Application, date, version string, settings *Settings)
} }
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
widget.View.SetText( widget.app.QueueUpdateDraw(func() {
fmt.Sprintf( widget.View.SetText(
"%8s: %s\n%8s: %s\n\n%8s: %s\n%8s: %s", fmt.Sprintf(
"Built", "%8s: %s\n%8s: %s\n\n%8s: %s\n%8s: %s",
widget.prettyDate(), "Built",
"Vers", widget.prettyDate(),
widget.Version, "Vers",
"OS", widget.Version,
widget.systemInfo.ProductVersion, "OS",
"Build", widget.systemInfo.ProductVersion,
widget.systemInfo.BuildVersion, "Build",
), widget.systemInfo.BuildVersion,
) ),
)
})
} }
func (widget *Widget) prettyDate() string { func (widget *Widget) prettyDate() string {

View File

@ -35,6 +35,7 @@ type Widget struct {
wtf.MultiSourceWidget wtf.MultiSourceWidget
wtf.TextWidget wtf.TextWidget
app *tview.Application
settings *Settings settings *Settings
} }
@ -44,6 +45,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common.ConfigKey, "filePath", "filePaths"), MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common.ConfigKey, "filePath", "filePaths"),
TextWidget: wtf.NewTextWidget(app, settings.common, true), TextWidget: wtf.NewTextWidget(app, settings.common, true),
app: app,
settings: settings, 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 // 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 // text files that first time. After that, the watcher takes over
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
widget.display() widget.app.QueueUpdateDraw(func() {
widget.display()
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -29,6 +29,7 @@ type Widget struct {
wtf.HelpfulWidget wtf.HelpfulWidget
wtf.TextWidget wtf.TextWidget
app *tview.Application
idx int idx int
projects []*Project projects []*Project
settings *Settings settings *Settings
@ -39,6 +40,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
TextWidget: wtf.NewTextWidget(app, settings.common, true), TextWidget: wtf.NewTextWidget(app, settings.common, true),
app: app,
settings: settings, settings: settings,
} }
@ -88,7 +90,9 @@ func (w *Widget) Refresh() {
return return
} }
w.display() w.app.QueueUpdateDraw(func() {
w.display()
})
} }
/* -------------------- Keyboard Movement -------------------- */ /* -------------------- Keyboard Movement -------------------- */

View File

@ -27,6 +27,7 @@ type Widget struct {
wtf.MultiSourceWidget wtf.MultiSourceWidget
wtf.TextWidget wtf.TextWidget
app *tview.Application
client *Client client *Client
idx int idx int
settings *Settings settings *Settings
@ -39,6 +40,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common.ConfigKey, "screenName", "screenNames"), MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common.ConfigKey, "screenName", "screenNames"),
TextWidget: wtf.NewTextWidget(app, settings.common, true), TextWidget: wtf.NewTextWidget(app, settings.common, true),
app: app,
idx: 0, idx: 0,
settings: settings, 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 // Refresh is called on the interval and refreshes the data
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
widget.display() widget.app.QueueUpdateDraw(func() {
widget.display()
})
} }
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */

View File

@ -12,6 +12,7 @@ import (
type Widget struct { type Widget struct {
wtf.TextWidget wtf.TextWidget
app *tview.Application
result string result string
settings *Settings settings *Settings
} }
@ -20,6 +21,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{ widget := Widget{
TextWidget: wtf.NewTextWidget(app, settings.common, false), TextWidget: wtf.NewTextWidget(app, settings.common, false),
app: app,
settings: settings, settings: settings,
} }
@ -29,7 +31,9 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
widget.prettyWeather() 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 //this method reads the config and calls wttr.in for pretty weather

View File

@ -24,8 +24,10 @@ type Widget struct {
wtf.TextWidget wtf.TextWidget
// APIKey string // APIKey string
Data []*owm.CurrentWeatherData Data []*owm.CurrentWeatherData
Idx int Idx int
app *tview.Application
settings *Settings settings *Settings
} }
@ -35,13 +37,12 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText), HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
TextWidget: wtf.NewTextWidget(app, settings.common, true), TextWidget: wtf.NewTextWidget(app, settings.common, true),
Idx: 0, Idx: 0,
app: app,
settings: settings, settings: settings,
} }
// widget.loadAPICredentials()
// widget.APIKey
widget.HelpfulWidget.SetView(widget.View) widget.HelpfulWidget.SetView(widget.View)
widget.View.SetInputCapture(widget.keyboardIntercept) widget.View.SetInputCapture(widget.keyboardIntercept)
@ -73,7 +74,9 @@ func (widget *Widget) Refresh() {
widget.Data = widget.Fetch(wtf.ToInts(widget.settings.cityIDs)) 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 // Next displays data for the next city data in the list. If the current city is the last