Files
Ant-Browser/backend/internal/browser/core_binary.go
T
Ant Browser Release Bot fc5a6fadbe publish: 1.1.0 snapshot (ff46de5)
channel: master
version: 1.1.0
source-ref: master
published-at-utc: 2026-03-20T14:14:07Z
2026-03-20 22:14:08 +08:00

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
}