mirror of
https://github.com/black-ant/Ant-Browser.git
synced 2026-07-14 18:48:55 +08:00
51 lines
2.0 KiB
Go
51 lines
2.0 KiB
Go
package backend
|
|
|
|
import (
|
|
"ant-chrome/backend/internal/browser"
|
|
"ant-chrome/backend/internal/proxy"
|
|
)
|
|
|
|
func (a *App) BrowserProxyList() []BrowserProxy {
|
|
return browser.ListProxiesWithFallback(a.browserMgr.ProxyDAO, a.config.Browser.Proxies)
|
|
}
|
|
|
|
// BrowserProxyListGroups 获取所有代理分组名称
|
|
func (a *App) BrowserProxyListGroups() []string {
|
|
return browser.ListProxyGroups(a.browserMgr.ProxyDAO)
|
|
}
|
|
|
|
// BrowserProxyListByGroup 按分组名称查询代理
|
|
func (a *App) BrowserProxyListByGroup(groupName string) []BrowserProxy {
|
|
return browser.ListProxiesByGroupWithFallback(a.browserMgr.ProxyDAO, groupName, a.config.Browser.Proxies)
|
|
}
|
|
|
|
// ValidateProxyConfig 验证代理配置是否支持
|
|
func (a *App) ValidateProxyConfig(proxyConfig string, proxyId string) ProxyValidationResult {
|
|
proxies := a.getLatestProxies()
|
|
supported, errorMsg := proxy.ValidateProxyConfig(proxyConfig, proxies, proxyId)
|
|
return ProxyValidationResult{
|
|
Supported: supported,
|
|
ErrorMsg: errorMsg,
|
|
}
|
|
}
|
|
|
|
// TestProxyConnectivity 测试代理连通性
|
|
func (a *App) TestProxyConnectivity(proxyId string, proxyConfig string) ProxyTestResult {
|
|
proxies := a.getLatestProxies()
|
|
result := proxy.TestConnectivity(proxyId, proxyConfig, proxies, nil)
|
|
return ProxyTestResult{ProxyId: result.ProxyId, Ok: result.Ok, LatencyMs: result.LatencyMs, Error: result.Error}
|
|
}
|
|
|
|
// TestProxyRealConnectivity 通过真实 HTTP 请求测试代理连通性(Wails 绑定)
|
|
// 参考 Clash URLTest 策略:多 URL fallback + 复用桥接 + TCP ping 降级
|
|
func (a *App) TestProxyRealConnectivity(proxyId string) ProxyTestResult {
|
|
proxies := a.getLatestProxies()
|
|
result := proxy.SpeedTest(proxyId, proxies, a.xrayMgr, a.singboxMgr, nil)
|
|
return ProxyTestResult{ProxyId: result.ProxyId, Ok: result.Ok, LatencyMs: result.LatencyMs, Error: result.Error}
|
|
}
|
|
|
|
// getLatestProxies 获取最新的代理列表,优先从数据库读取
|
|
func (a *App) getLatestProxies() []BrowserProxy {
|
|
return browser.LatestProxiesWithFallback(a.browserMgr.ProxyDAO, a.config.Browser.Proxies)
|
|
}
|