-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
119 lines (99 loc) · 2.64 KB
/
Copy pathmain.go
File metadata and controls
119 lines (99 loc) · 2.64 KB
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
package main
import (
"embed"
"encoding/json"
"io/ioutil"
"log"
"os"
"os/user"
"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
type BirchConfig struct {
// Explicitly setting the JSON key is required for Wails
// to add this struct to the TypeScript definition file
MinecraftDirectory string `json:"MinecraftDirectory"`
IgnoreOldLogs bool `json:"IgnoreOldLogs"`
SkipUpdateCheck bool `json:"SkipUpdateCheck"`
// Deprecated: This was replaced with BSS files stored in
// $birchConfigDir/searches/
SavedSearchQueries map[string]string `json:"SavedSearchQueries,omitempty"`
DefaultSearch string `json:"DefaultSearch"`
}
var config BirchConfig
var latestLogFile string
var userAppdataDir string
var birchConfigDir string
func ui(app *App) {
err := wails.Run(&options.App{
Title: "Birch",
AssetServer: &assetserver.Options{
Assets: assets,
},
Windows: &windows.Options{
WebviewUserDataPath: birchConfigDir + "\\wv2",
},
EnableDefaultContextMenu: true,
BackgroundColour: &options.RGBA{R: 0x33, G: 0x33, B: 0x33, A: 1},
OnStartup: app.startup,
OnDomReady: app.ready,
Bind: []interface{}{
app,
},
})
if err != nil {
println("Error:", err.Error())
}
}
func exists(file string) bool {
if _, err := os.Stat(file); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}
func SaveConfig() {
file, _ := json.MarshalIndent(config, "", " ")
ioutil.WriteFile(birchConfigDir + sep() + "config.json", file, os.ModePerm)
}
func main() {
config = BirchConfig{}
user, userErr := user.Current()
if userErr != nil {
log.Fatalf(userErr.Error())
}
userHomeDir := user.HomeDir
if userHomeDir == "" {
log.Fatalf("Failed to get user's home directory")
}
userAppdataDir = getAppDataDir(userHomeDir)
birchConfigDir = getConfigDir(userHomeDir)
if !exists(birchConfigDir) {
os.MkdirAll(birchConfigDir, os.ModePerm)
}
if !exists(birchConfigDir + sep() + "config.json") {
minecraftDir := getMinecraftDir(userHomeDir)
config.MinecraftDirectory = minecraftDir
SaveConfig()
} else {
configFile, err := ioutil.ReadFile(birchConfigDir + sep() + "config.json")
if err != nil {
log.Fatal(err.Error())
}
err = json.Unmarshal(configFile, &config)
if err != nil {
log.Fatal(err.Error())
}
if (config.SavedSearchQueries == nil) {
config.SavedSearchQueries = make(map[string]string)
}
}
latestLogFile = config.MinecraftDirectory + sep() + "logs" + sep() + "latest.log"
app := NewApp()
ui(app)
}