From 06da246c3a591ffc4f8ef565f44cdf9590668f4f Mon Sep 17 00:00:00 2001 From: aditya-K2 Date: Mon, 3 Oct 2022 15:37:26 +0530 Subject: [PATCH] Using QueueUpdateDraw() instead of Draw() The Draw() function still seems to slow down the App Hence Using QueueUpdateDraw() this makes it a little faster The Problem now is that the ProgressBar constantly makes request to mpd which in turn causes the slow down. --- main.go | 3 ++- ui/app.go | 2 +- ui/progressBar.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 1008e53..11af91b 100644 --- a/main.go +++ b/main.go @@ -338,8 +338,9 @@ func main() { }) go func() { + drawFunc := func() { ui.ProgressFunction() } for { - ui.Ui.App.Draw() + ui.Ui.App.QueueUpdateDraw(drawFunc) time.Sleep(time.Second) } }() diff --git a/ui/app.go b/ui/app.go index 34d2b98..b95294a 100644 --- a/ui/app.go +++ b/ui/app.go @@ -25,7 +25,7 @@ type Application struct { func NewApplication() *Application { pBar := NewProgressBar() - pBar.SetProgressFunc(progressFunction) + pBar.SetProgressFunc(ProgressFunction) expandedView := tview.NewTable() Navbar := tview.NewTable() searchBar := tview.NewInputField() diff --git a/ui/progressBar.go b/ui/progressBar.go index f950bb7..24e2fa7 100644 --- a/ui/progressBar.go +++ b/ui/progressBar.go @@ -82,7 +82,7 @@ func (self *ProgressBar) Draw(screen tcell.Screen) { x, y+2, _width-OFFSET, tview.AlignRight, tcell.ColorWhite) } -func progressFunction() (string, string, string, float64) { +func ProgressFunction() (string, string, string, float64) { _currentAttributes, err := CONN.CurrentSong() var song, top, text string var percentage float64