mirror of
https://gitlab.com/pulsechaincom/go-pulse.git
synced 2024-12-24 20:37:17 +00:00
Implemented GUI watchers for rapid reload. Implements #46
This commit is contained in:
parent
0ef7f63729
commit
0cf617ef0c
@ -18,14 +18,16 @@ type AppContainer interface {
|
|||||||
NewBlock(*ethchain.Block)
|
NewBlock(*ethchain.Block)
|
||||||
ObjectChanged(*ethchain.StateObject)
|
ObjectChanged(*ethchain.StateObject)
|
||||||
StorageChanged(*ethchain.StorageState)
|
StorageChanged(*ethchain.StorageState)
|
||||||
|
NewWatcher(chan bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ExtApplication struct {
|
type ExtApplication struct {
|
||||||
*ethpub.PEthereum
|
*ethpub.PEthereum
|
||||||
|
|
||||||
blockChan chan ethutil.React
|
blockChan chan ethutil.React
|
||||||
changeChan chan ethutil.React
|
changeChan chan ethutil.React
|
||||||
quitChan chan bool
|
quitChan chan bool
|
||||||
|
watcherQuitChan chan bool
|
||||||
|
|
||||||
container AppContainer
|
container AppContainer
|
||||||
lib *UiLib
|
lib *UiLib
|
||||||
@ -38,6 +40,7 @@ func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication {
|
|||||||
make(chan ethutil.React, 1),
|
make(chan ethutil.React, 1),
|
||||||
make(chan ethutil.React, 1),
|
make(chan ethutil.React, 1),
|
||||||
make(chan bool),
|
make(chan bool),
|
||||||
|
make(chan bool),
|
||||||
container,
|
container,
|
||||||
lib,
|
lib,
|
||||||
nil,
|
nil,
|
||||||
@ -66,6 +69,8 @@ func (app *ExtApplication) run() {
|
|||||||
reactor := app.lib.eth.Reactor()
|
reactor := app.lib.eth.Reactor()
|
||||||
reactor.Subscribe("newBlock", app.blockChan)
|
reactor.Subscribe("newBlock", app.blockChan)
|
||||||
|
|
||||||
|
app.container.NewWatcher(app.watcherQuitChan)
|
||||||
|
|
||||||
win := app.container.Window()
|
win := app.container.Window()
|
||||||
win.Show()
|
win.Show()
|
||||||
win.Wait()
|
win.Wait()
|
||||||
@ -83,6 +88,7 @@ func (app *ExtApplication) stop() {
|
|||||||
|
|
||||||
// Kill the main loop
|
// Kill the main loop
|
||||||
app.quitChan <- true
|
app.quitChan <- true
|
||||||
|
app.watcherQuitChan <- true
|
||||||
|
|
||||||
close(app.blockChan)
|
close(app.blockChan)
|
||||||
close(app.quitChan)
|
close(app.quitChan)
|
||||||
|
@ -6,6 +6,12 @@ import (
|
|||||||
"github.com/ethereum/eth-go/ethpub"
|
"github.com/ethereum/eth-go/ethpub"
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
"github.com/go-qml/qml"
|
"github.com/go-qml/qml"
|
||||||
|
"github.com/howeyc/fsnotify"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,6 +21,7 @@ type HtmlApplication struct {
|
|||||||
engine *qml.Engine
|
engine *qml.Engine
|
||||||
lib *UiLib
|
lib *UiLib
|
||||||
path string
|
path string
|
||||||
|
watcher *fsnotify.Watcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHtmlApplication(path string, lib *UiLib) *HtmlApplication {
|
func NewHtmlApplication(path string, lib *UiLib) *HtmlApplication {
|
||||||
@ -47,6 +54,59 @@ func (app *HtmlApplication) Create() error {
|
|||||||
return nil
|
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 {
|
func (app *HtmlApplication) Engine() *qml.Engine {
|
||||||
return app.engine
|
return app.engine
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user