-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.go
56 lines (43 loc) · 963 Bytes
/
main.go
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
package main
import (
"fmt"
"macMineable/lib"
"net/http"
"os"
"path/filepath"
"time"
"github.com/2nthony/webview"
)
const (
hostIP = "127.0.0.1"
hostPort = "47261" // Fixed http port because client-side uses `localstorage`
)
func main() {
runApp()
}
func runApp() {
// start: make the root dir is the `Resources`, global effected!
ep, err := os.Executable()
if err != nil {
fmt.Println("os.Executable:", err)
}
err = os.Chdir(filepath.Join(filepath.Dir(ep), "..", "Resources"))
if err != nil {
fmt.Println("os.Chdir:", err)
}
// end
w := webview.New(true)
defer w.Destroy()
lib.RegisterIPCEvents(w)
w.SetTitle("macMineable")
w.SetSize(400, 650, webview.HintFixed)
createServer()
w.Navigate(fmt.Sprintf("http://%s:%s?%d", hostIP, hostPort, time.Now().UnixMilli()))
w.Run()
}
func createServer() {
lib.RegisterRoutes()
go func() {
fmt.Println(http.ListenAndServe(fmt.Sprintf("%s:%s", hostIP, hostPort), nil))
}()
}