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:
parent
b7be868798
commit
a1aae6206f
@ -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 {
|
||||
|
@ -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) {
|
||||
|
@ -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 -------------------- */
|
||||
|
@ -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() {
|
||||
|
@ -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 -------------------- */
|
||||
|
@ -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() {
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 -------------------- */
|
||||
|
@ -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 -------------------- */
|
||||
|
@ -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 -------------------- */
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user