Getting started with Electron JS

Desktop applications are stand-alone applications that run on a system, they may or may not require Internet access. Examples of such apps are

  • Adobe Photoshop
  • Microsoft Office applications
  • Skype
  • Discord
  • Slack

There are various tools that can be used to build a desktop app, such as Electron, Winforms, WFP, Swing, JavaFX, etc. In this article, we’ll be getting a tour of Electron JS😀.

Introduction to Electron JS

Electron is a framework that is used to build cross-platform desktop applications using HTML, CSS, and JavaScript. it is an open-source and free project. Electron does not require native development skills for creating apps that run on Windows, macOS, and Linux; By embedding chromium and node.js, it maintains a codebase of JavaScript. Applications that use Electron JS for its development are WhatsApp, Slack, VS code, WordPress, etc.


Build an Electron App

Open the folder in which we want to create the app and initialize an npm package. 

The entry file would be main.js

npm init

Now, the next step would be to install an electron. For this, the following command needs to be executed.

npm install electron --save-dev

Create the files index.html and main.js

Electron Demo App

This is my first Electron App

In the main.js file, import the necessary modules

const { app, BrowserWindow } = require(‘electron’)

Create a function, create a window (), which will contain the property of the new window to be created, and load the html file.

const createWindow = () => {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true,
    },
  });

  win.loadFile("index.html");
};

The above function will be executed when our app is ready,

app.whenReady().then(create window)

To execute, add electron . to the start command in the scripts field of package.json. Through this command, the Electron executable will look for the main script in the current directory and run it in dev mode.

Now, Run the command

npm run start 

🥳Hurray!

BrowserWindow

The BrowserWindow class that we have used in the above example helps to modify the look and behavior of the app’s windows by using various options which are optional, few of them are as follows:

  • width (Integer): defines the window’s width (pixels). [Default value: 800].
  • height (Integer): defines the window’s height (pixels). [Default value: 600].
  • useContentSize (boolean): width and height are used as the size of the web page. That is, the actual window size includes the size of the window frame and is slightly larger. [Default value: false]
  • center (boolean): shows a window in the center of the screen. [Default value: false]
  • minWidth (Integer): defines the window’s minimum width. [Default value: 0]
  • minHeight (Integer): defines the window’s minimum height. [Default value: 0]
  • maxWidth (Integer): defines the window’s maximum width. [Default value: no limit]
  • maxHeight (Integer): defines window’s maximum height. [Default value: no limit]
  • resizable (boolean): describes whether window is resizable. [Default value: true]
  • movable (boolean) macOS Windows: describes whether window is movable. [Default value: true]
  • minimizable (boolean) macOS Windows: describes whether window is minimizable. [Default value: true]
  • maximizable (boolean) macOS Windows: describes whether window is maximizable. [Default value: true]

Reference

Electron JS documentation : https://www.electronjs.org/docs/latest/

Thank You
Keep Learning🤓

Latest

SENTRY integration in your React Native App for Error/Crash tracking

Sentry captures data by using an SDK within your...

Recall the concepts of useCallback.

useCallback hook is one of the best hooks offered...

Value of Comments in the code!!

During my journey of Software Development, I am always...

YOLO:Bullet Paced Algorithm

http://sh017.hostgator.tempwebhost.net/media/33949d0e61af4b50f374c534713f56b3 According to world health organization, more than 1.35 million...

Featured

Developing Enterprise Application in Node.js – CJS Vs ESM

Node.js is a popular runtime environment for building server-side...

Integrating your web react applications with their React Native(android and IOS) apps using QR code

Integrating a web application with Android and iOS apps...

YOLO: Bullet Paced Algorithm – popular choice for object detection in autonomous vehicles 

According to world health organization, more than 1.35 million...

Importance of Test Scalar Tool

TestScalar is quick to access, convenient to execute, easy to track. Our popular web-based test planning software lets you focus on what matters: meeting...

From Requirements to Reporting: How to Use a Test Case Management Tool to Ace Your Software Testing

The Software Testing Life Cycle (STLC) is a process that describes the stages of testing software. It includes planning, design, execution, and reporting of...

YOLO:Bullet Paced Algorithm

http://sh017.hostgator.tempwebhost.net/media/33949d0e61af4b50f374c534713f56b3 According to world health organization, more than 1.35 million people die every year because of vehicle accidents . Vehicle safety features started with passive safety...

LEAVE A REPLY

Please enter your comment!
Please enter your name here