Files
sing-box-extended-mirror/common/settings/proxy_windows.go
T

47 lines
965 B
Go
Raw Normal View History

2022-07-14 20:30:57 +08:00
package settings
2022-07-14 14:04:57 +08:00
import (
2023-09-03 14:29:37 +08:00
"context"
"strings"
2023-09-03 14:29:37 +08:00
M "github.com/sagernet/sing/common/metadata"
2022-07-17 15:11:26 +08:00
"github.com/sagernet/sing/common/wininet"
2022-07-14 14:04:57 +08:00
)
2023-09-03 14:29:37 +08:00
type WindowsSystemProxy struct {
serverAddr M.Socksaddr
supportSOCKS bool
bypassDomain []string
2023-09-03 14:29:37 +08:00
isEnabled bool
}
func NewSystemProxy(ctx context.Context, serverAddr M.Socksaddr, supportSOCKS bool, bypassDomain []string) (*WindowsSystemProxy, error) {
2023-09-03 14:29:37 +08:00
return &WindowsSystemProxy{
serverAddr: serverAddr,
supportSOCKS: supportSOCKS,
bypassDomain: bypassDomain,
2023-09-03 14:29:37 +08:00
}, nil
}
func (p *WindowsSystemProxy) IsEnabled() bool {
return p.isEnabled
}
func (p *WindowsSystemProxy) Enable() error {
err := wininet.SetSystemProxy("http://"+p.serverAddr.String(), strings.Join(p.bypassDomain, ";"))
2022-08-04 22:01:20 +08:00
if err != nil {
2023-09-03 14:29:37 +08:00
return err
2022-08-04 22:01:20 +08:00
}
2023-09-03 14:29:37 +08:00
p.isEnabled = true
return nil
}
func (p *WindowsSystemProxy) Disable() error {
err := wininet.ClearSystemProxy()
if err != nil {
return err
}
p.isEnabled = false
return nil
2022-07-14 14:04:57 +08:00
}