-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
90 lines (77 loc) · 1.93 KB
/
main.go
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
//go:build windows
// Sets up and runs the Wails application.
package main
import (
"context"
"embed"
"os"
"github.com/stnokott/r6-dissect-influx/internal/config"
"github.com/stnokott/r6-dissect-influx/internal/utils"
"github.com/rs/zerolog"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
"github.com/wailsapp/wails/v2/pkg/options/windows"
)
//go:embed all:frontend/dist
var assets embed.FS
// Wails hooks, will be executed in order
// targeted usecase is adding functions to the slices in build-tag-dependent source files
var onStartupFuncs, onDomReadyFuncs, onShutdownFuncs []func(context.Context)
func main() {
// necessary for r6-dissect
zerolog.SetGlobalLevel(zerolog.InfoLevel)
cfg, err := config.Init()
if err != nil {
utils.ErrDialog(err)
os.Exit(-1)
}
app := NewApp(cfg)
onStartupFuncs = append(onStartupFuncs, app.startup)
wailsOptions := &options.App{
Width: 800,
Height: 600,
AssetServer: &assetserver.Options{
Assets: assets,
},
OnStartup: func(ctx context.Context) {
runWailsHooks(ctx, onStartupFuncs)
},
OnDomReady: func(ctx context.Context) {
runWailsHooks(ctx, onDomReadyFuncs)
},
OnShutdown: func(ctx context.Context) {
runWailsHooks(ctx, onShutdownFuncs)
},
Bind: []interface{}{
app,
},
Windows: &windows.Options{
Theme: windows.Dark,
OnSuspend: func() {
if app.roundsWatcherStop != nil {
app.roundsWatcherStop()
}
},
OnResume: func() {
if app.roundsWatcherStop == nil {
if errRoundWatcher := app.StartRoundWatcher(); errRoundWatcher != nil {
utils.ErrDialog(errRoundWatcher)
}
}
},
},
Frameless: true,
}
// Create application with options
err = wails.Run(wailsOptions)
if err != nil {
utils.ErrDialog(err)
os.Exit(-1)
}
}
func runWailsHooks(ctx context.Context, hooks []func(context.Context)) {
for _, h := range hooks {
h(ctx)
}
}