IPC bidirectional communication issues


#1

Hi,

I was trying to find a way of communicating bidirectionally between the main process and my actual application (that is the render process) and found that it can be accomplished using ipc module. My problem appeared when I was trying to reference the module inside my application so that I can use ipcRenderer. I could not find a way to do this and tried experimenting with executeJavascript function:

mainWindow.webContents.executeJavaScript(`
    var ipcRenderer = require('electron').ipcRenderer;
    ipcRenderer.send('query', 'Hello World');
`);

Unfortunately, it did not work because require library was missing. I added it to the index.html and modified my code a bit:

mainWindow.webContents.executeJavaScript(`
     require(['electron'], function(electron){
       var ipcRenderer = electron.ipcRenderer;
       ipcRenderer.send('query', 'Hello world');
    })
');

But that failed too. Particularly, it was looking for electron.js file which was not really there!

Generally I am looking for a way to call a function that resides inside the application of the render process and get a returned value from that function. Does anyone have any clue?

Please note that my application is a bundled, minified Angular application.

Thanks


#2

You may want to read this topic that talks about how Electron is architected:


#3

Thanks very much for your reply. It was really helpful.

As I am new to this forum, do I need to take an action such as close this thread or mark it as solved?

Thanks again!


#4

No, nothing like that is necessary.