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

Create base #1

Merged
merged 4 commits into from
Apr 19, 2019
Merged
Changes from 1 commit
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
21 changes: 10 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ chmod +x ~/bin/code-server
)
output, err := sshCmd.CombinedOutput()
if err != nil {
flog.Fatal("failed to update code-server: %v: %s", err, string(output))
flog.Fatal("failed to update code-server: %v: %s", err, output)
}

flog.Info("starting code-server...")
Expand All @@ -72,20 +72,12 @@ chmod +x ~/bin/code-server
flog.Fatal("failed to start code-server: %v", err)
}

var openCmd *exec.Cmd
url := "http://127.0.0.1:" + localPort
if commandExists("google-chrome") {
openCmd = exec.Command("google-chrome", "--app="+url, "--disable-extensions", "--disable-plugins")
} else if commandExists("firefox") {
openCmd = exec.Command("firefox", "--url="+url, "-safe-mode")
}

ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
for {
err := ctx.Err()
if err != nil {
flog.Fatal("code-server didn't start in time %v", err)
if ctx.Err() != nil {
flog.Fatal("code-server didn't start in time %v", ctx.Err())
}
// Waits for code-server to be available before opening the browser.
r, _ := http.NewRequest("GET", url, nil)
Expand All @@ -98,6 +90,13 @@ chmod +x ~/bin/code-server
break
}

var openCmd *exec.Cmd
if commandExists("google-chrome") {
openCmd = exec.Command("google-chrome", "--app="+url, "--disable-extensions", "--disable-plugins")
} else if commandExists("firefox") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it back. If neither of these exist, this program will panic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

openCmd = exec.Command("firefox", "--url="+url, "-safe-mode")
}

err = openCmd.Start()
if err != nil {
flog.Fatal("failed to open browser: %v", err)
Expand Down