Skip to content

Commit

Permalink
Merge pull request #97 from clidey/main
Browse files Browse the repository at this point in the history
[FR] Add support for opening browser when running whodb
  • Loading branch information
hkdeman authored Aug 22, 2024
2 parents 9d72640 + 110a386 commit 7cc8500
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Or checkout our [demo video](https://youtu.be/hnAQcYYzcLo)

## Documentation

For more detailed information, check out our [Documentation README](/docs/docs.md)
For more detailed information, check out our [Documentation.](https://whodb.clidey.com/docs/)

<div style="width:100%;border-bottom:0.5px solid white;margin:50px 0px;"></div>

Expand Down
4 changes: 4 additions & 0 deletions core/src/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func InitializeRouter(staticFiles embed.FS) {
log.Logger.Infof("http://0.0.0.0:%s", port)
log.Logger.Info("Explore and enjoy working with your databases!")

if !isDocker() {
openBrowser(fmt.Sprintf("http://localhost:%v", port))
}

if err := http.ListenAndServe(fmt.Sprintf(":%v", port), router); err != nil {
panic(err)
}
Expand Down
31 changes: 31 additions & 0 deletions core/src/router/task.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package router

import (
"os"
"os/exec"
"runtime"

"github.com/clidey/whodb/core/src/log"
)

func openBrowser(url string) {
var err error
switch runtime.GOOS {
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
case "linux":
err = exec.Command("xdg-open", url).Start()
default:
log.Logger.Warnf("Unsupported platform. Please open the URL manually: %s\n", url)
}
if err != nil {
log.Logger.Warnf("Failed to open browser: %v\n", err)
}
}

func isDocker() bool {
_, err := os.Stat("/.dockerenv")
return !os.IsNotExist(err)
}

0 comments on commit 7cc8500

Please sign in to comment.