From e48e7a2ebc51ea2b008096574cd14fea6c7c9dcb Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 29 Jan 2025 13:19:28 +0100 Subject: [PATCH 1/2] Extract the inner part of WithWaitingStatus as a synchronous variant of it This is the same as WithWaitingStatus but without the implicit OnWorker, for those who are on a background thread already. --- pkg/gui/controllers/helpers/app_status_helper.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/gui/controllers/helpers/app_status_helper.go b/pkg/gui/controllers/helpers/app_status_helper.go index cf94c58cd..937518632 100644 --- a/pkg/gui/controllers/helpers/app_status_helper.go +++ b/pkg/gui/controllers/helpers/app_status_helper.go @@ -60,9 +60,13 @@ func (self appStatusHelperTask) Continue() { // withWaitingStatus wraps a function and shows a waiting status while the function is still executing func (self *AppStatusHelper) WithWaitingStatus(message string, f func(gocui.Task) error) { self.c.OnWorker(func(task gocui.Task) error { - return self.statusMgr().WithWaitingStatus(message, self.renderAppStatus, func(waitingStatusHandle *status.WaitingStatusHandle) error { - return f(appStatusHelperTask{task, waitingStatusHandle}) - }) + return self.WithWaitingStatusImpl(message, f, task) + }) +} + +func (self *AppStatusHelper) WithWaitingStatusImpl(message string, f func(gocui.Task) error, task gocui.Task) error { + return self.statusMgr().WithWaitingStatus(message, self.renderAppStatus, func(waitingStatusHandle *status.WaitingStatusHandle) error { + return f(appStatusHelperTask{task, waitingStatusHandle}) }) } From 638c9c5fe7a5cc8e4f07c87201d86703474d7a71 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Wed, 29 Jan 2025 13:26:05 +0100 Subject: [PATCH 2/2] Fix flicker when showing the status of a background fetch This was recently introduced, but it was done the wrong way. WithWaitingStatusSync should only be called from the main thread, and it is meant to be used for updating the bottom line while the UI is blocked. It is a bad idea to call this from a background thread, and it results in ugly flicker (occasionally). Use the newly extracted WithWaitingStatusImpl instead, this is the same as WithWaitingStatus (which is exactly what we need) but without the implicit OnWorker, which we don't want because we are on a background thread already. --- pkg/gui/background.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/gui/background.go b/pkg/gui/background.go index 1be8d2e21..8142c9af9 100644 --- a/pkg/gui/background.go +++ b/pkg/gui/background.go @@ -76,9 +76,9 @@ func (self *BackgroundRoutineMgr) startBackgroundFetch() { self.gui.waitForIntro.Wait() fetch := func() error { - return self.gui.PopupHandler.WithWaitingStatusSync(self.gui.Tr.FetchingStatus, func() error { + return self.gui.helpers.AppStatus.WithWaitingStatusImpl(self.gui.Tr.FetchingStatus, func(gocui.Task) error { return self.backgroundFetch() - }) + }, nil) } // We want an immediate fetch at startup, and since goEvery starts by