mirror of
https://github.com/black-ant/Ant-Browser.git
synced 2026-07-14 18:48:55 +08:00
channel: master version: 1.1.0 source-ref: master published-at-utc: 2026-03-20T14:14:07Z
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package browser
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
goruntime "runtime"
|
|
"strings"
|
|
)
|
|
|
|
// CoreExecutableCandidates 返回当前平台可接受的浏览器可执行文件候选名。
|
|
func CoreExecutableCandidates() []string {
|
|
switch goruntime.GOOS {
|
|
case "windows":
|
|
return []string{"chrome.exe"}
|
|
case "linux":
|
|
return []string{"chrome", "chrome-bin", "chrome.exe"}
|
|
case "darwin":
|
|
return []string{
|
|
"Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
"Chromium.app/Contents/MacOS/Chromium",
|
|
"chrome",
|
|
}
|
|
default:
|
|
return []string{"chrome"}
|
|
}
|
|
}
|
|
|
|
// FindCoreExecutable 在指定目录查找可执行文件,返回绝对路径和命中的候选名。
|
|
func FindCoreExecutable(baseDir string) (string, string, bool) {
|
|
baseDir = strings.TrimSpace(baseDir)
|
|
if baseDir == "" {
|
|
return "", "", false
|
|
}
|
|
for _, candidate := range CoreExecutableCandidates() {
|
|
p := filepath.Join(baseDir, filepath.FromSlash(candidate))
|
|
if _, err := os.Stat(p); err == nil {
|
|
return p, candidate, true
|
|
}
|
|
}
|
|
return "", "", false
|
|
}
|