Skip to content

Commit 99c36c2

Browse files
committed
config 导入
bug修复
1 parent 156fef5 commit 99c36c2

File tree

7 files changed

+51
-19
lines changed

7 files changed

+51
-19
lines changed

app.go

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (a *App) systemTray() {
5656

5757
func (a *App) testPing() {
5858
a.PingAll()
59-
tick := time.Tick(time.Second * 60)
59+
tick := time.Tick(time.Second * 5)
6060
for range tick {
6161
a.PingAll()
6262
}
@@ -86,18 +86,17 @@ func (a *App) startup(ctx context.Context) {
8686
rdata, err2 := httpGet("https://mirror.ghproxy.com/https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db.sha256sum")
8787
if err2 == nil {
8888
sum256 := sha256.Sum256(file)
89-
fmt.Println(fmt.Sprintf("%x", sum256), string(rdata))
9089
if fmt.Sprintf("%x", sum256) != string(rdata) {
9190
rdata, err2 = httpGet("https://mirror.ghproxy.com/https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db")
9291
if err2 == nil {
93-
_ = os.WriteFile(geoPath, rdata, 0644)
92+
_ = os.WriteFile(geoPath, rdata, 0o644)
9493
}
9594
}
9695
}
9796
} else {
9897
rdata, err2 := httpGet("https://mirror.ghproxy.com/https://github.com/SagerNet/sing-geoip/releases/latest/download/geoip.db")
9998
if err2 == nil {
100-
_ = os.WriteFile(geoPath, rdata, 0644)
99+
_ = os.WriteFile(geoPath, rdata, 0o644)
101100
}
102101
}
103102
geoPath = fmt.Sprintf("%s%c%s%c%s", home, os.PathSeparator, ".gpp", os.PathSeparator, "geosite.db")
@@ -106,24 +105,26 @@ func (a *App) startup(ctx context.Context) {
106105
rdata, err2 := httpGet("https://mirror.ghproxy.com/https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db.sha256sum")
107106
if err2 == nil {
108107
sum256 := sha256.Sum256(file)
109-
fmt.Println(fmt.Sprintf("%x", sum256), string(rdata))
110108
if fmt.Sprintf("%x", sum256) != string(rdata) {
111109
rdata, err2 = httpGet("https://mirror.ghproxy.com/https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db")
112110
if err2 == nil {
113-
_ = os.WriteFile(geoPath, rdata, 0644)
111+
_ = os.WriteFile(geoPath, rdata, 0o644)
114112
}
115113
}
116114
}
117115
} else {
118116
rdata, err2 := httpGet("https://mirror.ghproxy.com/https://github.com/SagerNet/sing-geosite/releases/latest/download/geosite.db")
119117
if err2 == nil {
120-
_ = os.WriteFile(geoPath, rdata, 0644)
118+
_ = os.WriteFile(geoPath, rdata, 0o644)
121119
}
122120
}
123121
}
124122
func (a *App) PingAll() {
125123
group := sync.WaitGroup{}
126124
for i := range a.conf.PeerList {
125+
if a.conf.PeerList[i].Protocol == "direct" {
126+
continue
127+
}
127128
group.Add(1)
128129
peer := a.conf.PeerList[i]
129130
go func() {
@@ -160,16 +161,31 @@ func (a *App) Add(token string) string {
160161
}
161162
err, peer := config.ParsePeer(token)
162163
if err != nil {
164+
_, _ = runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
165+
Type: runtime.ErrorDialog,
166+
Title: "导入错误",
167+
Message: err.Error(),
168+
})
163169
return err.Error()
164170
}
165171
for _, p := range a.conf.PeerList {
166172
if p.Name == peer.Name {
173+
_, _ = runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
174+
Type: runtime.ErrorDialog,
175+
Title: "导入错误",
176+
Message: fmt.Sprintf("节点 %s 已存在", peer.Name),
177+
})
167178
return fmt.Sprintf("peer %s already exists", peer.Name)
168179
}
169180
}
170181
a.conf.PeerList = append(a.conf.PeerList, peer)
171182
err = config.SaveConfig(a.conf)
172183
if err != nil {
184+
_, _ = runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
185+
Type: runtime.ErrorDialog,
186+
Title: "导入错误",
187+
Message: err.Error(),
188+
})
173189
return err.Error()
174190
}
175191
return "ok"
@@ -211,10 +227,20 @@ func (a *App) Start() string {
211227
var err error
212228
a.box, err = client.Client(a.gamePeer, a.httpPeer, a.processList)
213229
if err != nil {
230+
_, _ = runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
231+
Type: runtime.ErrorDialog,
232+
Title: "加速失败",
233+
Message: err.Error(),
234+
})
214235
return err.Error()
215236
}
216237
err = a.box.Start()
217238
if err != nil {
239+
_, _ = runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
240+
Type: runtime.ErrorDialog,
241+
Title: "加速失败",
242+
Message: err.Error(),
243+
})
218244
return err.Error()
219245
}
220246
return "ok"
@@ -227,6 +253,11 @@ func (a *App) Stop() string {
227253
}
228254
err := a.box.Close()
229255
if err != nil {
256+
_, _ = runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
257+
Type: runtime.ErrorDialog,
258+
Title: "停止失败",
259+
Message: err.Error(),
260+
})
230261
return err.Error()
231262
}
232263
a.box = nil

