little problem
Opened this issue · 1 comments
user381281 commented
Hello, what is wrong in the code, the message from javascript does not come?
package main
import("fmt";"github.com/asticode/go-astikit";"github.com/asticode/go-astilectron")
func main(){
a, _:= astilectron.New(nil, astilectron.Options{
AppName: "test",
BaseDirectoryPath: "example",
})
defer a.Close()
a.Start()
var w, _ = a.NewWindow("new.html", &astilectron.WindowOptions{
Center: astikit.BoolPtr(true),
Height: astikit.IntPtr(600),
Width: astikit.IntPtr(600)});
w.Create()
w.OnMessage(func(m *astilectron.EventMessage) interface{} {
// Unmarshal
var s string
m.Unmarshal(&s)
fmt.Print("+")
// Process message
if s == "hello" {
fmt.Print("this place")
return "world"
}
return nil
})
a.Wait()
}
<html><head><style>
body{background:RED;}
</style></head><body><script>
dq=0;
const remote = require('electron').remote;
setInterval(g, 500);
function e(){document.getElementById("qq").innerHTML="\\\\\\\\\\\\\\\\\\\\";}
function g()
{
document.getElementById("qq").innerHTML=dq;
document.addEventListener('astilectron-ready', function()
{
astilectron.sendMessage("hello", function(message) { console.log("received " + message) });
})
++dq;
console.log(dq);
}
</script>
<div id="qq"></div>
<div id="qq1"></div>
<h1>top</h1>
<div><input id="a" type="button" onclick="e()" value="zzzz">ZZZZ</div>
<h1>end</h1>
</body>
</html>
asticode commented
Try putting
w.OnMessage(func(m *astilectron.EventMessage) interface{} {
// Unmarshal
var s string
m.Unmarshal(&s)
fmt.Print("+")
// Process message
if s == "hello" {
fmt.Print("this place")
return "world"
}
return nil
})
before
w.Create()
Also, if it still fails, you'll need to paste logs here.