mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-22 08:31:30 +00:00
Add KDE set system proxy support
Co-authored-by: Hiddify <114227601+hiddify1@users.noreply.github.com>
This commit is contained in:
parent
4c050d7f4b
commit
69499a51a5
|
@ -16,10 +16,12 @@ import (
|
|||
|
||||
var (
|
||||
hasGSettings bool
|
||||
isKDE5 bool
|
||||
sudoUser string
|
||||
)
|
||||
|
||||
func init() {
|
||||
isKDE5 = common.Error(exec.LookPath("kwriteconfig5")) == nil
|
||||
hasGSettings = common.Error(exec.LookPath("gsettings")) == nil
|
||||
if os.Getuid() == 0 {
|
||||
sudoUser = os.Getenv("SUDO_USER")
|
||||
|
@ -37,9 +39,7 @@ func runAsUser(name string, args ...string) error {
|
|||
}
|
||||
|
||||
func SetSystemProxy(router adapter.Router, port uint16, isMixed bool) (func() error, error) {
|
||||
if !hasGSettings {
|
||||
return nil, E.New("unsupported desktop environment")
|
||||
}
|
||||
if hasGSettings {
|
||||
err := runAsUser("gsettings", "set", "org.gnome.system.proxy.http", "enabled", "true")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -63,6 +63,37 @@ func SetSystemProxy(router adapter.Router, port uint16, isMixed bool) (func() er
|
|||
return func() error {
|
||||
return runAsUser("gsettings", "set", "org.gnome.system.proxy", "mode", "none")
|
||||
}, nil
|
||||
}
|
||||
if isKDE5 {
|
||||
err := runAsUser("kwriteconfig5", "--file", "kioslaverc", "--group", "'Proxy Settings'", "--key", "ProxyType", "1")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if isMixed {
|
||||
err = setKDEProxy(port, "ftp", "http", "https", "socks")
|
||||
} else {
|
||||
err = setKDEProxy(port, "http", "https")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = runAsUser("kwriteconfig5", "--file", "kioslaverc", "--group", "'Proxy Settings'", "--key", "Authmode", "0")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = runAsUser("dbus-send", "--type=signal", "/KIO/Scheduler", "org.kde.KIO.Scheduler.reparseSlaveConfiguration", "string:''")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return func() error {
|
||||
err = runAsUser("kwriteconfig5", "--file", "kioslaverc", "--group", "'Proxy Settings'", "--key", "ProxyType", "0")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return runAsUser("dbus-send", "--type=signal", "/KIO/Scheduler", "org.kde.KIO.Scheduler.reparseSlaveConfiguration", "string:''")
|
||||
}, nil
|
||||
}
|
||||
return nil, E.New("unsupported desktop environment")
|
||||
}
|
||||
|
||||
func setGnomeProxy(port uint16, proxyTypes ...string) error {
|
||||
|
@ -78,3 +109,27 @@ func setGnomeProxy(port uint16, proxyTypes ...string) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setKDEProxy(port uint16, proxyTypes ...string) error {
|
||||
for _, proxyType := range proxyTypes {
|
||||
var proxyUrl string
|
||||
if proxyType == "socks" {
|
||||
proxyUrl = "socks://127.0.0.1:" + F.ToString(port)
|
||||
} else {
|
||||
proxyUrl = "http://127.0.0.1:" + F.ToString(port)
|
||||
}
|
||||
err := runAsUser(
|
||||
"kwriteconfig5",
|
||||
"--file",
|
||||
"kioslaverc",
|
||||
"--group",
|
||||
"'Proxy Settings'",
|
||||
"--key", proxyType+"Proxy",
|
||||
proxyUrl,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue