Open In App

Prevent System from Entering Sleep mode in ElectronJS

ElectronJS is an Open Source Framework used for building Cross-Platform native desktop applications using web technologies such as HTML, CSS, and JavaScript which are capable of running on Windows, macOS, and Linux operating systems. It combines the Chromium engine and NodeJS into a Single Runtime.

In some desktop applications, a need arises due to which we need to keep the system active for longer durations. For example, during a file download or streaming audio/video. In such cases, we need to prevent the system from entering low-power mode. Else the application might be suspended from further execution. Electron provides us with a built-in powerSaveBlocker module for this very purpose. Using this module, we can control the system behavior and block the system from entering sleep mode. We can also restore the system to its original settings by disabling this power blocker. This tutorial will demonstrate the powerSaveBlocker module in Electron.



We assume that you are familiar with the prerequisites as covered in the above-mentioned link. For Electron to work, node and npm need to be pre-installed in the system.

powerSaveBlocker: The powerSaveBlocker Module is part of the Main Process. To import and use this Module in the Renderer Process, we will be using Electron remote module. For more details on the remote module, Refer this link.



Example: We will start by building the Electron Application for the powerSaveBlocker module implementation by following the given steps.


Article Tags :