From e97283433f6089f6822b2bec2374db9af1a72579 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Thu, 25 Apr 2019 20:18:02 -0700 Subject: [PATCH] Fix potential race conditions in Logger --- logger/log.go | 11 ++++++++--- modules/clocks/widget.go | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/logger/log.go b/logger/log.go index 7b4b88cd..c5d3fcb3 100644 --- a/logger/log.go +++ b/logger/log.go @@ -16,6 +16,7 @@ const maxBufferSize int64 = 1024 type Widget struct { wtf.TextWidget + app *tview.Application filePath string settings *Settings } @@ -24,6 +25,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, settings.common, true), + app: app, filePath: logFilePath(), settings: settings, } @@ -48,15 +50,18 @@ func Log(msg string) { log.Println(msg) } +// Refresh updates the onscreen contents of the widget func (widget *Widget) Refresh() { if logFileMissing() { return } - widget.View.SetTitle(widget.Name()) - logLines := widget.tailFile() - widget.View.SetText(widget.contentFrom(logLines)) + + widget.app.QueueUpdateDraw(func() { + widget.View.SetTitle(widget.Name()) + widget.View.SetText(widget.contentFrom(logLines)) + }) } /* -------------------- Unexported Functions -------------------- */ diff --git a/modules/clocks/widget.go b/modules/clocks/widget.go index 3f1591c6..bcabe565 100644 --- a/modules/clocks/widget.go +++ b/modules/clocks/widget.go @@ -35,6 +35,7 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget { /* -------------------- Exported Functions -------------------- */ +// Refresh updates the onscreen contents of the widget func (widget *Widget) Refresh() { widget.app.QueueUpdateDraw(func() { sortedClocks := widget.clockColl.Sorted(widget.settings.sort)