2014-04-29 23:44:02 +00:00
|
|
|
package ethui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"github.com/ethereum/eth-go/ethchain"
|
2014-05-02 11:55:58 +00:00
|
|
|
"github.com/ethereum/eth-go/ethpub"
|
2014-04-29 23:44:02 +00:00
|
|
|
"github.com/ethereum/eth-go/ethutil"
|
|
|
|
"github.com/go-qml/qml"
|
|
|
|
"math/big"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
type HtmlApplication struct {
|
|
|
|
win *qml.Window
|
|
|
|
webView qml.Object
|
|
|
|
engine *qml.Engine
|
|
|
|
lib *UiLib
|
|
|
|
path string
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHtmlApplication(path string, lib *UiLib) *HtmlApplication {
|
|
|
|
engine := qml.NewEngine()
|
|
|
|
|
|
|
|
return &HtmlApplication{engine: engine, lib: lib, path: path}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *HtmlApplication) Create() error {
|
|
|
|
component, err := app.engine.LoadFile(app.lib.AssetPath("qml/webapp.qml"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if filepath.Ext(app.path) == "eth" {
|
|
|
|
return errors.New("Ethereum package not yet supported")
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
ethutil.OpenPackage(app.path)
|
|
|
|
}
|
|
|
|
|
|
|
|
win := component.CreateWindow(nil)
|
|
|
|
win.Set("url", app.path)
|
|
|
|
webView := win.ObjectByName("webView")
|
|
|
|
|
|
|
|
app.win = win
|
|
|
|
app.webView = webView
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *HtmlApplication) Engine() *qml.Engine {
|
|
|
|
return app.engine
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *HtmlApplication) Window() *qml.Window {
|
|
|
|
return app.win
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *HtmlApplication) NewBlock(block *ethchain.Block) {
|
2014-05-02 11:55:58 +00:00
|
|
|
b := ðpub.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())}
|
2014-04-29 23:44:02 +00:00
|
|
|
app.webView.Call("onNewBlockCb", b)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *HtmlApplication) ObjectChanged(stateObject *ethchain.StateObject) {
|
2014-05-02 11:55:58 +00:00
|
|
|
app.webView.Call("onObjectChangeCb", ethpub.NewPStateObject(stateObject))
|
2014-04-29 23:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (app *HtmlApplication) StorageChanged(stateObject *ethchain.StateObject, addr []byte, value *big.Int) {
|
|
|
|
app.webView.Call("onStorageChangeCb", nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *HtmlApplication) Destroy() {
|
|
|
|
app.engine.Destroy()
|
|
|
|
}
|