-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
91 lines (82 loc) · 1.97 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
package main
import (
"context"
"driver-box/pkg/execute"
"driver-box/pkg/store"
"driver-box/pkg/sysinfo"
"embed"
"os"
"path/filepath"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
)
//go:embed all:frontend/dist
var assets embed.FS
func main() {
// setup /conf directorys
var dirConf string
if exePath, err := os.Executable(); err != nil {
panic(err)
} else {
dirConf = filepath.Join(filepath.Dir(exePath), "conf")
if _, err := os.Stat(dirConf); err != nil {
if err := os.MkdirAll(dirConf, os.ModePerm); err != nil {
panic(err)
}
}
dirDir := filepath.Join(filepath.Dir(exePath), "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)
}
}
app := &App{}
mgt := &execute.CommandExecutor{}
err := wails.Run(&options.App{
Title: "driver-box",
Width: 768,
Height: 576,
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.DriverManager{Path: filepath.Join(dirConf, "drivers.json")},
&store.AppSettingManager{Path: filepath.Join(dirConf, "setting.json")},
&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"},
},
},
})
if err != nil {
println("Error:", err.Error())
}
}