From b53d00f55a7677e3c14178afe11dad569c32e944 Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Fri, 19 Apr 2019 11:05:21 -0500 Subject: [PATCH 1/2] Add support for chromium --- README.md | 2 +- main.go | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bba642f..3a9dcb6 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Chrome is recommended. ```bash -go get go.coder.com/sshcode +GO111MODULE=off go get go.coder.com/sshcode ``` ## Usage diff --git a/main.go b/main.go index 447e4d1..642b98d 100644 --- a/main.go +++ b/main.go @@ -97,11 +97,19 @@ chmod +x ~/bin/code-server func openBrowser(url string) { var openCmd *exec.Cmd if commandExists("google-chrome") { - openCmd = exec.Command("google-chrome", "--app="+url, "--disable-extensions", "--disable-plugins") + openCmd = exec.Command("google-chrome", fmtChromeOptions(url)...) + + } else if commandExists("chromium") { + openCmd = exec.Command("chromium", fmtChromeOptions(url)...) + + } else if commandExists("chromium-browser") { + openCmd = exec.Command("chromium-browser", fmtChromeOptions(url)...) + } else if commandExists("firefox") { openCmd = exec.Command("firefox", "--url="+url, "-safe-mode") + } else { - flog.Info("unable to find a browser to open: sshcode only supports firefox and chrome") + flog.Info("unable to find a browser to open: sshcode only supports firefox, chrome, and chromium") return } @@ -112,6 +120,10 @@ func openBrowser(url string) { } } +func fmtChromeOptions(url string) []string { + return []string{"--app=" + url, "--disable-extensions", "--disable-plugins"} +} + // Checks if a command exists locally. func commandExists(name string) bool { _, err := exec.LookPath(name) From c74ac7e6684d24d348ea04c6884a7d5f83e233b9 Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Fri, 19 Apr 2019 11:17:17 -0500 Subject: [PATCH 2/2] Remove redundant port++ --- main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/main.go b/main.go index 642b98d..1fb5039 100644 --- a/main.go +++ b/main.go @@ -136,7 +136,6 @@ func scanAvailablePort() (string, error) { l, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) if err != nil { // If we have an error the port is taken. - port++ continue } _ = l.Close()