How do I detect the click at the angle and pass the information to Electron?

Asked

Viewed 78 times

1

I am working on an Angular2 application that runs together with Electron, I need that when clicking on a specific angle link, the Electron application finishes. How do I make this kind of communication, so that the Electron understands a command coming from the angular?

1 answer

1


You will need to use the Electron ipcRenderer module. Regardless of the Javascript framework you are using the communication between the Chromiun browser and the Node in Electron is done by sending message to the processes.

So what happens is this:

Voce has Chromiun which is a browser and has Node which is the backend of an Electron application. If you want to take a browser information and manipulate in your main.js of Electron you need to use ipcRenderer.

Let me show you an example, buddy:

Imagine that I have a form and a button and want to get the name of the file selected by an input of type file. See below how I would have to do in the application view HTML:

<script>
        const electron = require('electron');
        const {ipcRenderer} = electron;

        document.querySelector('form').addEventListener('submit', (event) => {
           event.preventDefault();
           const {path} = document.querySelector('input').files[0];
           ipcRenderer.send('obterNomeArquivo', path);    
        });
</script>

See that the first method parameter .send ipcRenderer module is the name of your message identifier. In your main.js you can take the information as follows:

const {ipcMain} = electron;

ipcMain.on('obterNomeArquivo', (event, path)=> {
    console.log(path)
});

I hope I have helped you, friend! Anything just communicate! To finish, you can see the documentation of ipcRenderer, here: https://www.electronjs.org/docs/api/ipc-renderer

Browser other questions tagged

You are not signed in. Login or sign up in order to post.