new: add fallback for commander if not working as a service
This commit is contained in:
@@ -9,13 +9,17 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExecuteCmd(executablePath, args string) (string, error) {
|
func ExecuteCmd(executablePath, args string, background bool) (string, error) {
|
||||||
cwd := filepath.Dir(executablePath)
|
cwd := filepath.Dir(executablePath)
|
||||||
background := false
|
|
||||||
if appimage := os.Getenv("APPIMAGE"); appimage != "" {
|
if appimage := os.Getenv("APPIMAGE"); appimage != "" {
|
||||||
executablePath = appimage + " HiddifyService"
|
executablePath = appimage + " HiddifyService"
|
||||||
args = ""
|
if !background {
|
||||||
background = true
|
return nil, fmt.Errorf("Appimage can not have service")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := execCmdImp([]string{"cocoasudo", "--prompt=Hiddify needs root for tunneling.", executablePath, args}, cwd, background); err == nil {
|
||||||
|
return "Ok", nil
|
||||||
}
|
}
|
||||||
if err := execCmdImp([]string{"gksu", executablePath, args}, cwd, background); err == nil {
|
if err := execCmdImp([]string{"gksu", executablePath, args}, cwd, background); err == nil {
|
||||||
return "Ok", nil
|
return "Ok", nil
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExecuteCmd(exe string, args string) (string, error) {
|
func ExecuteCmd(exe string, args string, background bool) (string, error) {
|
||||||
verb := "runas"
|
verb := "runas"
|
||||||
cwd, _ := os.Getwd()
|
cwd, _ := os.Getwd()
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
|
|
||||||
"github.com/sagernet/sing-box/option"
|
"github.com/sagernet/sing-box/option"
|
||||||
dns "github.com/sagernet/sing-dns"
|
dns "github.com/sagernet/sing-dns"
|
||||||
E "github.com/sagernet/sing/common/exceptions"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -25,10 +24,10 @@ func isSupportedOS() bool {
|
|||||||
return runtime.GOOS == "windows" || runtime.GOOS == "linux"
|
return runtime.GOOS == "windows" || runtime.GOOS == "linux"
|
||||||
}
|
}
|
||||||
func ActivateTunnelService(opt ConfigOptions) (bool, error) {
|
func ActivateTunnelService(opt ConfigOptions) (bool, error) {
|
||||||
if !isSupportedOS() {
|
// if !isSupportedOS() {
|
||||||
return false, E.New("Unsupported OS: " + runtime.GOOS)
|
// return false, E.New("Unsupported OS: " + runtime.GOOS)
|
||||||
}
|
// }
|
||||||
|
|
||||||
go startTunnelRequest(opt, true)
|
go startTunnelRequest(opt, true)
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
@@ -93,9 +92,13 @@ func stopTunnelRequest() (bool, error) {
|
|||||||
|
|
||||||
func runTunnelService(opt ConfigOptions) (bool, error) {
|
func runTunnelService(opt ConfigOptions) (bool, error) {
|
||||||
executablePath := getTunnelServicePath()
|
executablePath := getTunnelServicePath()
|
||||||
fmt.Printf("Executable path is %s",executablePath)
|
fmt.Printf("Executable path is %s", executablePath)
|
||||||
out, err := ExecuteCmd(executablePath, "install")
|
out, err := ExecuteCmd(executablePath, "install", false)
|
||||||
fmt.Println("Shell command executed:", out, err)
|
fmt.Println("Shell command executed:", out, err)
|
||||||
|
if err != nil {
|
||||||
|
out, err := ExecuteCmd(executablePath, "", true)
|
||||||
|
fmt.Println("Shell command executed without flag:", out, err)
|
||||||
|
}
|
||||||
return startTunnelRequest(opt, false)
|
return startTunnelRequest(opt, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,6 +115,6 @@ func getTunnelServicePath() string {
|
|||||||
fullPath = "HiddifyService"
|
fullPath = "HiddifyService"
|
||||||
}
|
}
|
||||||
|
|
||||||
abspath,_:=filepath.Abs(filepath.Join(binFolder, fullPath))
|
abspath, _ := filepath.Abs(filepath.Join(binFolder, fullPath))
|
||||||
return abspath
|
return abspath
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user