-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
87 lines (76 loc) · 1.91 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
package main
import (
"embed"
"fmt"
app "github.com/mikumifa/BiliShareMall/internal/app"
. "github.com/mikumifa/BiliShareMall/internal/domain"
. "github.com/mikumifa/BiliShareMall/internal/util"
"github.com/rs/zerolog/log"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
"os"
"os/user"
"path/filepath"
"strings"
)
//go:embed all:frontend/dist
var assets embed.FS
func InitEnv() {
exePath, err := os.Executable()
if err != nil {
log.Error().Err(err).Msg("Init")
return
}
for _, v := range os.Args {
if v == "tasksch" {
Env.FromTaskSch = true
break
}
}
Env.BasePath = filepath.Dir(exePath)
Env.AppName = strings.TrimSuffix(filepath.Base(exePath), filepath.Ext(exePath))
// step2: Create a persistent data symlink
if Env.OS == "darwin" {
user, _ := user.Current()
linkPath := Env.BasePath + "/data"
appPath := "/Users/" + user.Username + "/Library/Application Support/" + Env.AppName
os.MkdirAll(appPath, os.ModePerm)
os.Symlink(appPath, linkPath)
} else if Env.OS == "windows" {
user, _ := user.Current()
appPath := fmt.Sprintf("%s\\AppData\\Local\\%s", user.HomeDir, Env.AppName)
linkPath := Env.BasePath + "\\data"
os.MkdirAll(appPath, os.ModePerm)
os.Symlink(appPath, linkPath)
} else {
log.Panic().Err(err).Msg("System not support")
panic("System not support")
}
}
func main() {
// Create an instance of the newApp structure
InitEnv()
newApp := app.NewApp()
log.Info().Msg("Creating newApp")
err := FileLogger()
if err != nil {
log.Panic()
}
err = wails.Run(&options.App{
Title: "BiliShareMall",
Width: 1024,
Height: 768,
AssetServer: &assetserver.Options{
Assets: assets,
},
BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
OnStartup: newApp.Startup,
Bind: []interface{}{
newApp,
},
})
if err != nil {
println("Error:", err.Error())
}
}