2

I need to send information to an angular component in order to do an "automatic" login, I can send component data to the electron process using the IPCRederer (on component) and IPCMain (on 'electron' side), but I can't use in the opposite way that would be from the electron to the component, could you help me?

PS: I've thought of a socket conversation, but I don't think it's a good practice.

Angular:

obterUsuario(){
    this.electronService.ipcRenderer.send("ping", "Teste");
}

Electron:

ipcMain.on("ping", (event, messageFromAngular) => {
    console.log("[electron] pong", messageFromAngular);
    let user = { email: "desenvolvedor@1245.com.br", password: "teste001" };
});
Emeric
  • 6,315
  • 2
  • 41
  • 54

2 Answers2

0

You can use the webContents.send method if you have the renderer reference (https://electronjs.org/docs/api/web-contents#contentssendchannel-arg1-arg2-), or you can use the event object to respond (https://electronjs.org/docs/api/structures/ipc-main-event). You can see more here (https://www.brainbell.com/javascript/ipc-communication.html)

observingstream
  • 466
  • 3
  • 8
0

It works for me to use one of the examples of the uploaded content, it remained like this: electron:

ipcMain.on("ping", (event, messageFromAngular) => {
console.log("[electron] pong", messageFromAngular);
let user = [
{
email: "desev@1234.com.br",
password: "teste001"
}
];

event.sender.send("sigin", "Test electron");
});

angular:

this.electronService.ipcRenderer.on("sigin", (event, args) => {
console.log(JSON.parse(args));
});