This commit is contained in:
zyxkad 2022-08-21 00:13:37 -06:00
parent 78972cd892
commit 4e15525043
No known key found for this signature in database
GPG Key ID: 75D46E883711CD87
5 changed files with 69 additions and 2 deletions

10
build.sh Normal file
View File

@ -0,0 +1,10 @@
#!/bin/bash
cd $(dirname $0)
function _build(){
go generate || exit $?
go build -o "$1" . || exit $?
}
_build ./target/output-self

2
go.mod
View File

@ -3,3 +3,5 @@ module gitee.ghink.com/ghink/omm-client
go 1.18
require github.com/webview/webview v0.0.0-20220816141928-2ee04ccd0530
require github.com/go-chi/chi/v5 v5.0.7 // indirect

2
go.sum
View File

@ -1,2 +1,4 @@
github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/webview/webview v0.0.0-20220816141928-2ee04ccd0530 h1:diPvLFzNaRG1c1Qh8s8jWQt/+l8HQs9iQgHvAV4N8q8=
github.com/webview/webview v0.0.0-20220816141928-2ee04ccd0530/go.mod h1:rpXAuuHgyEJb6kXcXldlkOjU6y4x+YcASKKXJNUhh0Y=

55
main.go
View File

@ -5,22 +5,75 @@ import (
"embed"
"flag"
"fmt"
"io/fs"
"net"
"net/http"
"time"
"github.com/go-chi/chi/v5"
"github.com/webview/webview"
)
//go:generate bash ./omm-front/build.sh
//go:embed all:omm-front/dist
var _dist embed.FS
var dist = func()(fs.FS){
f, err := fs.Sub(_dist, "omm-front/dist")
must(err)
return f
}()
var (
debug bool = false
hostIP string = "127.0.0.1"
)
func init(){
flag.BoolVar(&debug, "debug", false, "Debug flag")
flag.BoolVar(&debug, "debug", debug, "Debug flag")
flag.StringVar(&hostIP, "host", hostIP, "Web app host IP")
flag.Parse()
}
func makeRouter()(r *chi.Mux){
r = chi.NewRouter()
r.Handle("/W/*", http.StripPrefix("/W", http.FileServer(http.FS(dist))))
return
}
func main(){
listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.ParseIP(hostIP)})
must(err)
addr := listener.Addr().(*net.TCPAddr)
if debug {
fmt.Println("Server addr:", addr.String())
}
webRouter := makeRouter()
go func(){
svr := &http.Server{
Handler: webRouter,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
if err := svr.Serve(listener); err != nil {
panic(err)
}
}()
win := webview.New(debug)
defer win.Destroy()
win.SetTitle(fmt.Sprintf("Oh my mailbox v%s", VERSION))
win.SetSize(950, 600, webview.HintNone)
navuri := "http://" + addr.String() + "/W/"
if debug {
fmt.Println("Navigate url:", navuri)
}
win.Navigate(navuri)
win.Run()
}
func must(err error){
if err != nil {
panic(err)
}
}

@ -1 +1 @@
Subproject commit 3f84d0a2c55a4b80c0c60377bb2b9fbb4fd800b7
Subproject commit e72b1540a5dc50f3a08d3b0abb2d580f371712ea