Skip to content
This repository was archived by the owner on Jan 17, 2021. It is now read-only.

Commit 9cb8a75

Browse files
authored
Merge pull request #14 from codercom/pkgbrowser
Use pkg/browser where possible and remove explicit firefox support
2 parents 3ce3a26 + efca7a7 commit 9cb8a75

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module go.coder.com/sshcode
33
go 1.12
44

55
require (
6+
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
67
go.coder.com/flog v0.0.0-20190129195112-eaed154a0db8
78
golang.org/x/sys v0.0.0-20190418153312-f0ce4c0180be // indirect
89
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRU
44
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
55
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
66
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
7+
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98=
8+
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
79
go.coder.com/flog v0.0.0-20190129195112-eaed154a0db8 h1:PtQ3moPi4EAz3cyQhkUs1IGIXa2QgJpP60yMjOdu0kk=
810
go.coder.com/flog v0.0.0-20190129195112-eaed154a0db8/go.mod h1:83JsYgXYv0EOaXjIMnaZ1Fl6ddNB3fJnDZ/8845mUJ8=
911
golang.org/x/sys v0.0.0-20190418153312-f0ce4c0180be h1:mI+jhqkn68ybP0ORJqunXn+fq+Eeb4hHKqLQcFICjAc=

main.go

+15-11
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
"strconv"
1515
"time"
1616

17-
"golang.org/x/xerrors"
18-
17+
"github.com/pkg/browser"
1918
"go.coder.com/flog"
19+
"golang.org/x/xerrors"
2020
)
2121

2222
func init() {
@@ -139,26 +139,30 @@ func openBrowser(url string) {
139139
var openCmd *exec.Cmd
140140
switch {
141141
case commandExists("google-chrome"):
142-
openCmd = exec.Command("google-chrome", fmtChromeOptions(url)...)
142+
openCmd = exec.Command("google-chrome", chromeOptions(url)...)
143143
case commandExists("chromium"):
144-
openCmd = exec.Command("chromium", fmtChromeOptions(url)...)
144+
openCmd = exec.Command("chromium", chromeOptions(url)...)
145145
case commandExists("chromium-browser"):
146-
openCmd = exec.Command("chromium-browser", fmtChromeOptions(url)...)
147-
case commandExists("firefox"):
148-
openCmd = exec.Command("firefox", "--url="+url, "-safe-mode")
146+
openCmd = exec.Command("chromium-browser", chromeOptions(url)...)
149147
case pathExists("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"):
150-
openCmd = exec.Command("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", fmtChromeOptions(url)...)
148+
openCmd = exec.Command("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", chromeOptions(url)...)
151149
default:
152-
flog.Info("unable to find a browser to open: sshcode only supports firefox, chrome, and chromium")
150+
err := browser.OpenURL(url)
151+
if err != nil {
152+
flog.Error("failed to open browser: %v", err)
153+
}
154+
return
153155
}
154156

157+
// We do not use CombinedOutput because if there is no chrome instance, this will block
158+
// and become the parent process instead of using an existing chrome instance.
155159
err := openCmd.Start()
156160
if err != nil {
157-
flog.Fatal("failed to open browser: %v", err)
161+
flog.Error("failed to open browser: %v", err)
158162
}
159163
}
160164

161-
func fmtChromeOptions(url string) []string {
165+
func chromeOptions(url string) []string {
162166
return []string{"--app=" + url, "--disable-extensions", "--disable-plugins"}
163167
}
164168

0 commit comments

Comments
 (0)