forked from GUI-for-Cores/GUI.for.SingBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
112 lines (101 loc) · 2.9 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"context"
"embed"
"guiforcores/bridge"
"github.com/google/uuid"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/logger"
"github.com/wailsapp/wails/v2/pkg/menu"
"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"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
//go:embed all:frontend/dist
var assets embed.FS
//go:embed frontend/dist/favicon.ico
var icon []byte
func main() {
bridge.InitBridge(assets)
// Create an instance of the app structure
app := bridge.NewApp()
appMenu := menu.NewMenu()
if bridge.Env.OS == "darwin" {
bridge.AddMenusForDarwin(appMenu, app)
}
trayStart, _ := bridge.InitTray(app, icon)
// Create application with options
err := wails.Run(&options.App{
MinWidth: 600,
MinHeight: 400,
DisableResize: false,
Menu: appMenu,
Title: bridge.Env.AppName,
Frameless: bridge.Env.OS == "windows",
Width: bridge.Config.Width,
Height: bridge.Config.Height,
StartHidden: bridge.Config.StartHidden,
WindowStartState: options.WindowStartState(bridge.Config.WindowStartState),
BackgroundColour: &options.RGBA{R: 255, G: 255, B: 255, A: 1},
Windows: &windows.Options{
WebviewIsTransparent: true,
WindowIsTranslucent: true,
BackdropType: windows.Acrylic,
},
Mac: &mac.Options{
TitleBar: mac.TitleBarHiddenInset(),
Appearance: mac.DefaultAppearance,
WebviewIsTransparent: true,
WindowIsTranslucent: true,
About: &mac.AboutInfo{
Title: bridge.Env.AppName,
Message: "© 2024 GUI.for.Cores",
Icon: icon,
},
},
Linux: &linux.Options{
Icon: icon,
WindowIsTranslucent: false,
ProgramName: bridge.Env.AppName,
WebviewGpuPolicy: linux.WebviewGpuPolicy(bridge.Config.WebviewGpuPolicy),
},
AssetServer: &assetserver.Options{
Assets: assets,
Middleware: bridge.RollingRelease,
},
SingleInstanceLock: &options.SingleInstanceLock{
UniqueId: func() string {
if bridge.Config.MultipleInstance {
return uuid.New().String()
}
return bridge.Env.AppName
}(),
OnSecondInstanceLaunch: func(data options.SecondInstanceData) {
runtime.Show(app.Ctx)
runtime.EventsEmit(app.Ctx, "launchArgs", data.Args)
},
},
OnStartup: func(ctx context.Context) {
runtime.LogSetLogLevel(ctx, logger.INFO)
app.Ctx = ctx
bridge.InitScheduledTasks()
trayStart()
},
OnBeforeClose: func(ctx context.Context) (prevent bool) {
runtime.EventsEmit(ctx, "onBeforeExitApp")
return true
},
Bind: []interface{}{
app,
},
Debug: options.Debug{
OpenInspectorOnStartup: true,
},
})
if err != nil {
println("Error:", err.Error())
}
}