Skip to content

Commit

Permalink
this should now open the browser automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
sneak committed Nov 28, 2022
1 parent 42eda3b commit f25a261
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
7 changes: 4 additions & 3 deletions framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import "io"

// Flag is used by many of the framework generators
type Flag struct {
Embed bool
Minify bool
Hot bool
Embed bool
Minify bool
Hot bool
Noautolaunch bool

// Comes from *bud.Input
Stdin io.Reader
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
github.com/matthewmueller/gotext v0.0.0-20210424201144-265ed61725ac
github.com/matthewmueller/text v0.0.0-20210424201111-ec1e4af8dfe8
github.com/otiai10/copy v1.7.0
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/pointlander/peg v1.0.1
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/timewasted/go-accept-headers v0.0.0-20130320203746-c78f304b1b09
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
github.com/otiai10/mint v1.3.3 h1:7JgpsBaN0uMkyju4tbYHu0mnM55hNKVYLsXmwr15NQI=
github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down Expand Up @@ -132,6 +134,7 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
1 change: 1 addition & 0 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +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("listen", "address to listen to").String(&cmd.Listen).Default(":3000")
cli.Run(cmd.Run)
}
Expand Down
13 changes: 11 additions & 2 deletions internal/cli/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"path/filepath"
"time"

"golang.org/x/sync/errgroup"

"github.com/livebud/bud/framework"
"github.com/livebud/bud/framework/web/webrt"
"github.com/livebud/bud/internal/bfs"
Expand All @@ -26,6 +24,8 @@ import (
"github.com/livebud/bud/package/log"
"github.com/livebud/bud/package/socket"
"github.com/livebud/bud/package/watcher"
"github.com/pkg/browser"
"golang.org/x/sync/errgroup"
)

// New command for bud run.
Expand Down Expand Up @@ -150,6 +150,15 @@ func (c *Command) Run(ctx context.Context) (err error) {
// Start the internal app server
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())
}()
}

err = eg.Wait()
log.Field("error", err).Debug("run: command finished")
return err
Expand Down

0 comments on commit f25a261

Please sign in to comment.