Skip to content

Commit

Permalink
Added Firefox paths for Windows and OSX
Browse files Browse the repository at this point in the history
Also updated Gopkg dep versions.

And version bump to 1.0.0pre1!
  • Loading branch information
tombh committed Jun 10, 2018
1 parent 7d3620e commit 98fa801
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
18 changes: 9 additions & 9 deletions interfacer/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 15 additions & 6 deletions interfacer/src/browsh/browsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io/ioutil"
"os"
"os/exec"
"runtime"
"path/filepath"
"strings"
"unicode"
Expand Down Expand Up @@ -87,8 +88,10 @@ func Shutdown(err error) {
exitCode = 1
println(err.Error())
}
out := err.(*errors.Error).ErrorStack()
Log(fmt.Sprintf(out))
if *isDebug {
out := err.(*errors.Error).ErrorStack()
Log(fmt.Sprintf(out))
}
os.Exit(exitCode)
}

Expand Down Expand Up @@ -133,14 +136,16 @@ func stripWhitespace(str string) string {
}, str)
}

// Shell ... Nice and easy shell commands
// Shell provides nice and easy shell commands
func Shell(command string) string {
parts := strings.Fields(command)
head := parts[0]
parts = parts[1:len(parts)]
out, err := exec.Command(head, parts...).Output()
out, err := exec.Command(head, parts...).CombinedOutput()
if err != nil {
return "firefox not found"
fmt.Printf(
"Browsh tried to run `%s` but failed with: %s", command, string(out))
Shutdown(err)
}
return stripWhitespace(string(out))
}
Expand Down Expand Up @@ -176,7 +181,11 @@ func toInt32(char string) int32 {
func ttyEntry() {
// Hack to force true colours
// Follow: https://github.com/gdamore/tcell/pull/183
os.Setenv("TERM", "xterm-truecolor")
if runtime.GOOS != "windows" {
// On windows this generates a "character set not supported" error. The error comes
// from tcell.
os.Setenv("TERM", "xterm-truecolor")
}
realScreen, err := tcell.NewScreen()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
Expand Down
24 changes: 19 additions & 5 deletions interfacer/src/browsh/firefox.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net"
"os"
"os/exec"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -52,10 +53,7 @@ var (

func startHeadlessFirefox() {
Log("Starting Firefox in headless mode")
firefoxPath := Shell("which " + *firefoxBinary)
if _, err := os.Stat(firefoxPath); os.IsNotExist(err) {
Shutdown(errors.New("Firefox command not found: " + *firefoxBinary))
}
ensureFirefoxBinary()
args := []string{"--marionette"}
if !*isFFGui {
args = append(args, "--headless")
Expand Down Expand Up @@ -83,6 +81,22 @@ func startHeadlessFirefox() {
}
}

func ensureFirefoxBinary() {
if *firefoxBinary == "firefox" {
switch runtime.GOOS {
case "windows":
*firefoxBinary = `c:\Program Files (x86)\Mozilla Firefox\firefox.exe`
case "darwin":
*firefoxBinary = "/Applications/Firefox.app/Contents/MacOS/firefox"
default:
*firefoxBinary = Shell("which firefox")
}
}
if _, err := os.Stat(*firefoxBinary); os.IsNotExist(err) {
Shutdown(errors.New("Firefox binary not found: " + *firefoxBinary))
}
}

// Start Firefox via the `web-ext` CLI tool. This is for development and testing,
// because I haven't been able to recreate the way `web-ext` injects an unsigned
// extension.
Expand All @@ -96,7 +110,7 @@ func startWERFirefox() {
"--no-reload",
"--url=https://www.google.com",
}
firefoxProcess := exec.Command(rootDir+"/webext/node_modules/.bin/web-ext", args...)
firefoxProcess := exec.Command(rootDir + "/webext/node_modules/.bin/web-ext", args...)
firefoxProcess.Dir = rootDir + "/webext/dist/"
defer firefoxProcess.Process.Kill()
stdout, err := firefoxProcess.StdoutPipe()
Expand Down
2 changes: 1 addition & 1 deletion webext/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Browsh",
"version": "0.2.14",
"version": "1.0.0",

"description": "Renders the browser as realtime, interactive, TTY-compatible text",

Expand Down

0 comments on commit 98fa801

Please sign in to comment.