Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

electron to angular communication

I build an angular app and then wrapped it using Electron. My dir structure looks like this :
Project
|--electron
---|-main.js
-----|-index.html (and other files copied from webapp/dist)
|--webapp (angular app)
---|-src
-----|-app
-------|-service

I tried inter-process communication (ipcMain and ipcRenderer) but it got hanged up! Then I came to know about webcontent.executeJavascript();

So I made a service in angular which has a various functions like eventFromHost() & sendMessage().

how do I call this function from electron's main.js using webcontent or any other method?

like image 241
lazzy_ms Avatar asked Mar 06 '26 20:03

lazzy_ms


1 Answers

You should use ipcMain and ipcRenderer for that:

In Angular:

ipcMain.send('foo', data);

In electron:

ipcMain.on('foo', (event, data) => {
  // Do what you want with data.
});

Or same using ipcRenderer to make electron => angular communication (ipcMain being to communicate from angular to electron).

If you want to see a live example, check this main.js file on github, and the service that communicates with it here in angular.

like image 92
Supamiu Avatar answered Mar 08 '26 09:03

Supamiu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!