aboutsummaryrefslogtreecommitdiffstats
path: root/ethereal/ui/html_container.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-05-20 23:09:26 +0800
committerobscuren <geffobscura@gmail.com>2014-05-20 23:09:26 +0800
commitc07c454935609bfb0f65dc38bb596a90d5493fbb (patch)
treeb8d4ffc72b06bcd60d6f61de70bea8b680ed8333 /ethereal/ui/html_container.go
parent942f552c620471602326c1ded54095c1cf41ed76 (diff)
parent34014c1c516ea03b28e56db1a0478087d2416f74 (diff)
downloaddexon-c07c454935609bfb0f65dc38bb596a90d5493fbb.tar
dexon-c07c454935609bfb0f65dc38bb596a90d5493fbb.tar.gz
dexon-c07c454935609bfb0f65dc38bb596a90d5493fbb.tar.bz2
dexon-c07c454935609bfb0f65dc38bb596a90d5493fbb.tar.lz
dexon-c07c454935609bfb0f65dc38bb596a90d5493fbb.tar.xz
dexon-c07c454935609bfb0f65dc38bb596a90d5493fbb.tar.zst
dexon-c07c454935609bfb0f65dc38bb596a90d5493fbb.zip
Merge branch 'release/poc5-rc7'
Diffstat (limited to 'ethereal/ui/html_container.go')
-rw-r--r--ethereal/ui/html_container.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/ethereal/ui/html_container.go b/ethereal/ui/html_container.go
index 4f12aaaf6..3867c0353 100644
--- a/ethereal/ui/html_container.go
+++ b/ethereal/ui/html_container.go
@@ -6,6 +6,12 @@ import (
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethutil"
"github.com/go-qml/qml"
+ "github.com/howeyc/fsnotify"
+ "io/ioutil"
+ "log"
+ "net/url"
+ "os"
+ "path"
"path/filepath"
)
@@ -15,6 +21,7 @@ type HtmlApplication struct {
engine *qml.Engine
lib *UiLib
path string
+ watcher *fsnotify.Watcher
}
func NewHtmlApplication(path string, lib *UiLib) *HtmlApplication {
@@ -47,6 +54,59 @@ func (app *HtmlApplication) Create() error {
return nil
}
+func (app *HtmlApplication) RootFolder() string {
+ folder, err := url.Parse(app.path)
+ if err != nil {
+ return ""
+ }
+ return path.Dir(folder.RequestURI())
+}
+func (app *HtmlApplication) RecursiveFolders() []os.FileInfo {
+ files, _ := ioutil.ReadDir(app.RootFolder())
+ var folders []os.FileInfo
+ for _, file := range files {
+ if file.IsDir() {
+ folders = append(folders, file)
+ }
+ }
+ return folders
+}
+
+func (app *HtmlApplication) NewWatcher(quitChan chan bool) {
+ var err error
+
+ app.watcher, err = fsnotify.NewWatcher()
+ if err != nil {
+ return
+ }
+ err = app.watcher.Watch(app.RootFolder())
+ if err != nil {
+ log.Fatal(err)
+ }
+ for _, folder := range app.RecursiveFolders() {
+ fullPath := app.RootFolder() + "/" + folder.Name()
+ app.watcher.Watch(fullPath)
+ }
+
+ go func() {
+ out:
+ for {
+ select {
+ case <-quitChan:
+ app.watcher.Close()
+ break out
+ case <-app.watcher.Event:
+ //ethutil.Config.Log.Debugln("Got event:", ev)
+ app.webView.Call("reload")
+ case err := <-app.watcher.Error:
+ // TODO: Do something here
+ ethutil.Config.Log.Infoln("Watcher error:", err)
+ }
+ }
+ }()
+
+}
+
func (app *HtmlApplication) Engine() *qml.Engine {
return app.engine
}