-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
115 lines (101 loc) · 2.2 KB
/
main.go
File metadata and controls
115 lines (101 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main
import (
"log"
"net"
"bytes"
"io"
"net/http"
"mime"
"path/filepath"
"github.com/zserge/webview"
)
// Counter is a simple example of automatic Go-to-JS data binding
type Counter struct {
Value int `json:"value"`
}
// Add increases the value of a counter by n
func (c *Counter) Add(n int) {
c.Value = c.Value + int(n)
}
// Reset sets the value of a counter back to zero
func (c *Counter) Reset() {
c.Value = 0
}
// func runLocalHTTP() {
// ln, err := net.Listen("tcp", "127.0.0.1:0")
// if err != nil {
// log.Fatal(err)
// }
// go func() {
// defer ln.Close()
// http.Handle("/", http.FileServer(assetFS()))
// log.Fatal(http.Serve(ln, nil))
// }()
// url := "http://" + ln.Addr().String() + "/index.html"
// w := webview.New(webview.Settings{
// Title: "Loaded: " + url,
// URL: url,
// })
// defer w.Exit()
// w.Run()
// }
func startServer() string {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
log.Fatal(err)
}
go func() {
defer ln.Close()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
if len(path) > 0 && path[0] == '/' {
path = path[1:]
}
if path == "" {
path = "index.html"
}
if bs, err := Asset(path); err != nil {
w.WriteHeader(http.StatusNotFound)
} else {
w.Header().Add("Content-Type", mime.TypeByExtension(filepath.Ext(path)))
io.Copy(w, bytes.NewBuffer(bs))
}
})
log.Fatal(http.Serve(ln, nil))
}()
return "http://" + ln.Addr().String()
}
func main() {
url := startServer()
//---------------------------------
// Webview
//---------------------------------
w := webview.New(webview.Settings{
Width: 320,
Height: 480,
Title: "Todo App",
URL: url,
})
defer w.Exit()
go func() {
w.Eval(string(MustAsset("index.html")))
}()
//---------------------------------
// Lorca
//---------------------------------
// w, _ := lorca.New(url,"",1200,880)
//defer w.Close()
//<-w.Done()
}
//func main() {
// w := webview.New(webview.Settings{
// Title: "Nuxt Sample ",
// })
// defer w.Exit()
// w.Dispatch(func() {
// // Inject controller
// w.Bind("counter", &Counter{})
// w.Eval(string(MustAsset("index.html")))
// })
// w.Run()
//}