How to Create Custom Notification in ElectronJS

In this lesson we want to learn about How to Create Custom Notification in ElectronJS, so first of all What is ElectronJs?

 

 

What is ElectronJs?

ElectronJS is a framework that allows developers to build crossplatform desktop applications using web technologies such as JavaScript, HTML and CSS. It is built on top of Chromium, open source version of Google Chrome and Node.js, which provides runtime environment for JavaScript. with ElectronJS, you can use the same codebase to create applications for Windows, Mac and Linux. this eliminates the need to write separate code for different platforms and it makes it development faster and more efficient.

 

 

 

Main Structure of ElectronJS

Structure of an ElectronJS application is composed of two main parts: main process which runs on the desktop and manages the application’s lifecycle, and the renderer process, which runs in web page and handles the user interface. main process and the renderer process communicate with each other through inter-process communication (IPC) mechanisms. ElectronJS also provides set of built in modules such as electron and remote modules, which allow developers to access the native functionality of the operating system and perform tasks such as creating windows and accessing file system or displaying notifications.

 

 

 

Applications that are Created with ElectronJS

ElectronJS is used by many popular applications such as Visual Studio Code, Slack and Discord. It is also well good for creating desktop applications that require offline capabilities, native system integration, or access to hardware devices.

 

 

This is an example of how to create a custom notification in ElectronJS using notification module:

This code creates new instance of the Notification class, passing in an options object with the title, body and icon properties. show() method is called to display notification. whenReady() method of the app module is used to wait for the app to be ready before creating the notification.

 

 

You can also add click event listener that will be triggered when the user clicks on notification, like this:

 

 

You can also add an action to the notification like this:

 

This is simple exampl but it demonstrates how to create custom notifications in ElectronJS. You can customize the notification further by adding different options, like buttons and custom actions.

 

 

This is the complete code for index.js – How to Build Custom Notifications in ElectronJS

In this example createWindow() function creates new BrowserWindow instance, loads the index.html file and sets up an event listener to handle when the window is closed. createNotification() function creates new instance of the Notification class, passing in an options object with the title, body and icon properties and sets up an event listener to handle when the notification is clicked. The whenReady() method of the app module is used to wait for the app to be ready before creating the window and notification.

This is basic example, you can customize the window, html, css and the notification according to your needs.

 

 

This is basic index.html file

This file creates simple HTML document with <h1> heading and <p> paragraph. you can add more elements, styles and scripts to make it more interactive and beautiful. You can also include external CSS and JavaScript files to give more functionality to your app.

 

 

Note: You can run the application with npm start, also make sure that you have installed electronjs.

 

 

 

Run the code using npm start and this will be the result

How to Create Custom Notification in ElectronJS
How to Create Custom Notification in ElectronJS

 

 

Subscribe and Get Free Video Courses & Articles in your Email

 

Leave a Comment

Share via
Copy link
Powered by Social Snap
×