From 227541b5a1bd67f285f2b33ec97fa8c4df6c185f Mon Sep 17 00:00:00 2001 From: sneak Date: Tue, 29 Nov 2022 17:12:11 +0100 Subject: [PATCH] requested changes per #334 --- framework/framework.go | 8 ++++---- internal/cli/cli.go | 2 +- internal/cli/run/run.go | 11 +++++------ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/framework/framework.go b/framework/framework.go index 003c9e194..e96bef2e6 100644 --- a/framework/framework.go +++ b/framework/framework.go @@ -4,10 +4,10 @@ import "io" // Flag is used by many of the framework generators type Flag struct { - Embed bool - Minify bool - Hot bool - Noautolaunch bool + Embed bool + Minify bool + Hot bool + OpenBrowser bool // Comes from *bud.Input Stdin io.Reader diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 2b366385b..778d4a17c 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -63,7 +63,7 @@ func (c *CLI) Run(ctx context.Context, args ...string) error { cli.Flag("embed", "embed assets").Bool(&cmd.Flag.Embed).Default(false) cli.Flag("hot", "hot reloading").Bool(&cmd.Flag.Hot).Default(true) cli.Flag("minify", "minify assets").Bool(&cmd.Flag.Minify).Default(false) - cli.Flag("noautolaunch", "don't autolaunch browser").Bool(&cmd.Flag.Noautolaunch).Default(false) + cli.Flag("open", "open browser on dev server startup").Bool(&cmd.Flag.OpenBrowser).Default(false) cli.Flag("listen", "address to listen to").String(&cmd.Listen).Default(":3000") cli.Run(cmd.Run) } diff --git a/internal/cli/run/run.go b/internal/cli/run/run.go index 2eec0cb45..df3efb156 100644 --- a/internal/cli/run/run.go +++ b/internal/cli/run/run.go @@ -151,12 +151,11 @@ func (c *Command) Run(ctx context.Context) (err error) { eg.Go(func() error { return appServer.Run(ctx) }) // Wait until either the hot or web server exits - // Launch browser unless we're told not to - if !c.Flag.Noautolaunch { // if not not autolaunch, i.e. if autolaunch - go func() { - time.Sleep(1 * time.Second) - _ = browser.OpenURL("http://" + webln.Addr().String()) - }() + if !c.Flag.OpenBrowser { + err := browser.OpenURL("http://" + webln.Addr().String()) + if err != nil { + return err + } } err = eg.Wait()