From 5e595fe460b6a87943c11d1957aedabea6a22afc Mon Sep 17 00:00:00 2001 From: Dieter Lang Date: Tue, 11 Aug 2026 19:20:58 +0200 Subject: [PATCH] Close assignment window with main window --- internal/gui/app.go | 47 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/internal/gui/app.go b/internal/gui/app.go index 1c8f7d2..bf9470e 100644 --- a/internal/gui/app.go +++ b/internal/gui/app.go @@ -60,6 +60,8 @@ type App struct { errorLabel *widget.Label reconnectButton *widget.Button assignmentButton *widget.Button + + assignmentWindow fyne.Window } // NewApp creates the graphical rs2322tcp client application. @@ -232,6 +234,12 @@ func (a *App) showAssignments() { return } + // Do not create another assignment window when one is already open. + if a.assignmentWindow != nil { + a.assignmentWindow.Show() + return + } + cfg := a.clientApplication.Config() devices := a.clientApplication.Devices() @@ -295,6 +303,19 @@ func (a *App) showAssignments() { "Gerätezuordnung", ) assignmentWindow.Resize(fyne.NewSize(650, 450)) + + // Remember the child window so it can be closed together with + // the main window. + a.assignmentWindow = assignmentWindow + + assignmentWindow.SetOnClosed(func() { + // Only clear the reference if this is still the current + // assignment window. + if a.assignmentWindow == assignmentWindow { + a.assignmentWindow = nil + } + }) + assignmentWindow.SetContent( container.NewBorder( nil, @@ -309,18 +330,40 @@ func (a *App) showAssignments() { container.NewVScroll(content), ), ) + assignmentWindow.Show() } +// closeAssignmentWindow closes the currently open device-assignment window. +// +// This is deliberately kept separate from Close() so that the child window +// can be closed without changing any configuration or technical client +// state. +func (a *App) closeAssignmentWindow() { + if a == nil { + return + } + + if a.assignmentWindow == nil { + return + } + + window := a.assignmentWindow + a.assignmentWindow = nil + window.Close() +} + // Close closes the technical client application. // -// The Runtime and the server connection are closed before the GUI window -// itself is closed. +// Any open child GUI window is closed first. The technical client is then +// shut down. func (a *App) Close() { if a == nil { return } + a.closeAssignmentWindow() + _ = a.clientApplication.Close() }