-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
85 lines (74 loc) · 2.16 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
package main
import (
"embed"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
"github.com/google/uuid"
"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
var (
AccessToken string
Version = "dev"
BaseURI = "http://freechat.lidong.xin"
app *App
)
func main() {
var ctx = gctx.New()
var title = "XYHELPER 开源免费的AI助理 https://xyhelper.cn version: " + Version
latestVersion, err := GetLatestVersion(ctx)
if err == nil {
if gstr.CompareVersion(latestVersion, Version) > 0 {
title = title + " 有新版本 " + latestVersion + " 请前往 https://xyhelper.cn 下载"
}
}
// Create an instance of the app structure
app = NewApp()
AccessToken = uuid.NewString()
// Create application with options
err = wails.Run(&options.App{
Title: title,
Width: 1050,
Height: 649,
AssetServer: &assetserver.Options{
Assets: assets,
Handler: NewAssetHandler(),
},
BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
OnStartup: app.startup,
Bind: []interface{}{
app,
},
OnDomReady: app.DomReady,
})
if err != nil {
println("Error:", err.Error())
}
g.Log().Info(gctx.New(), "XYHELPER 开源免费的AI助理 https://xyhelper.cn version: "+Version)
}
func GetLatestVersion(ctx g.Ctx) (lasterVersion string, err error) {
httpClient := g.Client()
httpProxyAddr, err := g.Cfg().Get(ctx, "httpProxyAddr")
if err == nil && httpProxyAddr.String() != "" {
g.Log().Info(ctx, "httpProxyAddr", httpProxyAddr.String())
httpClient.SetProxy(httpProxyAddr.String())
}
r, err := httpClient.Get(ctx, "https://xyhelper.cn/version.txt?time="+gconv.String(gtime.Timestamp()), nil)
if err != nil {
g.Log().Error(ctx, "GetLatestVersion", err.Error())
return
}
if r.StatusCode != 200 {
g.Log().Error(ctx, "GetLatestVersion", "StatusCode!=200")
return "", gerror.New("StatusCode!=200")
}
lasterVersion = gstr.Trim(r.ReadAllString())
return
}