Skip to content

Commit 7c2ef7d

Browse files
committed
Use rods LookPath.
1 parent 1202eca commit 7c2ef7d

File tree

1 file changed

+1
-37
lines changed

1 file changed

+1
-37
lines changed

rendering/rendering.go

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@ package rendering
99
import (
1010
"bytes"
1111
"errors"
12-
"fmt"
1312
"image"
1413
_ "image/png"
1514
"net/url"
1615
"os"
17-
"os/exec"
1816
"runtime"
19-
"strings"
2017
"time"
2118

2219
"github.com/BigJk/snd/log"
@@ -29,39 +26,6 @@ import (
2926

3027
var browser *rod.Browser
3128

32-
var macChromePath = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
33-
var windowsChromePaths = []string{"Program Files (x86)/Google/Chrome/Application/chrome.exe", "Program Files/Google/Chrome/Application/chrome.exe"}
34-
35-
// detectChrome tries to search for a local chrome instance to use to avoid downloading a chrome browser.
36-
func detectChrome() (string, error) {
37-
chrome, err := exec.LookPath("chrome")
38-
if err == nil {
39-
return chrome, nil
40-
}
41-
42-
chromium, err := exec.LookPath("chromium")
43-
if err == nil {
44-
return chromium, nil
45-
}
46-
47-
if runtime.GOOS == "darwin" {
48-
if file, err := os.Stat(macChromePath); err == nil && !file.IsDir() {
49-
return macChromePath, nil
50-
}
51-
} else if runtime.GOOS == "windows" {
52-
for _, drive := range strings.Split("CABDEFGHIJKLMNOPQRSTUVWXYZ", "") {
53-
for _, path := range windowsChromePaths {
54-
executable := fmt.Sprintf("%s:/%s", drive, path)
55-
if file, err := os.Stat(executable); err == nil && !file.IsDir() {
56-
return executable, nil
57-
}
58-
}
59-
}
60-
}
61-
62-
return "", errors.New("local chrome not found")
63-
}
64-
6529
func InitBrowser() {
6630
if browser != nil {
6731
_ = browser.Close()
@@ -89,7 +53,7 @@ func InitBrowser() {
8953
l.Set(flags.Bin, customChromeBinary)
9054
} else if os.Getenv("SND_CHROME_SKIP_LOCAL") != "1" {
9155
// try to auto-detect chrome
92-
if chrome, err := detectChrome(); err == nil {
56+
if chrome, ok := launcher.LookPath(); ok {
9357
l.Set(flags.Bin, chrome)
9458
log.Info("local chrome found! If rendering causes problems start S&D with the environment flag SND_CHROME_SKIP_LOCAL=1", log.WithValue("bin", chrome))
9559
} else {

0 commit comments

Comments
 (0)