-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp.go
154 lines (133 loc) · 2.91 KB
/
app.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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package main
import (
"bytes"
"context"
"encoding/base64"
"github.com/qtgolang/SunnyNet/SunnyNet"
"github.com/qtgolang/SunnyNet/public"
"github.com/wailsapp/wails/v2/pkg/runtime"
_ "github.com/wailsapp/wails/v2/pkg/runtime"
"io"
"io/ioutil"
_ "log"
"os"
"path/filepath"
)
type App struct {
ctx context.Context
}
type Result struct {
Code int
Msg string
}
type AppInfo struct {
Version string
}
var (
AppInfoData = AppInfo{
Version: "4.0.0",
}
)
type FileInfo struct {
Name string
Source string
}
func NewApp() *App {
return &App{}
}
func (a *App) startup(ctx context.Context) {
// Perform your setup here
a.ctx = ctx
}
var ctxContent context.Context = nil
func (a App) domReady(ctx context.Context) {
ctxContent = ctx
runtime.EventsEmit(ctx, "AppInfo", AppInfoData)
}
func (a *App) shutdown(ctx context.Context) {
// Perform your teardown here
}
func (a *App) StartSunnyCore(port int) Result {
s := SunnyNet.NewSunny()
s.SetGoCallback(HttpCallback, nil, nil, nil)
s = s.SetPort(port).Start()
// 开启随机TLS指纹
s.SetRandomTLS(true)
// 安装证书
s.InstallCert()
s.SetIeProxy(false)
err := s.Error
if err != nil {
return Result{
Code: -1,
Msg: err.Error(),
}
}
return Result{
Code: 0,
Msg: "success",
}
}
func (a *App) StopSunnyCore() Result {
s := SunnyNet.NewSunny()
err := s.Error
if err != nil {
return Result{
Code: -1,
Msg: err.Error(),
}
}
s.SetIeProxy(true)
s.Close()
return Result{
Code: 0,
Msg: "success",
}
}
func HttpCallback(Conn *SunnyNet.HttpConn) {
URL := Conn.Request.URL.String()
urlEquals := URL == "https://wxmini.jj5agame.com/p.f"
if Conn.Type == public.HttpResponseOK && urlEquals {
if Conn.Response.Body != nil {
Body, _ := io.ReadAll(Conn.Response.Body)
_ = Conn.Response.Body.Close()
// 将body进行base64编码
bs64Body := base64.StdEncoding.EncodeToString(Body)
Conn.Response.Body = io.NopCloser(bytes.NewBuffer(Body))
runtime.EventsEmit(ctxContent, "SunnyCallback", bs64Body)
}
}
}
// ReadFileToBase64 /**
func (a *App) ReadFileToBase64(filePath string) (string, error) {
fileBytes, err := os.ReadFile(filePath)
if err != nil {
return "", err
}
encodedString := base64.StdEncoding.EncodeToString(fileBytes)
return encodedString, nil
}
// GetJSFiles returns all .js files in the 'scripts' directory.
func (a *App) GetJSFiles() ([]FileInfo, error) {
dir, err := os.Getwd()
if err != nil {
return nil, err
}
scriptsPath := filepath.Join(dir, "scripts")
files, err := ioutil.ReadDir(scriptsPath)
if err != nil {
return nil, err
}
var jsFiles []FileInfo
for _, file := range files {
if !file.IsDir() && filepath.Ext(file.Name()) == ".js" {
filePath := filepath.Join(scriptsPath, file.Name())
content, err := ioutil.ReadFile(filePath)
if err != nil {
return nil, err
}
jsFiles = append(jsFiles, FileInfo{Name: file.Name(), Source: string(content)})
}
}
return jsFiles, nil
}