backend/config/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ func InitConfig() {
3434
if err != nil {
3535
_path = fmt.Sprintf("%s%c%s%c%s", home, os.PathSeparator, ".gpp", os.PathSeparator, "config.json")
3636
}
37-
_ = os.MkdirAll(filepath.Dir(_path), os.ModeDir|os.ModePerm)
37+
_ = os.MkdirAll(filepath.Dir(_path), 0o755)
3838
_, err = os.Stat(_path)
3939
if err != nil {
4040
file, _ := json.Marshal(Config{PeerList: make([]*Peer, 0)})
41-
err = os.WriteFile(_path, file, os.ModePerm)
41+
err = os.WriteFile(_path, file, 0o644)
4242
}
4343
}
4444
func LoadConfig() (*Config, error) {
@@ -76,7 +76,7 @@ func SaveConfig(config *Config) error {
7676
_path = fmt.Sprintf("%s%c%s%c%s", home, os.PathSeparator, ".gpp", os.PathSeparator, "config.json")
7777
}
7878
file, _ := json.Marshal(config)
79-
return os.WriteFile(_path, file, os.ModePerm)
79+
return os.WriteFile(_path, file, 0o644)
8080
}
8181
func ParsePeer(token string) (error, *Peer) {
8282
split := strings.Split(token, "#")
@@ -93,7 +93,7 @@ func ParsePeer(token string) (error, *Peer) {
9393
split = strings.Split(token, "@")
9494
protocol := strings.ReplaceAll(split[0], "gpp://", "")
9595
switch protocol {
96-
case "vless", "shadowsocks", "socks":
96+
case "vless", "shadowsocks", "socks", "hysteria2":
9797
default:
9898
return fmt.Errorf("unknown protocol: %s", protocol), nil
9999
}

frontend/src/views/Index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
</n-button>
5252
</n-space>
5353
<n-gradient-text type="success" style="margin-left: 130px;margin-top: 35px">
54-
v1.2.8
54+
v1.3.0
5555
</n-gradient-text>
5656
</n-space>
5757
<div>

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,4 @@ require (
105105
google.golang.org/grpc v1.65.0 // indirect
106106
google.golang.org/protobuf v1.34.2 // indirect
107107
lukechampine.com/blake3 v1.3.0 // indirect
108-
)
108+
)

server/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

server/build.sh

Lines changed: 0 additions & 1 deletion
This file was deleted.

server/install.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ echo "请选择一个选项:"
1313
echo "1) shadowsocks"
1414
echo "2) socks"
1515
echo "3) vless"
16+
echo "4) hysteria2"
1617
read -p "输入选项 (1-3): " input
1718
PROTOCOL="vless"
1819
case $input in
@@ -25,6 +26,9 @@ case $input in
2526
3)
2627
PROTOCOL="vless"
2728
;;
29+
4)
30+
PROTOCOL="hysteria2"
31+
;;
2832
*)
2933
echo "无效选项: $input"
3034
exit 0
@@ -89,13 +93,13 @@ if [ "\$1" = "start" ]; then
8993
echo "Starting gpp"
9094
nohup ${INSTALL_PATH}/gpp > "\$log_file" 2>&1 &
9195
echo \$! > "\$pid_file"
92-
echo "stm started with pid \$!"
96+
echo "gpp started with pid \$!"
9397
exit 0
9498
fi
9599
elif [ "\$1" = "stop" ]; then
96100
if [ -f "\$pid_file" ]; then
97101
pid=\$(cat "\$pid_file")
98-
echo "Stopping stm with pid \$pid"
102+
echo "Stopping gpp with pid \$pid"
99103
kill "\$pid"
100104
rm "\$pid_file"
101105
exit 0
@@ -112,7 +116,6 @@ EOF
112116
chmod +x run.sh
113117

114118
echo "安装完成,请执行 ${INSTALL_PATH}/run.sh start 启动服务端,执行 ${INSTALL_PATH}/run.sh stop 停止服务端"
115-
#fmt.Sprintf("gpp://%s@%s:%d/%s", config.Protocol, ipStr, config.Port, config.UUID
116119
result="gpp://$PROTOCOL@$NET_IP:$LISTEN_PORT/$UUID"
117120
encoded_result=$(echo -n $result | base64)
118-
echo "导入Token${encoded_result}"
121+
echo "导入链接${encoded_result}"

0 commit comments

Comments
 (0)