Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

little problem #313

Open
user381281 opened this issue Mar 6, 2021 · 1 comment
Open

little problem #313

user381281 opened this issue Mar 6, 2021 · 1 comment

Comments

@user381281
Copy link

user381281 commented Mar 6, 2021

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
Copy link
Owner

asticode commented Mar 8, 2021

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants