-
-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathapp_window.go
More file actions
326 lines (294 loc) · 8.85 KB
/
app_window.go
File metadata and controls
326 lines (294 loc) · 8.85 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
package main
import (
"context"
"fmt"
"path/filepath"
"github.com/chromedp/chromedp"
"github.com/wailsapp/wails/v3/pkg/application"
"github.com/wailsapp/wails/v3/pkg/events"
"github.com/yhy0/ChYing/conf/file"
"github.com/yhy0/ChYing/lib/webUnPack"
"github.com/yhy0/logging"
)
/**
@author yhy
@since 2024/7/12
@desc 窗口管理相关方法
**/
var (
scanWindow *application.WebviewWindow
vulnWindow *application.WebviewWindow
claudeWindow *application.WebviewWindow
pluginWindows = make(map[string]*application.WebviewWindow)
browserCancel context.CancelFunc
)
// NewScanLogWindow 创建扫描日志窗口
func (a *App) NewScanLogWindow() {
// 如果窗口存在且未被销毁,聚焦它
if scanWindow != nil {
scanWindow.Show()
scanWindow.Focus()
return
}
scanWindow = wailsApp.Window.NewWithOptions(application.WebviewWindowOptions{
Name: "Scan Log",
Title: "扫描日志",
DevToolsEnabled: true, // 启用 DevTools (F12)
Mac: application.MacWindow{
Backdrop: application.MacBackdropLiquidGlass,
InvisibleTitleBarHeight: 25, // 只让顶部 25px 可拖拽,避免影响文字选择
LiquidGlass: application.MacLiquidGlass{
Style: application.LiquidGlassStyleLight,
Material: application.NSVisualEffectMaterialAuto,
CornerRadius: 20.0,
TintColor: nil,
},
},
Width: 1200,
Height: 900,
URL: "/#/scanLog",
EnableFileDrop: true,
})
// 注册窗口关闭事件
scanWindow.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
scanWindow = nil // 清空引用
})
scanWindow.Show()
}
// NewVulnerabilityWindow 创建漏洞窗口
func (a *App) NewVulnerabilityWindow() {
// 如果窗口存在且未被销毁,聚焦它
if vulnWindow != nil {
vulnWindow.Show()
vulnWindow.Focus()
return
}
vulnWindow = wailsApp.Window.NewWithOptions(application.WebviewWindowOptions{
Name: "Vulnerability",
Title: "漏洞列表",
DevToolsEnabled: true, // 启用 DevTools (F12)
Mac: application.MacWindow{
Backdrop: application.MacBackdropLiquidGlass,
InvisibleTitleBarHeight: 25, // 只让顶部 25px 可拖拽,避免影响文字选择
LiquidGlass: application.MacLiquidGlass{
Style: application.LiquidGlassStyleLight,
Material: application.NSVisualEffectMaterialAuto,
CornerRadius: 20.0,
TintColor: nil,
},
},
Width: 1200,
Height: 900,
URL: "/#/vulnerability",
})
// 注册窗口关闭事件
vulnWindow.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
vulnWindow = nil // 清空引用
})
vulnWindow.Show()
}
// NewClaudeAgentWindow 创建Claude AI Agent窗口
// trafficIds: 可选的流量ID列表,用于预填充分析请求
func (a *App) NewClaudeAgentWindow(trafficIds []int64) {
// 构建 URL
url := "/#/claude-agent"
if len(trafficIds) > 0 {
// 将流量 ID 转换为逗号分隔的字符串
idsStr := ""
for i, id := range trafficIds {
if i > 0 {
idsStr += ","
}
idsStr += fmt.Sprintf("%d", id)
}
url = fmt.Sprintf("/#/claude-agent?trafficIds=%s", idsStr)
}
// 如果窗口存在且未被销毁,聚焦它并更新 URL
if claudeWindow != nil {
claudeWindow.Show()
claudeWindow.Focus()
// 如果有新的流量 ID,通过事件通知前端
if len(trafficIds) > 0 {
wailsApp.Event.Emit("claude:traffic-ids", trafficIds)
}
return
}
claudeWindow = wailsApp.Window.NewWithOptions(application.WebviewWindowOptions{
Name: "Claude Agent",
Title: "AI Security Assistant",
DevToolsEnabled: true, // 启用 DevTools (F12)
Mac: application.MacWindow{
Backdrop: application.MacBackdropLiquidGlass,
InvisibleTitleBarHeight: 25, // 只让顶部 25px 可拖拽,避免影响文字选择
LiquidGlass: application.MacLiquidGlass{
Style: application.LiquidGlassStyleLight,
Material: application.NSVisualEffectMaterialAuto,
CornerRadius: 20.0,
TintColor: nil,
},
},
Width: 1200,
Height: 1000,
URL: url,
})
// 注册窗口关闭事件
claudeWindow.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
claudeWindow = nil // 清空引用
})
claudeWindow.Show()
}
// pluginDisplayName 返回插件的显示名称
func pluginDisplayName(pluginId string) string {
names := map[string]string{
"jwt": "JWT 分析器",
"fuzz": "目录扫描",
"auth": "越权检测",
"apigen": "API 生成器",
"sqlinjection": "SQL 注入",
"xss": "XSS",
"oast": "OAST",
}
if name, ok := names[pluginId]; ok {
return name
}
return pluginId
}
// NewPluginWindow 创建/聚焦插件独立窗口
func (a *App) NewPluginWindow(pluginId string) {
// 如果窗口已存在,聚焦它
if w, ok := pluginWindows[pluginId]; ok && w != nil {
w.Show()
w.Focus()
return
}
w := wailsApp.Window.NewWithOptions(application.WebviewWindowOptions{
Name: fmt.Sprintf("Plugin-%s", pluginId),
Title: pluginDisplayName(pluginId),
DevToolsEnabled: true,
Mac: application.MacWindow{
Backdrop: application.MacBackdropLiquidGlass,
InvisibleTitleBarHeight: 25,
LiquidGlass: application.MacLiquidGlass{
Style: application.LiquidGlassStyleLight,
Material: application.NSVisualEffectMaterialAuto,
CornerRadius: 20.0,
TintColor: nil,
},
},
Width: 1100,
Height: 850,
URL: fmt.Sprintf("/#/plugin/%s", pluginId),
})
// 注册窗口关闭事件
w.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
delete(pluginWindows, pluginId)
wailsApp.Event.Emit("plugin:window-closed", pluginId)
})
pluginWindows[pluginId] = w
w.Show()
}
// ClosePluginWindow 关闭指定插件窗口
func (a *App) ClosePluginWindow(pluginId string) {
if w, ok := pluginWindows[pluginId]; ok && w != nil {
w.Close()
}
}
// IsPluginWindowOpen 查询插件窗口是否打开
func (a *App) IsPluginWindowOpen(pluginId string) bool {
_, ok := pluginWindows[pluginId]
return ok
}
// NewPluginsWindow 创建/聚焦整个插件系统的独立窗口(包含所有插件 tab)
func (a *App) NewPluginsWindow() {
const key = "__all__"
if w, ok := pluginWindows[key]; ok && w != nil {
w.Show()
w.Focus()
return
}
w := wailsApp.Window.NewWithOptions(application.WebviewWindowOptions{
Name: "Plugins-All",
Title: "插件",
DevToolsEnabled: true,
Mac: application.MacWindow{
Backdrop: application.MacBackdropLiquidGlass,
InvisibleTitleBarHeight: 25,
LiquidGlass: application.MacLiquidGlass{
Style: application.LiquidGlassStyleLight,
Material: application.NSVisualEffectMaterialAuto,
CornerRadius: 20.0,
TintColor: nil,
},
},
Width: 1200,
Height: 900,
URL: "/#/plugin/all",
})
w.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
delete(pluginWindows, key)
wailsApp.Event.Emit("plugins:window-closed")
})
pluginWindows[key] = w
w.Show()
}
// IsPluginsWindowOpen 查询整个插件系统独立窗口是否打开
func (a *App) IsPluginsWindowOpen() bool {
_, ok := pluginWindows["__all__"]
return ok
}
// WebUnPack 解包Web资源
func (a *App) WebUnPack(target string) {
webUnPack.Run(target)
}
// OpenChromeBrowser 打开Chrome浏览器
func (a *App) OpenChromeBrowser(proxy string) {
InitBrowser(proxy)
}
// InitBrowser 初始化浏览器
func InitBrowser(proxy string) error {
opts := append(chromedp.DefaultExecAllocatorOptions[:],
// 无头模式
chromedp.Flag("headless", false),
chromedp.Flag("ignore-certificate-errors", true),
chromedp.WindowSize(1920, 1080),
chromedp.ProxyServer(proxy),
// 使用 <-loopback> 语法强制代理 localhost 和 127.0.0.1
// Chrome 默认会绕过本地地址的代理,<-loopback> 表示"不绕过 loopback 地址"
chromedp.Flag("proxy-bypass-list", "<-loopback>"),
)
allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
bctx, ctxCancel := chromedp.NewContext(allocCtx,
chromedp.WithLogf(logging.Logger.Printf),
)
// 保存两个取消函数,确保资源正确释放
browserCancel = func() {
ctxCancel()
cancel()
}
// 启动浏览器
if err := chromedp.Run(bctx); err != nil {
browserCancel() // 出错时释放资源
return err
}
return nil
}
// FileSelection 文件选择
func (a *App) FileSelection() string {
return FileSelection()
}
// FileSelection 文件选择实现
func FileSelection() string {
filePath := ""
dialog := wailsApp.Dialog.OpenFile()
dialog.SetTitle("Select Image")
dialog.AddFilter("TXT Files", "*.txt")
// Single file selection
if path, err := dialog.PromptForSingleSelection(); err == nil {
// Use selected file path
filePath = path
return filePath
} else {
filePath = filepath.Join(file.ChyingDir, "jwt.txt")
}
return filePath
}