Skip to content

Commit

Permalink
Added -startup-url and -time-limit args
Browse files Browse the repository at this point in the history
  • Loading branch information
tombh committed Feb 4, 2018
1 parent fc5e72b commit cf6cde8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
26 changes: 23 additions & 3 deletions interfacer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ var (
isUseExistingFirefox = flag.Bool("use-existing-ff", false, "Whether Browsh should launch Firefox or not")
useFFProfile = flag.String("ff-profile", "default", "Firefox profile to use")
isDebug = flag.Bool("debug", false, "Log to ./debug.log")
startupURL = flag.String("startup-url", "https://google.com", "URL to launch at startup")
timeLimit = flag.Int("time-limit", 0, "Kill Browsh after the specified number of seconds")
upgrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool { return true },
ReadBufferSize: 1024,
Expand Down Expand Up @@ -139,7 +141,7 @@ func readStdin() {
case termbox.EventKey:
if ev.Key == termbox.KeyCtrlQ {
if !*isUseExistingFirefox {
sendFirefoxCommand("quitApplication", map[string]interface{}{})
quitFirefox()
}
shutdown("normal")
}
Expand Down Expand Up @@ -387,7 +389,7 @@ func loadHomePage() {
// Wait for the CLI websocket server to start listening
time.Sleep(200 * time.Millisecond)
args := map[string]interface{}{
"url": "https://google.com",
"url": *startupURL,
}
sendFirefoxCommand("get", args)
}
Expand All @@ -398,11 +400,25 @@ func setDefaultPreferences() {
}
}

func beginTimeLimit() {
warningLength := 10
warningLimit := time.Duration(*timeLimit - warningLength);
time.Sleep(warningLimit * time.Second)
message := fmt.Sprintf("Browsh will close in %d seconds...", warningLength)
sendMessageToWebExtension("/status," + message)
time.Sleep(time.Duration(warningLength) * time.Second)
quitFirefox()
shutdown("normal")
}

// Note that everything executed in and from this function is not covered by the integration
// tests, because it uses the officially signed webextension, of which there can be only one.
// We can't bump the version and create a new signed webextension for every commit.
func setupFirefox() {
go startHeadlessFirefox()
if (*timeLimit > 0) {
go beginTimeLimit()
}
// TODO: Do something better than just waiting
time.Sleep(3 * time.Second)
firefoxMarionette()
Expand All @@ -411,10 +427,14 @@ func setupFirefox() {
go loadHomePage()
}

func quitFirefox() {
sendFirefoxCommand("quitApplication", map[string]interface{}{})
}

func main() {
initialise()
if !*isUseExistingFirefox {
println("Starting Browsh...")
println("Starting Browsh, the modern terminal web browser...")
setupFirefox()
} else {
println("Waiting for a Firefox instance to connect...")
Expand Down
2 changes: 1 addition & 1 deletion webext/dist/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Browsh",
"version": "0.2.6",
"version": "0.2.7",

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

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.6",
"version": "0.2.7",

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

Expand Down

0 comments on commit cf6cde8

Please sign in to comment.