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

Add support for chromium #5

Merged
merged 2 commits into from
Apr 19, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Chrome is recommended.

```bash
go get go.coder.com/sshcode
GO111MODULE=off go get go.coder.com/sshcode
```

## Usage
Expand Down
17 changes: 14 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -124,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()
Expand Down