-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
130 lines (117 loc) · 2.86 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package main
import (
"context"
"driver-box/pkg/execute"
"driver-box/pkg/porter"
"driver-box/pkg/store"
"driver-box/pkg/sysinfo"
"embed"
"os"
"path/filepath"
"github.com/Masterminds/semver"
"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
var (
dirRoot string
// Path to the configuration directory
dirConf string
// Path to the driver directory
dirDir string
// Path to the WebView2 executable
pathWV2 string
// Type of the build version number
buildVersion string
// Version struct, parsed from [buildVersion]
version *semver.Version
)
func init() {
if buildVersion == "" {
version, _ = semver.NewVersion("0.0.0")
} else if v, err := semver.NewVersion(buildVersion); err != nil {
panic(err)
} else {
version = v
}
if pathExe, err := os.Executable(); err != nil {
panic(err)
} else {
dirRoot = filepath.Dir(pathExe)
dirConf = filepath.Join(dirRoot, "conf")
if _, err := os.Stat(dirConf); err != nil {
if err := os.MkdirAll(dirConf, os.ModePerm); err != nil {
panic(err)
}
}
dirDir = filepath.Join(dirRoot, "drivers")
if _, err := os.Stat(dirDir); err != nil {
if err := os.MkdirAll(dirDir, os.ModePerm); err != nil {
panic(err)
}
}
for _, name := range [3]string{"network", "display", "miscellaneous"} {
os.MkdirAll(filepath.Join(dirDir, name), os.ModePerm)
}
// WebView2 binary lookup
pathWV2 = filepath.Join(dirRoot, "bin", "WebView2")
if _, err := os.Stat(pathWV2); err != nil {
pathWV2 = ""
}
}
}
func main() {
app := &App{}
mgt := &execute.CommandExecutor{}
err := wails.Run(&options.App{
Title: "driver-box",
Width: 768,
Height: 576,
MinWidth: 640,
MinHeight: 480,
AssetServer: &assetserver.Options{
Assets: assets,
},
BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
OnStartup: func(ctx context.Context) {
app.SetContext(ctx)
mgt.SetContext(ctx)
},
Bind: []interface{}{
app,
mgt,
&store.DriverGroupManager{Path: filepath.Join(dirConf, "groups.json")},
&store.AppSettingManager{Path: filepath.Join(dirConf, "setting.json")},
&porter.Porter{DirRoot: dirRoot, DirConf: dirConf, DirDriver: dirDir},
&sysinfo.SysInfo{},
},
EnumBind: []interface{}{
[]struct {
Value store.DriverType
TSName string
}{
{store.Network, "NETWORK"},
{store.Display, "DISPLAY"},
{store.Miscellaneous, "MISCELLANEOUS"},
},
[]struct {
Value store.SuccessAction
TSName string
}{
{store.Nothing, "NOTHING"},
{store.Reboot, "REBOOT"},
{store.Shutdown, "SHUTDOWN"},
{store.Firmware, "FIRMWARE"},
},
},
Windows: &windows.Options{
WebviewBrowserPath: pathWV2,
},
})
if err != nil {
println("Error:", err.Error())
}
}