From a03f5505353a21502406c3ded6bd7c4491c2169d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Marku=C5=A1i=C4=87?= Date: Thu, 12 May 2022 14:19:06 +0200 Subject: [PATCH] Refactor pausing a bit --- pkg/gui/containers_panel.go | 18 +++++++++++------- pkg/gui/services_panel.go | 14 +------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/pkg/gui/containers_panel.go b/pkg/gui/containers_panel.go index 961d073c3..c50e19855 100644 --- a/pkg/gui/containers_panel.go +++ b/pkg/gui/containers_panel.go @@ -423,13 +423,8 @@ func (gui *Gui) handleContainersRemoveMenu(g *gocui.Gui, v *gocui.View) error { return gui.createMenu("", options, len(options), handleMenuPress) } -func (gui *Gui) handleContainerPause(g *gocui.Gui, v *gocui.View) error { - container, err := gui.getSelectedContainer() - if err != nil { - return nil - } - - return gui.WithWaitingStatus(gui.Tr.PausingStatus, func() error { +func (gui *Gui) PauseContainer(container *commands.Container) error { + return gui.WithWaitingStatus(gui.Tr.PausingStatus, func() (err error) { if container.Details.State.Paused { err = container.Unpause() } else { @@ -444,6 +439,15 @@ func (gui *Gui) handleContainerPause(g *gocui.Gui, v *gocui.View) error { }) } +func (gui *Gui) handleContainerPause(g *gocui.Gui, v *gocui.View) error { + container, err := gui.getSelectedContainer() + if err != nil { + return nil + } + + return gui.PauseContainer(container) +} + func (gui *Gui) handleContainerStop(g *gocui.Gui, v *gocui.View) error { container, err := gui.getSelectedContainer() if err != nil { diff --git a/pkg/gui/services_panel.go b/pkg/gui/services_panel.go index 57b025397..b308bb936 100644 --- a/pkg/gui/services_panel.go +++ b/pkg/gui/services_panel.go @@ -228,19 +228,7 @@ func (gui *Gui) handleServicePause(g *gocui.Gui, v *gocui.View) error { return nil } - return gui.WithWaitingStatus(gui.Tr.PausingStatus, func() error { - if service.Container.Details.State.Paused { - err = service.Container.Unpause() - } else { - err = service.Container.Pause() - } - - if err != nil { - return gui.createErrorPanel(gui.g, err.Error()) - } - - return gui.refreshContainersAndServices() - }) + return gui.PauseContainer(service.Container) } func (gui *Gui) handleServiceStop(g *gocui.Gui, v *gocui.View) error {