Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Kelp UI: use github.com/pkg/browser to call cross-platform OpenURL fu…
Browse files Browse the repository at this point in the history
…nction (#397)
  • Loading branch information
nikhilsaraf authored Apr 7, 2020
1 parent 9f9ab96 commit 8729754
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions cmd/server_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 8729754

Please sign in to comment.