From 7aa267dbb65077bea3848337f746df251f5b2f9f Mon Sep 17 00:00:00 2001 From: Justin McCarthy Date: Thu, 17 May 2018 22:45:39 -0700 Subject: [PATCH] only open html after render is complete during serve --- internal/render/html.go | 12 +++++++++++- internal/render/site.go | 5 ----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/render/html.go b/internal/render/html.go index 00d7a6e..09e614d 100644 --- a/internal/render/html.go +++ b/internal/render/html.go @@ -9,6 +9,7 @@ import ( "sync" "github.com/pkg/errors" + "github.com/skratchdot/open-golang/open" "github.com/yosssi/ace" ) @@ -29,6 +30,8 @@ const websocketReloader = `` func html(output string, live bool, errCh chan error, wg *sync.WaitGroup) { + opened := false + for { files, err := ioutil.ReadDir(filepath.Join(".", "templates")) if err != nil { @@ -77,10 +80,17 @@ func html(output string, live bool, errCh chan error, wg *sync.WaitGroup) { } w.Close() } - if !live { + + if live { + if !opened { + opened = true + open.Run("output/index.html") + } + } else { wg.Done() return } + <-subscribe() } } diff --git a/internal/render/site.go b/internal/render/site.go index d1fdbd6..b967666 100644 --- a/internal/render/site.go +++ b/internal/render/site.go @@ -8,7 +8,6 @@ import ( "github.com/gorilla/websocket" "github.com/pkg/errors" - "github.com/skratchdot/open-golang/open" "github.com/yosssi/ace" ) @@ -103,10 +102,6 @@ func Build(output string, live bool) error { close(wgCh) }() - if live { - open.Run("output/index.html") - } - select { case <-wgCh: // success