Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assetPath configurable on command line for ethereal GUI #31

Merged
merged 1 commit into from
Mar 27, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ethereal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var UseSeed bool
var ImportKey string
var ExportKey bool
var DataDir string
var AssetPath string

func Init() {
flag.BoolVar(&StartConsole, "c", false, "debug and testing console")
Expand All @@ -29,6 +30,7 @@ func Init() {
flag.StringVar(&DataDir, "dir", ".ethereal", "ethereum data directory")
flag.StringVar(&ImportKey, "import", "", "imports the given private key (hex)")
flag.IntVar(&MaxPeer, "x", 5, "maximum desired peers")
flag.StringVar(&AssetPath, "asset_path", "", "absolute path to GUI assets directory")

flag.Parse()
}
4 changes: 2 additions & 2 deletions ethereal/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ func main() {
os.Exit(0)
}

log.Printf("Starting Ethereum v%s\n", ethutil.Config.Ver)
log.Printf("Starting Ethereum GUI v%s\n", ethutil.Config.Ver)

// Set the max peers
ethereum.MaxPeers = MaxPeer

gui := ethui.New(ethereum)
gui.Start()
gui.Start(AssetPath)
}
11 changes: 7 additions & 4 deletions ethereal/ui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Gui struct {
txDb *ethdb.LDBDatabase

addr []byte

}

// Create GUI, but doesn't start it
Expand All @@ -71,7 +72,7 @@ func New(ethereum *eth.Ethereum) *Gui {
return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr}
}

func (ui *Gui) Start() {
func (ui *Gui) Start(assetPath string) {
defer ui.txDb.Close()

// Register ethereum functions
Expand All @@ -89,14 +90,16 @@ func (ui *Gui) Start() {

// Expose the eth library and the ui library to QML
context.SetVar("eth", ui.lib)
context.SetVar("ui", &UiLib{engine: ui.engine, eth: ui.eth})
uiLib := NewUiLib(ui.engine, ui.eth, assetPath)
context.SetVar("ui", uiLib)

// Load the main QML interface
component, err := ui.engine.LoadFile(AssetPath("qml/wallet.qml"))
component, err := ui.engine.LoadFile(uiLib.AssetPath("qml/wallet.qml"))
if err != nil {
ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'")
panic(err)
}
ui.engine.LoadFile(AssetPath("qml/transactions.qml"))
ui.engine.LoadFile(uiLib.AssetPath("qml/transactions.qml"))

ui.win = component.CreateWindow(nil)

Expand Down
14 changes: 11 additions & 3 deletions ethereal/ui/ui_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ type UiLib struct {
engine *qml.Engine
eth *eth.Ethereum
connected bool
assetPath string
}

func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib {
if assetPath == "" {
assetPath = DefaultAssetPath()
}
return &UiLib{engine: engine, eth: eth, assetPath: assetPath}
}

// Opens a QML file (external application)
Expand Down Expand Up @@ -45,10 +53,10 @@ func (ui *UiLib) ConnectToPeer(addr string) {
}

func (ui *UiLib) AssetPath(p string) string {
return AssetPath(p)
return path.Join(ui.assetPath, p)
}

func AssetPath(p string) string {
func DefaultAssetPath() string {
var base string

// If the current working directory is the go-ethereum dir
Expand All @@ -72,5 +80,5 @@ func AssetPath(p string) string {
}
}

return path.Join(base, p)
return base
}