-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathmain.go
More file actions
146 lines (129 loc) · 3.47 KB
/
main.go
File metadata and controls
146 lines (129 loc) · 3.47 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package main
import (
"context"
"embed"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/logger"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
"github.com/wailsapp/wails/v2/pkg/options/linux"
"github.com/wailsapp/wails/v2/pkg/options/mac"
"github.com/wailsapp/wails/v2/pkg/options/windows"
"sniffer/internal/capture"
"sniffer/internal/config"
"sniffer/internal/scheduler"
"sniffer/internal/server"
"sniffer/internal/store"
)
//go:embed all:frontend/dist
var assets embed.FS
//go:embed build/appicon.png
var icon []byte
func main() {
// Load configuration
cfg, err := config.Load("config.yaml")
if err != nil {
log.Printf("Warning: failed to load config: %v, using defaults", err)
cfg = config.Default()
}
// Create store
st, err := store.NewComposite(cfg)
if err != nil {
log.Fatalf("Failed to create store: %v", err)
}
// Get underlying SQLite store for dashboard
sqliteStore := st.GetDB()
// Create dashboard manager
dashboard := server.NewDashboardManager(sqliteStore.GetRawDB())
// Create capture
cap := capture.New(cfg, st)
// Create scheduler
sched := scheduler.New(st, cfg)
// Create app
app := server.NewApp(cfg, cap, sched, st, dashboard)
// Start scheduler in background
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go sched.Run(ctx)
// Handle signals
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
go func() {
<-sigCh
fmt.Println("\nReceived interrupt signal, shutting down...")
cancel()
if cap.IsRunning() {
cap.Stop()
}
st.Close()
os.Exit(0)
}()
// Create Wails application
err = wails.Run(&options.App{
Title: "Network Packet Sniffer",
Width: 1400,
Height: 900,
MinWidth: 1200,
MinHeight: 700,
MaxWidth: 2560,
MaxHeight: 1440,
DisableResize: false,
Fullscreen: false,
Frameless: false,
StartHidden: false,
HideWindowOnClose: false,
BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
AssetServer: &assetserver.Options{
Assets: assets,
},
Menu: nil,
Logger: nil,
LogLevel: logger.DEBUG,
OnStartup: app.Startup,
OnDomReady: nil,
OnBeforeClose: nil,
OnShutdown: app.Shutdown,
WindowStartState: options.Normal,
Bind: []interface{}{
app,
},
Windows: &windows.Options{
WebviewIsTransparent: false,
WindowIsTranslucent: false,
DisableWindowIcon: false,
DisableFramelessWindowDecorations: false,
WebviewUserDataPath: "",
WebviewBrowserPath: "",
Theme: windows.SystemDefault,
},
Mac: &mac.Options{
TitleBar: &mac.TitleBar{
TitlebarAppearsTransparent: true,
HideTitle: false,
HideTitleBar: false,
FullSizeContent: false,
UseToolbar: false,
HideToolbarSeparator: true,
},
Appearance: mac.NSAppearanceNameDarkAqua,
WebviewIsTransparent: true,
WindowIsTranslucent: true,
About: &mac.AboutInfo{
Title: "Network Packet Sniffer",
Message: "A powerful network packet capture and analysis tool built with Wails",
Icon: icon,
},
},
Linux: &linux.Options{
Icon: icon,
},
})
if err != nil {
log.Fatal(err)
}
}