webContents.send not sending anything


#1

Trying to send some data to a login state and it is not sending any data. I’m not sure if this is because it is in an Angular controller, or what.

Main:

mainWindow.webContents.on('did-finish-load', function() {
	mainWindow.webContents.send('onload-user', 'test');
});

Render

ipc.on('onload-user', function(data) {
    console.log(data);
});

ipc is sending things back to the main process just fine, but I’m getting nothing from the on in the render.


#2

If I were you I will try to use a document.ready = function(){} or $(function(){}) to trigger that on render, not on main.

<script>
var ipc = require('ipc');
ipc.on('onload-user', function(data) {
    console.log(data);
});
$(function(){
 ipc.send('did-finish-load');
});
</script>

main:

var ipc = require('ipc');
ipc.on('did-finish-load',function(){
    mainWindow.webContents.send('onload-user', 'test');
});

I tried to do the same: to execute a script once everything is loaded, but for the more practical case, I ended using $(function(){}) to do the trick.


#3

Because when on render you recive an event and the data.

So:

ipc.on('onload-user', function(**event** , data) {
    console.log(data);
});

#4

I am wonder why do I need to send the event after did-finish-load event happen ? can I use webContents to send message to a browser window directly ? like

mainWindow.webContents.send('some-event-happen', some message)

tried this but doesn’t send anything as well…