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

Use pkg/browser where possible and remove explicit firefox support #14

Merged
merged 2 commits into from
Apr 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module go.coder.com/sshcode
go 1.12

require (
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
go.coder.com/flog v0.0.0-20190129195112-eaed154a0db8
golang.org/x/sys v0.0.0-20190418153312-f0ce4c0180be // indirect
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRU
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98=
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
go.coder.com/flog v0.0.0-20190129195112-eaed154a0db8 h1:PtQ3moPi4EAz3cyQhkUs1IGIXa2QgJpP60yMjOdu0kk=
go.coder.com/flog v0.0.0-20190129195112-eaed154a0db8/go.mod h1:83JsYgXYv0EOaXjIMnaZ1Fl6ddNB3fJnDZ/8845mUJ8=
golang.org/x/sys v0.0.0-20190418153312-f0ce4c0180be h1:mI+jhqkn68ybP0ORJqunXn+fq+Eeb4hHKqLQcFICjAc=
Expand Down
26 changes: 15 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"strconv"
"time"

"golang.org/x/xerrors"

"github.com/pkg/browser"
"go.coder.com/flog"
"golang.org/x/xerrors"
)

func init() {
Expand Down Expand Up @@ -139,26 +139,30 @@ func openBrowser(url string) {
var openCmd *exec.Cmd
switch {
case commandExists("google-chrome"):
openCmd = exec.Command("google-chrome", fmtChromeOptions(url)...)
openCmd = exec.Command("google-chrome", chromeOptions(url)...)
case commandExists("chromium"):
openCmd = exec.Command("chromium", fmtChromeOptions(url)...)
openCmd = exec.Command("chromium", chromeOptions(url)...)
case commandExists("chromium-browser"):
openCmd = exec.Command("chromium-browser", fmtChromeOptions(url)...)
case commandExists("firefox"):
openCmd = exec.Command("firefox", "--url="+url, "-safe-mode")
openCmd = exec.Command("chromium-browser", chromeOptions(url)...)
case pathExists("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"):
openCmd = exec.Command("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", fmtChromeOptions(url)...)
openCmd = exec.Command("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", chromeOptions(url)...)
default:
flog.Info("unable to find a browser to open: sshcode only supports firefox, chrome, and chromium")
err := browser.OpenURL(url)
if err != nil {
flog.Error("failed to open browser: %v", err)
}
return
}

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

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

Expand Down