diff options
-rw-r--r-- | pkg/gui/controllers/helpers/app_status_helper.go | 21 | ||||
-rw-r--r-- | pkg/gui/gui.go | 4 | ||||
-rw-r--r-- | pkg/gui/popup/popup_handler.go | 7 | ||||
-rw-r--r-- | pkg/gui/status/status_manager.go | 7 |
4 files changed, 18 insertions, 21 deletions
diff --git a/pkg/gui/controllers/helpers/app_status_helper.go b/pkg/gui/controllers/helpers/app_status_helper.go index b054d0db5..31bfcca3a 100644 --- a/pkg/gui/controllers/helpers/app_status_helper.go +++ b/pkg/gui/controllers/helpers/app_status_helper.go @@ -60,25 +60,24 @@ 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) { - self.statusMgr().WithWaitingStatus(message, self.renderAppStatus, func(waitingStatusHandle *status.WaitingStatusHandle) { - if err := f(appStatusHelperTask{task, waitingStatusHandle}); err != nil { - self.c.OnUIThread(func() error { - return err - }) - } + err := self.statusMgr().WithWaitingStatus(message, self.renderAppStatus, func(waitingStatusHandle *status.WaitingStatusHandle) error { + return f(appStatusHelperTask{task, waitingStatusHandle}) }) + if err != nil { + self.c.OnUIThread(func() error { + return err + }) + } }) } -func (self *AppStatusHelper) WithWaitingStatusSync(message string, f func() error) { - self.statusMgr().WithWaitingStatus(message, func() {}, func(*status.WaitingStatusHandle) { +func (self *AppStatusHelper) WithWaitingStatusSync(message string, f func() error) error { + return self.statusMgr().WithWaitingStatus(message, func() {}, func(*status.WaitingStatusHandle) error { stop := make(chan struct{}) defer func() { close(stop) }() self.renderAppStatusSync(stop) - if err := f(); err != nil { - _ = self.c.Error(err) - } + return f() }) } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index e52d9113c..37c181b16 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -516,8 +516,8 @@ func NewGui( func() types.Context { return gui.State.ContextMgr.Current() }, gui.createMenu, func(message string, f func(gocui.Task) error) { gui.helpers.AppStatus.WithWaitingStatus(message, f) }, - func(message string, f func() error) { - gui.helpers.AppStatus.WithWaitingStatusSync(message, f) + func(message string, f func() error) error { + return gui.helpers.AppStatus.WithWaitingStatusSync(message, f) }, func(message string, kind types.ToastKind) { gui.helpers.AppStatus.Toast(message, kind) }, func() string { return gui.Views.Confirmation.TextArea.GetContent() }, diff --git a/pkg/gui/popup/popup_handler.go b/pkg/gui/popup/popup_handler.go index 40a664c0e..c8ff10d85 100644 --- a/pkg/gui/popup/popup_handler.go +++ b/pkg/gui/popup/popup_handler.go @@ -18,7 +18,7 @@ type PopupHandler struct { currentContextFn func() types.Context createMenuFn func(types.CreateMenuOptions) error withWaitingStatusFn func(message string, f func(gocui.Task) error) - withWaitingStatusSyncFn func(message string, f func() error) + withWaitingStatusSyncFn func(message string, f func() error) error toastFn func(message string, kind types.ToastKind) getPromptInputFn func() string inDemo func() bool @@ -34,7 +34,7 @@ func NewPopupHandler( currentContextFn func() types.Context, createMenuFn func(types.CreateMenuOptions) error, withWaitingStatusFn func(message string, f func(gocui.Task) error), - withWaitingStatusSyncFn func(message string, f func() error), + withWaitingStatusSyncFn func(message string, f func() error) error, toastFn func(message string, kind types.ToastKind), getPromptInputFn func() string, inDemo func() bool, @@ -76,8 +76,7 @@ func (self *PopupHandler) WithWaitingStatus(message string, f func(gocui.Task) e } func (self *PopupHandler) WithWaitingStatusSync(message string, f func() error) error { - self.withWaitingStatusSyncFn(message, f) - return nil + return self.withWaitingStatusSyncFn(message, f) } func (self *PopupHandler) Error(err error) error { diff --git a/pkg/gui/status/status_manager.go b/pkg/gui/status/status_manager.go index b1433a6f9..5cee4edc2 100644 --- a/pkg/gui/status/status_manager.go +++ b/pkg/gui/status/status_manager.go @@ -48,13 +48,12 @@ func NewStatusManager() *StatusManager { return &StatusManager{} } -func (self *StatusManager) WithWaitingStatus(message string, renderFunc func(), f func(*WaitingStatusHandle)) { +func (self *StatusManager) WithWaitingStatus(message string, renderFunc func(), f func(*WaitingStatusHandle) error) error { handle := &WaitingStatusHandle{statusManager: self, message: message, renderFunc: renderFunc, id: -1} handle.Show() + defer handle.Hide() - f(handle) - - handle.Hide() + return f(handle) } func (self *StatusManager) AddToastStatus(message string, kind types.ToastKind) int { |