134 lines
3.6 KiB
Go
134 lines
3.6 KiB
Go
/*
|
|
* ============================================================================
|
|
* Projekt.....: rs2322tcp
|
|
* Datei.......: cmd/rs2322tcp-client/main.go
|
|
* Copyright (C) 2026 Dieter Lang
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*
|
|
* Beschreibung:
|
|
* Einstiegspunkt für den grafischen rs2322tcp-Client.
|
|
*
|
|
* Der Client wird als eigenständige Desktop-Anwendung ausgeführt. Die
|
|
* grafische Oberfläche basiert auf Fyne und bildet sowohl die Statusanzeige
|
|
* als auch später die Konfiguration der lokalen virtuellen seriellen
|
|
* Ports ab.
|
|
*
|
|
* Die eigentliche Client- und Runtime-Logik bleibt in den internen
|
|
* Packages gekapselt. Diese Datei ist bewusst auf den Programmstart
|
|
* und die Übergabe an die GUI beschränkt.
|
|
* ============================================================================
|
|
*/
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"fyne.io/fyne/v2"
|
|
"fyne.io/fyne/v2/app"
|
|
"fyne.io/fyne/v2/theme"
|
|
"image/color"
|
|
|
|
"git.lang-dieter.de/rs2322tcp/internal/gui"
|
|
"git.lang-dieter.de/rs2322tcp/internal/version"
|
|
)
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// Application theme
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// applicationTheme keeps the standard Fyne theme and increases the general
|
|
// text size for better readability.
|
|
//
|
|
// All other colors, fonts, icons and dimensions remain unchanged.
|
|
type applicationTheme struct{}
|
|
|
|
// Ensure applicationTheme implements fyne.Theme.
|
|
var _ fyne.Theme = (*applicationTheme)(nil)
|
|
|
|
// Color returns the standard Fyne theme color.
|
|
func (t *applicationTheme) Color(
|
|
name fyne.ThemeColorName,
|
|
variant fyne.ThemeVariant,
|
|
) color.Color {
|
|
return theme.DefaultTheme().Color(name, variant)
|
|
}
|
|
|
|
// Font returns the standard Fyne theme font.
|
|
func (t *applicationTheme) Font(
|
|
style fyne.TextStyle,
|
|
) fyne.Resource {
|
|
return theme.DefaultTheme().Font(style)
|
|
}
|
|
|
|
// Icon returns the standard Fyne theme icon.
|
|
func (t *applicationTheme) Icon(
|
|
name fyne.ThemeIconName,
|
|
) fyne.Resource {
|
|
return theme.DefaultTheme().Icon(name)
|
|
}
|
|
|
|
// Size returns the standard Fyne theme size, except for normal text.
|
|
//
|
|
// Normal text is increased from the Fyne default to 22 px for better
|
|
// readability.
|
|
func (t *applicationTheme) Size(
|
|
name fyne.ThemeSizeName,
|
|
) float32 {
|
|
if name == theme.SizeNameText {
|
|
return 22
|
|
}
|
|
|
|
return theme.DefaultTheme().Size(name)
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// Main
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
func main() {
|
|
fmt.Printf(
|
|
"rs2322tcp-client %s\n",
|
|
version.Version,
|
|
)
|
|
|
|
application := app.NewWithID(
|
|
"git.lang-dieter.de.rs2322tcp.client",
|
|
)
|
|
|
|
// Use the standard Fyne theme with a larger general text size.
|
|
application.Settings().SetTheme(
|
|
&applicationTheme{},
|
|
)
|
|
|
|
guiApplication, err := gui.NewApp(
|
|
application,
|
|
"./configs/client.json",
|
|
)
|
|
if err != nil {
|
|
fmt.Printf(
|
|
"GUI konnte nicht gestartet werden: %v\n",
|
|
err,
|
|
)
|
|
|
|
return
|
|
}
|
|
|
|
// Das technische Client-System wird nach dem Erzeugen des Fensters
|
|
// asynchron gestartet. Dadurch bleibt die GUI auch während des
|
|
// Verbindungsaufbaus sofort sichtbar und bedienbar.
|
|
guiApplication.Start()
|
|
|
|
// SetOnClosed gehört zum Fyne-Fenster, nicht zur Fyne-Anwendung.
|
|
//
|
|
// Beim Schließen des Hauptfensters wird die technische Client-
|
|
// Anwendung beendet. Dadurch werden Runtime, Bridges, virtuelle
|
|
// Ports und die Serververbindung sauber geschlossen.
|
|
guiApplication.Window().SetOnClosed(
|
|
func() {
|
|
guiApplication.Close()
|
|
},
|
|
)
|
|
|
|
// ShowAndRun zeigt das Fenster und startet den Fyne-Eventloop.
|
|
guiApplication.ShowAndRun()
|
|
}
|