How to Show Custom Messages in ElectronJS

In this lesson i want to talk about How to Show Custom Messages in ElectronJS, ElectronJS is framework that allows developers to build cross platform desktop applications using web technologies such as JavaScript, HTML and CSS. it is built on top of Chromium, the open source version of Google Chrome and Node.js which provides runtime environment for JavaScript.

 

 

for creating  custom messages in ElectronJS, you can use ipcRenderer and ipcMain modules from electron package.

In the main process, you can use the ipcMain.on() method to listen for a custom message. for example following code in the main process listens for a message with the channel “custom-message” and logs the received message to the console:

 

 

In the renderer process, you can use ipcRenderer.send() method to send a custom message. for example following code in the renderer process sends a message with the channel “custom-message” and the message “Hello from the renderer”:

It is important to note that ipcRenderer module can only be used in the renderer process and ipcMain module can only be used in the main process.

This is just simple example you can use it to pass information between the main and renderer processes, you can also use it to trigger actions and events.

 

 

 

 

More on ElectronJS

 

 

This is the code for index.js

 

 

This is index.html

 

You can also use the message to update the UI or show notification.

 

 

 

Leave a Comment