Skip to content

Commit

Permalink
added helper functions to download geoweaver, open browser and close …
Browse files Browse the repository at this point in the history
…geoweaver
  • Loading branch information
gokulprathin8 committed Mar 24, 2024
1 parent 4c2cea0 commit 0b3dbb2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
22 changes: 22 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/getlantern/systray"
"image/png"
"os"
"path/filepath"
)

var serverStarted bool = false
Expand Down Expand Up @@ -91,25 +92,46 @@ func onReady() {
systray.Quit()
}()

// handle server start and stop
go func() {
for {
<-startServer.ClickedCh
fmt.Print(startServer, serverStarted)
if serverStarted {
startServer.SetTitle("Start server")
serverStarted = false
err := utils.KillGeoweaverProcesses()
if err != nil {
panic("Failed to stop geoweaver server")
}
} else {
startServer.SetTitle("Stop server")
serverStarted = true
homeDir, _ := os.UserHomeDir()
err := utils.DownloadFile(utils.GEOWEAVER_JAR_URL, homeDir)
if err != nil {
panic("Unable to download file")
} else {
geoweaverJarPath := filepath.Join(homeDir, "geoweaver.jar")
err := utils.RunJavaJar(geoweaverJarPath)
if err != nil {
panic("Failed to start geoweaver jar file")
}
}
}
}
}()

// handle URL open
go func() {
for {
<-openBrowser.ClickedCh
err := utils.OpenURLInBrowser("http:https://localhost:8070/Geoweaver")
if err != nil {
panic("Failed to open browser")
}
}
}()
}

func onExit() {
Expand Down
16 changes: 16 additions & 0 deletions utils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
)

Expand Down Expand Up @@ -57,3 +58,18 @@ func RunJavaJar(jarPath string) error {
cmd.Dir = filepath.Dir(jarPath)
return cmd.Run()
}

func OpenURLInBrowser(url string) error {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = exec.Command("xdg-open", url).Start() // Fallback for other UNIX-like OSes
}
return err
}

0 comments on commit 0b3dbb2

Please sign in to comment.