From bb10a6da5835bcfffa40ee00ba48ce3208df3e6b Mon Sep 17 00:00:00 2001 From: Roland Singer Date: Mon, 6 May 2019 12:32:41 +0200 Subject: [PATCH] added new search paths and initial code for ExecDev --- gml.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 1 + go.sum | 2 ++ 3 files changed, 55 insertions(+) diff --git a/gml.go b/gml.go index bc67eac..a10e0a2 100644 --- a/gml.go +++ b/gml.go @@ -50,6 +50,9 @@ func init() { if err != nil { log.Fatalf("gml: failed to create global application: %v", err) } + + SetSearchPaths("qml", []string{":/qml"}) + SetSearchPaths("res", []string{":/resources"}) } // Must exits the application with a fatal log if the error is present. @@ -127,3 +130,52 @@ func SetSearchPaths(prefix string, searchPaths []string) { C.gml_global_set_search_paths(prefixC, pathsC, C.int(len(searchPaths))) } + +/* +func ExecDev(basePath, url string) (retCode int, err error) { + AddImportPath(basePath) + + w := watcher.New() + w.SetMaxEvents(1) + + go func() { + for { + select { + case event := <-w.Event: + RunMain(func() { + fmt.Println(event) // Print the event's info. TODO: log + gapp.ClearComponentCache() + }) + + case err := <-w.Error: + log.Println("dev file watcher error: %v", err) + + case <-w.Closed: + return + } + } + }() + + err = w.AddRecursive(filepath.Join(basePath, "qml")) + if err != nil { + return + } + + go func() { + err := w.Start(time.Millisecond * 250) + if err != nil { + log.Println("dev file watcher failed: %v", err) + } + }() + + return Exec(url) +} + +func ExecDevExit(basePath, url string) { + ret, err := ExecDev(basePath, url) + if err != nil { + fmt.Println(err) + } + os.Exit(ret) +} +*/ diff --git a/go.mod b/go.mod index e241fb3..8afaf3e 100644 --- a/go.mod +++ b/go.mod @@ -9,5 +9,6 @@ require ( github.com/json-iterator/go v1.1.6 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.1 // indirect + github.com/radovskyb/watcher v1.0.6 golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a ) diff --git a/go.sum b/go.sum index 9cf09c0..8d64869 100644 --- a/go.sum +++ b/go.sum @@ -29,6 +29,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/radovskyb/watcher v1.0.6 h1:8WIQ9UxEYMZjem1OwU7dVH94DXXk9mAIE1i8eqHD+IY= +github.com/radovskyb/watcher v1.0.6/go.mod h1:78okwvY5wPdzcb1UYnip1pvrZNIVEIh/Cm+ZuvsUYIg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a h1:Igim7XhdOpBnWPuYJ70XcNpq8q3BCACtVgNfoJxOV7g=