2019-12-13 22:06:18 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/kataras/iris/v12"
|
2020-07-24 12:03:49 +02:00
|
|
|
"github.com/webview/webview"
|
2019-12-13 22:06:18 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const addr = "127.0.0.1:8080"
|
|
|
|
|
|
|
|
/*
|
|
|
|
# Windows requires special linker flags for GUI apps.
|
|
|
|
# It's also recommended to use TDM-GCC-64 compiler for CGo.
|
|
|
|
# http://tdm-gcc.tdragon.net/download
|
|
|
|
#
|
|
|
|
#
|
2021-02-19 07:49:15 +01:00
|
|
|
$ go build -mod=mod -ldflags="-H windowsgui" -o myapp.exe # build for windows
|
2019-12-13 22:06:18 +01:00
|
|
|
$ ./myapp.exe # run
|
|
|
|
#
|
2022-01-08 18:54:33 +01:00
|
|
|
# MacOS uses app bundles for GUI apps
|
|
|
|
$ mkdir -p example.app/Contents/MacOS
|
|
|
|
$ go build -o example.app/Contents/MacOS/example
|
|
|
|
$ open example.app # Or click on the app in Finder
|
2019-12-13 22:06:18 +01:00
|
|
|
#
|
|
|
|
# Note: if you see "use option -std=c99 or -std=gnu99 to compile your code"
|
2020-07-24 12:03:49 +02:00
|
|
|
# please refer to: https://github.com/webview/webview/issues/188
|
2019-12-13 22:06:18 +01:00
|
|
|
*/
|
|
|
|
func main() {
|
|
|
|
go runServer()
|
|
|
|
showAndWaitWindow()
|
|
|
|
}
|
|
|
|
|
|
|
|
func runServer() {
|
|
|
|
app := iris.New()
|
|
|
|
app.Get("/", func(ctx iris.Context) {
|
2022-01-08 18:54:33 +01:00
|
|
|
ctx.HTML("<h1>Hello Desktop</h1>")
|
2019-12-13 22:06:18 +01:00
|
|
|
})
|
2020-03-05 21:41:27 +01:00
|
|
|
app.Listen(addr)
|
2019-12-13 22:06:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func showAndWaitWindow() {
|
2020-04-08 19:04:56 +02:00
|
|
|
debug := true
|
2022-01-08 18:54:33 +01:00
|
|
|
|
2020-04-08 19:04:56 +02:00
|
|
|
w := webview.New(debug)
|
|
|
|
defer w.Destroy()
|
|
|
|
w.SetTitle("Minimal webview example")
|
|
|
|
w.SetSize(800, 600, webview.HintNone)
|
2022-01-08 18:54:33 +01:00
|
|
|
w.Navigate("http://" + addr)
|
2020-04-08 19:04:56 +02:00
|
|
|
w.Run()
|
2019-12-13 22:06:18 +01:00
|
|
|
}
|