-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
81 lines (68 loc) · 1.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
package main
import (
"embed"
"fmt"
"github.com/rainu/ask-mai/config"
"github.com/rainu/ask-mai/controller"
"github.com/wailsapp/wails/v2"
"log/slog"
"os"
"runtime"
"slices"
"strings"
)
//go:embed frontend/dist
var assets embed.FS
//go:embed build/appicon.png
var icon []byte
// this variable will be set correctly in built-time
var windowMode = "true"
func init() {
if runtime.GOOS == "windows" && windowMode == "true" {
// in windows there is no stdout and stderr in window-mode
// so we need to redirect the log output to a file
os.Stdout, _ = os.OpenFile("ask-mai.out.txt", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660)
os.Stderr, _ = os.OpenFile("ask-mai.err.txt", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660)
}
}
// this function will be set by debug.go:init() - if "debug" flag is available
var onStartUp func(c *config.Config)
func main() {
buildMode := slices.ContainsFunc(os.Environ(), func(s string) bool {
return strings.HasPrefix(s, "tsprefix=")
})
cfg := config.Parse(os.Args[1:], os.Environ())
if cfg.Debug.PrintVersion {
fmt.Fprintln(os.Stderr, versionLine())
os.Exit(0)
return
}
if !buildMode {
if err := cfg.Validate(); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
return
}
slog.SetLogLoggerLevel(slog.Level(cfg.Debug.LogLevel))
if onStartUp != nil {
onStartUp(cfg)
}
}
ctrl, err := controller.BuildFromConfig(cfg)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(2)
return
}
// Create application with options
if cfg.Debug.WebKit.HttpServerAddress != "" {
// the underlying webview library will use this environment variable to start the inspector server
os.Setenv("WEBKIT_INSPECTOR_HTTP_SERVER", cfg.Debug.WebKit.HttpServerAddress)
}
err = wails.Run(controller.GetOptions(ctrl, icon, assets))
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(3)
return
}
}