diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2023-09-20 08:08:14 +0200 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2023-09-20 13:29:11 +0200 |
commit | c222a618a86c2b434bbb92fc1e3ba95273daa002 (patch) | |
tree | 11f56e304ba657516f8711fa41dcbf2d61d55993 | |
parent | 05c32e292e307a245eabcb2344bd1527d69f64f2 (diff) |
Extract WaitingStatusHandle
-rw-r--r-- | pkg/gui/controllers/helpers/app_status_helper.go | 4 | ||||
-rw-r--r-- | pkg/gui/status/status_manager.go | 25 |
2 files changed, 23 insertions, 6 deletions
diff --git a/pkg/gui/controllers/helpers/app_status_helper.go b/pkg/gui/controllers/helpers/app_status_helper.go index a6befe1a2..bdab8f1b1 100644 --- a/pkg/gui/controllers/helpers/app_status_helper.go +++ b/pkg/gui/controllers/helpers/app_status_helper.go @@ -36,9 +36,7 @@ func (self *AppStatusHelper) Toast(message string) { // 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) { - self.statusMgr().WithWaitingStatus(message, func() { - self.renderAppStatus() - + self.statusMgr().WithWaitingStatus(message, self.renderAppStatus, func() { if err := f(task); err != nil { self.c.OnUIThread(func() error { return self.c.Error(err) diff --git a/pkg/gui/status/status_manager.go b/pkg/gui/status/status_manager.go index ba04e14f2..1e2aa9cf1 100644 --- a/pkg/gui/status/status_manager.go +++ b/pkg/gui/status/status_manager.go @@ -16,6 +16,24 @@ type StatusManager struct { mutex deadlock.Mutex } +// Can be used to manipulate a waiting status while it is running (e.g. pause +// and resume it) +type WaitingStatusHandle struct { + statusManager *StatusManager + message string + renderFunc func() + id int +} + +func (self *WaitingStatusHandle) Show() { + self.id = self.statusManager.addStatus(self.message, "waiting") + self.renderFunc() +} + +func (self *WaitingStatusHandle) Hide() { + self.statusManager.removeStatus(self.id) +} + type appStatus struct { message string statusType string @@ -26,12 +44,13 @@ func NewStatusManager() *StatusManager { return &StatusManager{} } -func (self *StatusManager) WithWaitingStatus(message string, f func()) { - id := self.addStatus(message, "waiting") +func (self *StatusManager) WithWaitingStatus(message string, renderFunc func(), f func()) { + handle := &WaitingStatusHandle{statusManager: self, message: message, renderFunc: renderFunc, id: -1} + handle.Show() f() - self.removeStatus(id) + handle.Hide() } func (self *StatusManager) AddToastStatus(message string) int { |