From 8729754b4df07e2c0db537780a1dd41c90e44b09 Mon Sep 17 00:00:00 2001 From: Nikhil Saraf <1028334+nikhilsaraf@users.noreply.github.com> Date: Tue, 7 Apr 2020 19:40:26 +0530 Subject: [PATCH] Kelp UI: use github.com/pkg/browser to call cross-platform OpenURL function (#397) --- cmd/server_amd64.go | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/cmd/server_amd64.go b/cmd/server_amd64.go index df6d5220d..0fd89a091 100644 --- a/cmd/server_amd64.go +++ b/cmd/server_amd64.go @@ -23,6 +23,7 @@ import ( "github.com/go-chi/chi" "github.com/go-chi/chi/middleware" "github.com/nikhilsaraf/go-tools/multithreading" + "github.com/pkg/browser" "github.com/rs/cors" "github.com/spf13/cobra" "github.com/stellar/go/clients/horizonclient" @@ -172,7 +173,7 @@ func init() { // local mode (non --dev) and release binary should open browser (since --dev already opens browser via yarn and returns) go func() { if *options.noElectron { - openBrowser(kos, appURL, openBrowserWg) + openBrowser(appURL, openBrowserWg) } else { openElectron(trayIconPathNative, electronURL) } @@ -531,22 +532,11 @@ func getCurrentDirUnix() (string, error) { return strings.TrimSpace(string(outputBytes)), nil } -func openBrowser(kos *kelpos.KelpOS, url string, openBrowserWg *sync.WaitGroup) { +func openBrowser(url string, openBrowserWg *sync.WaitGroup) { log.Printf("opening URL in native browser: %s", url) - - var browserCmd string - if runtime.GOOS == "linux" { - browserCmd = fmt.Sprintf("xdg-open %s", url) - } else if runtime.GOOS == "darwin" { - browserCmd = fmt.Sprintf("open %s", url) - } else if runtime.GOOS == "windows" { - browserCmd = fmt.Sprintf("start %s", url) - } else { - log.Fatalf("unable to open url '%s' in browser because runtime.GOOS was unrecognized: %s", url, runtime.GOOS) - } - openBrowserWg.Wait() - _, e := kos.Blocking("browser", browserCmd) + + e := browser.OpenURL(url) if e != nil { log.Fatal(e) }