From c535d0d24623caafcab084546f85f1f70cb2ac67 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 24 Apr 2014 14:42:31 +0200 Subject: [PATCH] Added new block sub for webapp --- ethereal/ui/ui_lib.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 9191e5ea90..08e2267a70 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -70,8 +70,34 @@ func (ui *UiLib) OpenHtml(path string) { win.Set("url", path) go func() { + blockChan := make(chan ethutil.React, 1) + quitChan := make(chan bool) + + go func() { + out: + for { + select { + case <-quitChan: + ui.eth.Reactor().Unsubscribe("newBlock", blockChan) + break out + case block := <-blockChan: + if block, ok := block.Resource.(*ethchain.Block); ok { + b := &Block{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())} + win.ObjectByName("webView").Call("onNewBlockCb", b) + } + } + } + + // Clean up + close(blockChan) + close(quitChan) + }() + ui.eth.Reactor().Subscribe("newBlock", blockChan) + win.Show() win.Wait() + + quitChan <- true }() }