-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_core.go
More file actions
109 lines (90 loc) · 3.17 KB
/
Copy pathapp_core.go
File metadata and controls
109 lines (90 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"context"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
// Version information - injected at build time via ldflags
// Use: go build -ldflags "-X main.Version=1.4.2"
var Version = "dev"
// ================================================================================
// APP CORE - Main application struct with lifecycle management
// Follows Single Responsibility Principle: handles only app lifecycle and metadata
// ================================================================================
// App struct is the main application controller
// It manages lifecycle hooks and coordinates between services
type App struct {
ctx context.Context
// Service references for coordination
connectionService *ConnectionService
syslogService *SyslogService
stressTestService *StressTestService
}
// NewApp creates a new App instance
func NewApp() *App {
return &App{}
}
// SetServices injects service dependencies (called from main.go)
func (a *App) SetServices(conn *ConnectionService, syslog *SyslogService, stress *StressTestService) {
a.connectionService = conn
a.syslogService = syslog
a.stressTestService = stress
}
// startup is called at application startup
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
// domReady is called after front-end resources have been loaded
func (a *App) domReady(ctx context.Context) {
// Center the window on the screen
runtime.WindowCenter(a.ctx)
}
// beforeClose is called when the application is about to quit
func (a *App) beforeClose(ctx context.Context) (prevent bool) {
// Check if connection service has active connection
if a.connectionService != nil && a.connectionService.IsConnected() {
result, err := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.QuestionDialog,
Title: "Confirm Exit",
Message: "There is an active connection. Are you sure you want to exit?",
Buttons: []string{"Yes", "No"},
DefaultButton: "No",
CancelButton: "No",
})
if err != nil || result != "Yes" {
return true // Prevent close
}
}
// Clean up connections
if a.connectionService != nil {
a.connectionService.Disconnect()
}
// Stop stress test if running
if a.stressTestService != nil {
a.stressTestService.StopContinuousSend()
}
return false
}
// shutdown is called at application termination
func (a *App) shutdown(ctx context.Context) {
// Ensure all connections are closed
if a.connectionService != nil {
a.connectionService.Disconnect()
}
}
// ================================================================================
// APP METADATA API
// ================================================================================
// GetVersion returns the application version
// The version is injected at build time via ldflags
func (a *App) GetVersion() string {
return Version
}
// OpenURL opens a URL in the default system browser
func (a *App) OpenURL(url string) {
runtime.BrowserOpenURL(a.ctx, url)
runtime.LogDebug(a.ctx, "Opened URL in browser: "+url)
}
// OpenGitHub opens the project's GitHub repository in the default browser
func (a *App) OpenGitHub() {
runtime.BrowserOpenURL(a.ctx, "https://github.com/yllada/Send-Log-TCP")
}