Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Electron powerMonitor module


May 25, 2021 Electron


Table of contents


power-monitor module is used to monitor changes in the energy zone. C an only be used in the main process. You app use ready module after the ready event is triggered.

For example:

app.on('ready', function() {
  require('electron').powerMonitor.on('suspend', function() {
    console.log('The system is going to sleep');
  });
});

Event

power-monitor can trigger the following events:

Event: 'suspend'

Triggered when the system hangs.

Event: 'resume'

Triggered when the system resumes to work. Emitted when system is resuming.

Event: 'on-ac'

Triggered when the system uses AC. Emitted when the system changes to AC power.

Event: 'on-battery'

Triggered when the system uses battery power. Emitted when system changes to battery power.