Updated. /JL
Some checks are pending
Go / build (1.19.x) (push) Waiting to run
Go / build (1.20.x) (push) Waiting to run

This commit is contained in:
Jan Lerking
2024-04-23 09:37:58 +02:00
parent 0ef7f49b80
commit 4831dcc0d9
3 changed files with 20 additions and 15 deletions

6
go.mod
View File

@@ -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

2
go.sum
View File

@@ -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=

27
main.go
View File

@@ -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()
}