aboutsummaryrefslogtreecommitdiffstats
path: root/ethereal/ui/html_container.go
blob: e3e48bfcc6e1d508bba34b7a840242d2a5f030fd (plain) (blame)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package ethui

import (
    "errors"
    "github.com/ethereum/eth-go/ethchain"
    "github.com/ethereum/eth-go/ethpub"
    "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) {
    b := &ethpub.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())}
    app.webView.Call("onNewBlockCb", b)
}

func (app *HtmlApplication) ObjectChanged(stateObject *ethchain.StateObject) {
    app.webView.Call("onObjectChangeCb", ethpub.NewPStateObject(stateObject))
}

func (app *HtmlApplication) StorageChanged(stateObject *ethchain.StateObject, addr []byte, value *big.Int) {
    app.webView.Call("onStorageChangeCb", nil)
}

func (app *HtmlApplication) Destroy() {
    app.engine.Destroy()
}