-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathmain.go
116 lines (109 loc) · 2.95 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
113
114
115
116
package main
import (
"context"
"embed"
"fmt"
"runtime"
"transok/backend/app"
"transok/backend/services"
"transok/backend/utils/logger"
"transok/backend/utils/mdns"
mdns_handlers "transok/backend/utils/mdns/handlers"
"github.com/wailsapp/wails/v2"
"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"
)
//go:embed all:frontend/dist
var assets embed.FS
//go:embed build/appicon.png
var icon []byte
func main() {
sysSvc := services.System()
fileSvc := services.File()
discoverSvc := services.GetDiscoverService()
shareSvc := services.Share()
storageSvc := services.Storage()
ginSvc := app.Gin()
logger.InitLogger()
appInfo := sysSvc.GetAppInfo()
windowStartState := options.Normal
// menu
isMacOS := runtime.GOOS == "darwin"
appMenu := menu.NewMenu()
if isMacOS {
appMenu.Append(menu.AppMenu())
appMenu.Append(menu.EditMenu())
appMenu.Append(menu.WindowMenu())
}
err := wails.Run(&options.App{
Title: appInfo["name"],
Width: 380,
Height: 620,
MinWidth: 380,
MinHeight: 620,
MaxWidth: 380,
MaxHeight: 620,
WindowStartState: windowStartState,
Menu: appMenu,
EnableDefaultContextMenu: true,
DragAndDrop: &options.DragAndDrop{
EnableFileDrop: true,
DisableWebViewDrop: true,
},
Debug: options.Debug{
OpenInspectorOnStartup: false,
},
AssetServer: &assetserver.Options{
Assets: assets,
},
BackgroundColour: options.NewRGBA(0, 0, 0, 0),
StartHidden: true,
OnStartup: func(ctx context.Context) {
sysSvc.Start(ctx, appInfo["version"])
fileSvc.Start(ctx)
storageSvc.Init(ctx)
discoverSvc.Start()
shareSvc.Start(ctx)
/* 订阅mdns消息 */
mdns.GetDispatcher().Subscribe(mdns_handlers.GetDiscoverHandler())
mdns.GetDispatcher().Subscribe(mdns_handlers.NewPingHandler())
},
Bind: []interface{}{
sysSvc,
fileSvc,
storageSvc,
ginSvc,
shareSvc,
discoverSvc,
mdns_handlers.GetDiscoverHandler(),
},
Mac: &mac.Options{
About: &mac.AboutInfo{
Title: fmt.Sprintf("%s %s", appInfo["name"], appInfo["version"]),
Message: appInfo["desc"],
Icon: icon,
},
TitleBar: mac.TitleBarHiddenInset(),
WebviewIsTransparent: false,
WindowIsTranslucent: false,
},
Windows: &windows.Options{
WebviewIsTransparent: false,
WindowIsTranslucent: false,
DisableFramelessWindowDecorations: false,
},
Linux: &linux.Options{
ProgramName: appInfo["name"],
Icon: icon,
WebviewGpuPolicy: linux.WebviewGpuPolicyOnDemand,
WindowIsTranslucent: true,
},
})
if err != nil {
println("Error:", err.Error())
}
}