Added -startup-url and -time-limit args

This commit is contained in:
Thomas Buckley-Houston 2018-02-04 18:26:01 +08:00
parent fc5e72b191
commit cf6cde86f7
3 changed files with 25 additions and 5 deletions

View file

@ -32,6 +32,8 @@ var (
isUseExistingFirefox = flag.Bool("use-existing-ff", false, "Whether Browsh should launch Firefox or not") isUseExistingFirefox = flag.Bool("use-existing-ff", false, "Whether Browsh should launch Firefox or not")
useFFProfile = flag.String("ff-profile", "default", "Firefox profile to use") useFFProfile = flag.String("ff-profile", "default", "Firefox profile to use")
isDebug = flag.Bool("debug", false, "Log to ./debug.log") 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{ upgrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool { return true }, CheckOrigin: func(r *http.Request) bool { return true },
ReadBufferSize: 1024, ReadBufferSize: 1024,
@ -139,7 +141,7 @@ func readStdin() {
case termbox.EventKey: case termbox.EventKey:
if ev.Key == termbox.KeyCtrlQ { if ev.Key == termbox.KeyCtrlQ {
if !*isUseExistingFirefox { if !*isUseExistingFirefox {
sendFirefoxCommand("quitApplication", map[string]interface{}{}) quitFirefox()
} }
shutdown("normal") shutdown("normal")
} }
@ -387,7 +389,7 @@ func loadHomePage() {
// Wait for the CLI websocket server to start listening // Wait for the CLI websocket server to start listening
time.Sleep(200 * time.Millisecond) time.Sleep(200 * time.Millisecond)
args := map[string]interface{}{ args := map[string]interface{}{
"url": "https://google.com", "url": *startupURL,
} }
sendFirefoxCommand("get", args) sendFirefoxCommand("get", args)
} }
@ -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 // 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. // 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. // We can't bump the version and create a new signed webextension for every commit.
func setupFirefox() { func setupFirefox() {
go startHeadlessFirefox() go startHeadlessFirefox()
if (*timeLimit > 0) {
go beginTimeLimit()
}
// TODO: Do something better than just waiting // TODO: Do something better than just waiting
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
firefoxMarionette() firefoxMarionette()
@ -411,10 +427,14 @@ func setupFirefox() {
go loadHomePage() go loadHomePage()
} }
func quitFirefox() {
sendFirefoxCommand("quitApplication", map[string]interface{}{})
}
func main() { func main() {
initialise() initialise()
if !*isUseExistingFirefox { if !*isUseExistingFirefox {
println("Starting Browsh...") println("Starting Browsh, the modern terminal web browser...")
setupFirefox() setupFirefox()
} else { } else {
println("Waiting for a Firefox instance to connect...") println("Waiting for a Firefox instance to connect...")

View file

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Browsh", "name": "Browsh",
"version": "0.2.6", "version": "0.2.7",
"description": "Renders the browser as realtime, interactive, TTY-compatible text", "description": "Renders the browser as realtime, interactive, TTY-compatible text",

View file

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Browsh", "name": "Browsh",
"version": "0.2.6", "version": "0.2.7",
"description": "Renders the browser as realtime, interactive, TTY-compatible text", "description": "Renders the browser as realtime, interactive, TTY-compatible text",