refactor: 拆分 proxy.go 为平台特定文件,兼容 macOS 和 Linux\n\n- proxy.go: 保留通用类型和辅助函数\n- proxy_windows.go: 通过注册表读取 Windows 系统代理\n- proxy_darwin.go: 通过 scutil --proxy 读取 macOS 系统代理\n- proxy_linux.go: 通过 gsettings/kreadconfig 读取 Linux 系统代理"
This commit is contained in:
43
internal/proxy_windows.go
Normal file
43
internal/proxy_windows.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/sys/windows/registry"
|
||||
)
|
||||
|
||||
// readSystemProxy 从 Windows 注册表读取系统代理设置
|
||||
func readSystemProxy(info *ProxyInfo) error {
|
||||
key, err := registry.OpenKey(
|
||||
registry.CURRENT_USER,
|
||||
`Software\Microsoft\Windows\CurrentVersion\Internet Settings`,
|
||||
registry.QUERY_VALUE,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("无法打开注册表键: %w", err)
|
||||
}
|
||||
defer key.Close()
|
||||
|
||||
// 读取代理是否启用 (ProxyEnable: 0=关闭, 1=开启)
|
||||
proxyEnable, _, err := key.GetIntegerValue("ProxyEnable")
|
||||
if err != nil {
|
||||
return fmt.Errorf("无法读取 ProxyEnable: %w", err)
|
||||
}
|
||||
info.Enabled = proxyEnable == 1
|
||||
|
||||
// 读取代理服务器地址
|
||||
proxyServer, _, err := key.GetStringValue("ProxyServer")
|
||||
if err == nil && proxyServer != "" {
|
||||
info.Server = proxyServer
|
||||
// 根据端口推断代理协议
|
||||
info.Protocol = guessProtocol(proxyServer)
|
||||
}
|
||||
|
||||
// 读取代理绕过列表
|
||||
bypass, _, err := key.GetStringValue("ProxyOverride")
|
||||
if err == nil {
|
||||
info.Bypass = bypass
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user