remove jsre from mist

This commit is contained in:
zelig 2015-03-15 13:18:58 +07:00
parent da44097800
commit 31ffca6d8a
4 changed files with 63 additions and 193 deletions

View File

@ -12,7 +12,7 @@ import "../ext/http.js" as Http
ApplicationWindow { ApplicationWindow {
id: root id: root
//flags: Qt.FramelessWindowHint //flags: Qt.FramelessWindowHint
// Use this to make the window frameless. But then you'll need to do move and resize by hand // Use this to make the window frameless. But then you'll need to do move and resize by hand
@ -53,7 +53,7 @@ ApplicationWindow {
whisperTab.view.url = "http://ethereum-dapp-whisper-client.meteor.com/"; whisperTab.view.url = "http://ethereum-dapp-whisper-client.meteor.com/";
whisperTab.menuItem.title = "Whisper Chat"; whisperTab.menuItem.title = "Whisper Chat";
*/ */
addPlugin("./views/wallet.qml", {noAdd: true, close: false, section: "legacy"}); addPlugin("./views/wallet.qml", {noAdd: true, close: false, section: "legacy"});
addPlugin("./views/transaction.qml", {noAdd: true, close: false, section: "legacy"}); addPlugin("./views/transaction.qml", {noAdd: true, close: false, section: "legacy"});
addPlugin("./views/whisper.qml", {noAdd: true, close: false, section: "legacy"}); addPlugin("./views/whisper.qml", {noAdd: true, close: false, section: "legacy"});
addPlugin("./views/chain.qml", {noAdd: true, close: false, section: "legacy"}); addPlugin("./views/chain.qml", {noAdd: true, close: false, section: "legacy"});
@ -126,7 +126,7 @@ ApplicationWindow {
} }
function newBrowserTab(url) { function newBrowserTab(url) {
var urlMatches = url.toString().match(/^[a-z]*\:\/\/([^\/?#]+)(?:[\/?#]|$)/i); var urlMatches = url.toString().match(/^[a-z]*\:\/\/([^\/?#]+)(?:[\/?#]|$)/i);
var requestedDomain = urlMatches && urlMatches[1]; var requestedDomain = urlMatches && urlMatches[1];
@ -138,17 +138,17 @@ ApplicationWindow {
var existingDomain = matches && matches[1]; var existingDomain = matches && matches[1];
if (requestedDomain == existingDomain) { if (requestedDomain == existingDomain) {
domainAlreadyOpen = true; domainAlreadyOpen = true;
if (mainSplit.views[i].view.url != url){ if (mainSplit.views[i].view.url != url){
mainSplit.views[i].view.url = url; mainSplit.views[i].view.url = url;
} }
activeView(mainSplit.views[i].view, mainSplit.views[i].menuItem); activeView(mainSplit.views[i].view, mainSplit.views[i].menuItem);
} }
} }
} }
if (!domainAlreadyOpen) { if (!domainAlreadyOpen) {
var window = addPlugin("./views/browser.qml", {noAdd: true, close: true, section: "apps", active: true}); var window = addPlugin("./views/browser.qml", {noAdd: true, close: true, section: "apps", active: true});
window.view.url = url; window.view.url = url;
window.menuItem.title = "Mist"; window.menuItem.title = "Mist";
@ -158,105 +158,6 @@ ApplicationWindow {
menuBar: MenuBar {
Menu {
title: "File"
MenuItem {
text: "New tab"
shortcut: "Ctrl+t"
onTriggered: {
activeView(catalog.view, catalog.menuItem);
}
}
MenuSeparator {}
MenuItem {
text: "Import key"
shortcut: "Ctrl+i"
onTriggered: {
generalFileDialog.show(true, function(path) {
gui.importKey(path)
})
}
}
MenuItem {
text: "Export keys"
shortcut: "Ctrl+e"
onTriggered: {
generalFileDialog.show(false, function(path) {
})
}
}
MenuItem {
text: "Generate key"
shortcut: "Ctrl+k"
onTriggered: gui.generateKey()
}
}
Menu {
title: "Developer"
MenuItem {
text: "Import Tx"
onTriggered: {
txImportDialog.visible = true
}
}
MenuItem {
text: "Run JS file"
onTriggered: {
generalFileDialog.show(true, function(path) {
eth.evalJavascriptFile(path)
})
}
}
MenuItem {
text: "Dump state"
onTriggered: {
generalFileDialog.show(false, function(path) {
// Empty hash for latest
gui.dumpState("", path)
})
}
}
MenuSeparator {}
}
Menu {
title: "Network"
MenuItem {
text: "Add Peer"
shortcut: "Ctrl+p"
onTriggered: {
addPeerWin.visible = true
}
}
MenuItem {
text: "Show Peers"
shortcut: "Ctrl+e"
onTriggered: {
peerWindow.visible = true
}
}
}
Menu {
title: "Help"
MenuItem {
text: "About"
onTriggered: {
aboutWin.visible = true
}
}
}
}
property var blockModel: ListModel { property var blockModel: ListModel {
id: blockModel id: blockModel
@ -313,28 +214,28 @@ ApplicationWindow {
Layout.minimumWidth: 192 Layout.minimumWidth: 192
Layout.maximumWidth: 192 Layout.maximumWidth: 192
FontLoader { FontLoader {
id: sourceSansPro id: sourceSansPro
source: "fonts/SourceSansPro-Regular.ttf" source: "fonts/SourceSansPro-Regular.ttf"
} }
FontLoader { FontLoader {
source: "fonts/SourceSansPro-Semibold.ttf" source: "fonts/SourceSansPro-Semibold.ttf"
} }
FontLoader { FontLoader {
source: "fonts/SourceSansPro-Bold.ttf" source: "fonts/SourceSansPro-Bold.ttf"
} }
FontLoader { FontLoader {
source: "fonts/SourceSansPro-Black.ttf" source: "fonts/SourceSansPro-Black.ttf"
} }
FontLoader { FontLoader {
source: "fonts/SourceSansPro-Light.ttf" source: "fonts/SourceSansPro-Light.ttf"
} }
FontLoader { FontLoader {
source: "fonts/SourceSansPro-ExtraLight.ttf" source: "fonts/SourceSansPro-ExtraLight.ttf"
} }
FontLoader { FontLoader {
id: simpleLineIcons id: simpleLineIcons
source: "fonts/Simple-Line-Icons.ttf" source: "fonts/Simple-Line-Icons.ttf"
} }
Rectangle { Rectangle {
@ -393,7 +294,7 @@ ApplicationWindow {
function setSelection(on) { function setSelection(on) {
sel.visible = on sel.visible = on
if (this.closable == true) { if (this.closable == true) {
closeIcon.visible = on closeIcon.visible = on
} }
@ -404,7 +305,7 @@ ApplicationWindow {
label.visible = !on label.visible = !on
buttonLabel.visible = on buttonLabel.visible = on
} }
width: 192 width: 192
height: 55 height: 55
color: "#00000000" color: "#00000000"
@ -417,7 +318,7 @@ ApplicationWindow {
Rectangle { Rectangle {
// New App Button // New App Button
id: newAppButton id: newAppButton
visible: false visible: false
anchors.fill: parent anchors.fill: parent
anchors.rightMargin: 8 anchors.rightMargin: 8
border.width: 0 border.width: 0
@ -504,16 +405,16 @@ ApplicationWindow {
id: buttonLabel id: buttonLabel
visible: false visible: false
text: "GO TO NEW APP" text: "GO TO NEW APP"
font.family: sourceSansPro.name font.family: sourceSansPro.name
font.weight: Font.DemiBold font.weight: Font.DemiBold
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
color: "#AAA0A0" color: "#AAA0A0"
} }
Text { Text {
id: label id: label
font.family: sourceSansPro.name font.family: sourceSansPro.name
font.weight: Font.DemiBold font.weight: Font.DemiBold
elide: Text.ElideRight elide: Text.ElideRight
x:250 x:250
@ -529,15 +430,15 @@ ApplicationWindow {
} }
} }
Text { Text {
id: secondary id: secondary
//only shows secondary title if there's no badge //only shows secondary title if there's no badge
visible: (badgeContent == "icon" || badgeContent == "number" )? false : true visible: (badgeContent == "icon" || badgeContent == "number" )? false : true
font.family: sourceSansPro.name font.family: sourceSansPro.name
font.weight: Font.Light font.weight: Font.Light
anchors { anchors {
left: icon.right left: icon.right
@ -566,8 +467,8 @@ ApplicationWindow {
} }
Text { Text {
font.family: simpleLineIcons.name font.family: simpleLineIcons.name
anchors { anchors {
centerIn: parent centerIn: parent
} }
@ -575,11 +476,11 @@ ApplicationWindow {
font.pixelSize: 20 font.pixelSize: 20
text: "\ue082" text: "\ue082"
} }
} }
Rectangle { Rectangle {
id: badge id: badge
visible: (badgeContent == "icon" || badgeContent == "number" )? true : false visible: (badgeContent == "icon" || badgeContent == "number" )? true : false
width: 32 width: 32
color: "#05000000" color: "#05000000"
anchors { anchors {
@ -588,11 +489,11 @@ ApplicationWindow {
bottom: parent.bottom; bottom: parent.bottom;
rightMargin: 4; rightMargin: 4;
} }
Text { Text {
id: badgeIconLabel id: badgeIconLabel
visible: (badgeContent == "icon") ? true : false; visible: (badgeContent == "icon") ? true : false;
font.family: simpleLineIcons.name font.family: simpleLineIcons.name
anchors { anchors {
centerIn: parent centerIn: parent
} }
@ -600,7 +501,7 @@ ApplicationWindow {
color: "#AAA0A0" color: "#AAA0A0"
font.pixelSize: 20 font.pixelSize: 20
text: badgeIcon text: badgeIcon
} }
Text { Text {
id: badgeNumberLabel id: badgeNumberLabel
@ -609,14 +510,14 @@ ApplicationWindow {
centerIn: parent centerIn: parent
} }
horizontalAlignment: Text.AlignCenter horizontalAlignment: Text.AlignCenter
font.family: sourceSansPro.name font.family: sourceSansPro.name
font.weight: Font.Light font.weight: Font.Light
color: "#AAA0A0" color: "#AAA0A0"
font.pixelSize: 18 font.pixelSize: 18
text: badgeNumber text: badgeNumber
} }
} }
function closeApp() { function closeApp() {
@ -685,7 +586,7 @@ ApplicationWindow {
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
spacing: 3 spacing: 3
ColumnLayout { ColumnLayout {
@ -702,7 +603,7 @@ ApplicationWindow {
color: "transparent" color: "transparent"
Text { Text {
text: "ETHEREUM" text: "ETHEREUM"
font.family: sourceSansPro.name font.family: sourceSansPro.name
font.weight: Font.Regular font.weight: Font.Regular
// anchors.top: 20 // anchors.top: 20
// anchors.left: 16 // anchors.left: 16
@ -711,10 +612,10 @@ ApplicationWindow {
topMargin: 4 topMargin: 4
fill: parent fill: parent
} }
// anchors.leftMargin: 16 // anchors.leftMargin: 16
// anchors.topMargin: 16 // anchors.topMargin: 16
// anchors.verticalCenterOffset: 50 // anchors.verticalCenterOffset: 50
color: "#AAA0A0" color: "#AAA0A0"
} }
} }
@ -735,7 +636,7 @@ ApplicationWindow {
Text { Text {
text: "APPS" text: "APPS"
font.family: sourceSansPro.name font.family: sourceSansPro.name
font.weight: Font.Regular font.weight: Font.Regular
anchors.fill: parent anchors.fill: parent
anchors.leftMargin: 16 anchors.leftMargin: 16
@ -775,7 +676,7 @@ ApplicationWindow {
anchors.left: menu.right anchors.left: menu.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.top: parent.top anchors.top: parent.top
color: "#00000000" color: "#00000000"
/*Rectangle { /*Rectangle {
id: urlPane id: urlPane

View File

@ -25,9 +25,7 @@ import "C"
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"math/big" "math/big"
"os"
"path" "path"
"runtime" "runtime"
"sort" "sort"
@ -99,7 +97,7 @@ func NewWindow(ethereum *eth.Ethereum) *Gui {
return gui return gui
} }
func (gui *Gui) Start(assetPath string) { func (gui *Gui) Start(assetPath, libPath string) {
defer gui.txDb.Close() defer gui.txDb.Close()
guilogger.Infoln("Starting GUI") guilogger.Infoln("Starting GUI")
@ -117,7 +115,7 @@ func (gui *Gui) Start(assetPath string) {
// Create a new QML engine // Create a new QML engine
gui.engine = qml.NewEngine() gui.engine = qml.NewEngine()
context := gui.engine.Context() context := gui.engine.Context()
gui.uiLib = NewUiLib(gui.engine, gui.eth, assetPath) gui.uiLib = NewUiLib(gui.engine, gui.eth, assetPath, libPath)
gui.whisper = qwhisper.New(gui.eth.Whisper()) gui.whisper = qwhisper.New(gui.eth.Whisper())
// Expose the eth library and the ui library to QML // Expose the eth library and the ui library to QML
@ -292,25 +290,6 @@ func (self *Gui) getObjectByName(objectName string) qml.Object {
return self.win.Root().ObjectByName(objectName) return self.win.Root().ObjectByName(objectName)
} }
func loadJavascriptAssets(gui *Gui) (jsfiles string) {
for _, fn := range []string{"ext/q.js", "ext/eth.js/main.js", "ext/eth.js/qt.js", "ext/setup.js"} {
f, err := os.Open(gui.uiLib.AssetPath(fn))
if err != nil {
fmt.Println(err)
continue
}
content, err := ioutil.ReadAll(f)
if err != nil {
fmt.Println(err)
continue
}
jsfiles += string(content)
}
return
}
func (gui *Gui) SendCommand(cmd ServEv) { func (gui *Gui) SendCommand(cmd ServEv) {
gui.serviceEvents <- cmd gui.serviceEvents <- cmd
} }

View File

@ -65,6 +65,7 @@ func init() {
utils.NodeKeyFileFlag, utils.NodeKeyFileFlag,
utils.RPCListenAddrFlag, utils.RPCListenAddrFlag,
utils.RPCPortFlag, utils.RPCPortFlag,
utils.JSpathFlag,
} }
} }
@ -111,7 +112,7 @@ func run(ctx *cli.Context) {
gui := NewWindow(ethereum) gui := NewWindow(ethereum)
utils.RegisterInterrupt(func(os.Signal) { gui.Stop() }) utils.RegisterInterrupt(func(os.Signal) { gui.Stop() })
// gui blocks the main thread // gui blocks the main thread
gui.Start(ctx.GlobalString(assetPathFlag.Name)) gui.Start(ctx.GlobalString(assetPathFlag.Name), ctx.GlobalString(utils.JSpathFlag.Name))
return nil return nil
}) })
} }

View File

@ -21,7 +21,6 @@
package main package main
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"path" "path"
@ -29,7 +28,6 @@ import (
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/event/filter" "github.com/ethereum/go-ethereum/event/filter"
"github.com/ethereum/go-ethereum/javascript"
"github.com/ethereum/go-ethereum/xeth" "github.com/ethereum/go-ethereum/xeth"
"github.com/obscuren/qml" "github.com/obscuren/qml"
) )
@ -49,15 +47,19 @@ type UiLib struct {
// The main application window // The main application window
win *qml.Window win *qml.Window
jsEngine *javascript.JSRE
filterCallbacks map[int][]int filterCallbacks map[int][]int
filterManager *filter.FilterManager filterManager *filter.FilterManager
} }
func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib { func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath, libPath string) *UiLib {
x := xeth.New(eth, nil) x := xeth.New(eth, nil)
lib := &UiLib{XEth: x, engine: engine, eth: eth, assetPath: assetPath, jsEngine: javascript.NewJSRE(x), filterCallbacks: make(map[int][]int)} //, filters: make(map[int]*xeth.JSFilter)} lib := &UiLib{
XEth: x,
engine: engine,
eth: eth,
assetPath: assetPath,
filterCallbacks: make(map[int][]int),
}
lib.filterManager = filter.NewFilterManager(eth.EventMux()) lib.filterManager = filter.NewFilterManager(eth.EventMux())
go lib.filterManager.Start() go lib.filterManager.Start()
@ -76,19 +78,6 @@ func (self *UiLib) ImportTx(rlpTx string) {
} }
} }
func (self *UiLib) EvalJavascriptFile(path string) {
self.jsEngine.LoadExtFile(path[7:])
}
func (self *UiLib) EvalJavascriptString(str string) string {
value, err := self.jsEngine.Run(str)
if err != nil {
return err.Error()
}
return fmt.Sprintf("%v", value)
}
func (ui *UiLib) Muted(content string) { func (ui *UiLib) Muted(content string) {
component, err := ui.engine.LoadFile(ui.AssetPath("qml/muted.qml")) component, err := ui.engine.LoadFile(ui.AssetPath("qml/muted.qml"))
if err != nil { if err != nil {