v0.1.0
This commit is contained in:
parent
78972cd892
commit
4e15525043
10
build.sh
Normal file
10
build.sh
Normal 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
2
go.mod
@ -3,3 +3,5 @@ module gitee.ghink.com/ghink/omm-client
|
|||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
require github.com/webview/webview v0.0.0-20220816141928-2ee04ccd0530
|
require github.com/webview/webview v0.0.0-20220816141928-2ee04ccd0530
|
||||||
|
|
||||||
|
require github.com/go-chi/chi/v5 v5.0.7 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -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 h1:diPvLFzNaRG1c1Qh8s8jWQt/+l8HQs9iQgHvAV4N8q8=
|
||||||
github.com/webview/webview v0.0.0-20220816141928-2ee04ccd0530/go.mod h1:rpXAuuHgyEJb6kXcXldlkOjU6y4x+YcASKKXJNUhh0Y=
|
github.com/webview/webview v0.0.0-20220816141928-2ee04ccd0530/go.mod h1:rpXAuuHgyEJb6kXcXldlkOjU6y4x+YcASKKXJNUhh0Y=
|
||||||
|
55
main.go
55
main.go
@ -5,22 +5,75 @@ import (
|
|||||||
"embed"
|
"embed"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/webview/webview"
|
"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 (
|
var (
|
||||||
debug bool = false
|
debug bool = false
|
||||||
|
hostIP string = "127.0.0.1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init(){
|
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()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makeRouter()(r *chi.Mux){
|
||||||
|
r = chi.NewRouter()
|
||||||
|
r.Handle("/W/*", http.StripPrefix("/W", http.FileServer(http.FS(dist))))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func main(){
|
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)
|
win := webview.New(debug)
|
||||||
defer win.Destroy()
|
defer win.Destroy()
|
||||||
win.SetTitle(fmt.Sprintf("Oh my mailbox v%s", VERSION))
|
win.SetTitle(fmt.Sprintf("Oh my mailbox v%s", VERSION))
|
||||||
win.SetSize(950, 600, webview.HintNone)
|
win.SetSize(950, 600, webview.HintNone)
|
||||||
|
navuri := "http://" + addr.String() + "/W/"
|
||||||
|
if debug {
|
||||||
|
fmt.Println("Navigate url:", navuri)
|
||||||
|
}
|
||||||
|
win.Navigate(navuri)
|
||||||
win.Run()
|
win.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func must(err error){
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 3f84d0a2c55a4b80c0c60377bb2b9fbb4fd800b7
|
Subproject commit e72b1540a5dc50f3a08d3b0abb2d580f371712ea
|
Loading…
x
Reference in New Issue
Block a user