diff --git a/go.mod b/go.mod index ded22db..5b7ca3d 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,3 @@ -module template +module test-web-app -go 1.20 - -require github.com/webview/webview v0.0.0-20240422163931-93be13a101e5 // indirect +go 1.22 diff --git a/go.sum b/go.sum index 2b1bcba..e69de29 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +0,0 @@ -github.com/webview/webview v0.0.0-20240422163931-93be13a101e5 h1:YeAdzszxZAIYebts/ZGyJjEXCpQWv+XCJm/4F3QNQDE= -github.com/webview/webview v0.0.0-20240422163931-93be13a101e5/go.mod h1:Zk81X+8/mp/MNoeJXXK4Noydn8pcea09e00dFfAwrxg= diff --git a/main.go b/main.go index 540d64a..02f811a 100644 --- a/main.go +++ b/main.go @@ -6,10 +6,24 @@ import ( "io" "net/http" "os" - - "github.com/webview/webview" + "os/exec" + "runtime" ) +func openBrowser(url string) bool { + var args []string + switch runtime.GOOS { + case "darwin": + args = []string{"open"} + case "windows": + args = []string{"cmd", "/c", "start", "chrome"} + default: + args = []string{"xdg-open"} + } + cmd := exec.Command(args[0], append(args[1:], url)...) + return cmd.Start() == nil +} + func getRoot(w http.ResponseWriter, r *http.Request) { fmt.Printf("got / request\n") io.WriteString(w, "Welcome to TimeCard!\n") @@ -20,6 +34,8 @@ func getHello(w http.ResponseWriter, r *http.Request) { } func main() { + openBrowser("127.0.0.10:3333") + mux := http.NewServeMux() mux.HandleFunc("/", getRoot) mux.HandleFunc("/hello", getHello) @@ -31,11 +47,4 @@ func main() { fmt.Printf("error starting server: %s\n", err) os.Exit(1) } - - w := webview.New(false) - defer w.Destroy() - w.SetTitle("Basic Example") - w.SetSize(480, 320, webview.HintNone) - w.SetHtml("Thanks for using webview!") - w.Run() }