-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (38 loc) · 1.25 KB
/
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
package main
import (
"net/url"
"path/filepath"
"github.com/promignis/knack/bridge"
"github.com/promignis/knack/constants"
"github.com/promignis/knack/fs"
"github.com/promignis/knack/utils"
"github.com/zserge/webview"
)
func main() {
root := utils.GetRootPath()
// scope them in state
// to prevent name clashes
filepath.Walk(filepath.Join(root, constants.ViewFolder), fs.AddFileToState)
filepath.Walk(filepath.Join(root, constants.RuntimeJsPath), fs.AddFileToState)
filepath.Walk(filepath.Join(root, constants.JsFolder), fs.AddFileToState)
filepath.Walk(filepath.Join(root, constants.CssFolder), fs.AddFileToState)
filepath.Walk(filepath.Join(root, constants.ImageFoler), fs.AddFileToState)
if indexView, ok := fs.FileState[constants.DefaultIndexFile]; ok {
w := webview.New(webview.Settings{
URL: `data:text/html,` + url.PathEscape(indexView.StringData()),
ExternalInvokeCallback: bridge.HandleRPC,
Debug: true,
Resizable: true,
})
// race condition happening
if runtimeJs, ok := fs.FileState[constants.RuntimeJsFile]; ok {
bridge.RunJsInWebview(w, runtimeJs.StringData())
} else {
panic("Failed to load runtime.js")
}
defer w.Exit()
w.Run()
} else {
panic("File index.html has to be present in views folder")
}
}