sing-box/common/settings/proxy_windows.go

44 lines
847 B
Go
Raw Permalink Normal View History

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