From 08e9b05d5199f913e5ffd105e3f99a2565983a96 Mon Sep 17 00:00:00 2001 From: Maycon Santos Date: Sun, 22 Jun 2025 10:33:04 +0200 Subject: [PATCH] [client] close windows when process needs to exit (#4027) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR fixes a bug by ensuring that the advanced settings and re-authentication windows are closed appropriately when the main GUI process exits. - Updated runSelfCommand calls throughout the UI to pass a context parameter. - Modified runSelfCommand’s signature and its internal command invocation to use exec.CommandContext for proper cancellation handling. --- client/ui/client_ui.go | 2 +- client/ui/event_handler.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client/ui/client_ui.go b/client/ui/client_ui.go index db53bc4eb..2b74c31d1 100644 --- a/client/ui/client_ui.go +++ b/client/ui/client_ui.go @@ -879,7 +879,7 @@ func (s *serviceClient) onUpdateAvailable() { func (s *serviceClient) onSessionExpire() { s.sendNotification = true if s.sendNotification { - s.eventHandler.runSelfCommand("login-url", "true") + s.eventHandler.runSelfCommand(s.ctx, "login-url", "true") s.sendNotification = false } } diff --git a/client/ui/event_handler.go b/client/ui/event_handler.go index 5441f3481..39ea3867c 100644 --- a/client/ui/event_handler.go +++ b/client/ui/event_handler.go @@ -122,7 +122,7 @@ func (h *eventHandler) handleAdvancedSettingsClick() { go func() { defer h.client.mAdvancedSettings.Enable() defer h.client.getSrvConfig() - h.runSelfCommand("settings", "true") + h.runSelfCommand(h.client.ctx, "settings", "true") }() } @@ -130,7 +130,7 @@ func (h *eventHandler) handleCreateDebugBundleClick() { h.client.mCreateDebugBundle.Disable() go func() { defer h.client.mCreateDebugBundle.Enable() - h.runSelfCommand("debug", "true") + h.runSelfCommand(h.client.ctx, "debug", "true") }() } @@ -154,7 +154,7 @@ func (h *eventHandler) handleNetworksClick() { h.client.mNetworks.Disable() go func() { defer h.client.mNetworks.Enable() - h.runSelfCommand("networks", "true") + h.runSelfCommand(h.client.ctx, "networks", "true") }() } @@ -172,14 +172,14 @@ func (h *eventHandler) updateConfigWithErr() { } } -func (h *eventHandler) runSelfCommand(command, arg string) { +func (h *eventHandler) runSelfCommand(ctx context.Context, command, arg string) { proc, err := os.Executable() if err != nil { log.Errorf("error getting executable path: %v", err) return } - cmd := exec.Command(proc, + cmd := exec.CommandContext(ctx, proc, fmt.Sprintf("--%s=%s", command, arg), fmt.Sprintf("--daemon-addr=%s", h.client.addr), )