May 25, 2021 Electron
powerSaveBlocker
is used to prevent the application from entering sleep mode, so this allows the application to keep the system and screen working.
For example:
const powerSaveBlocker = require('electron').powerSaveBlocker;
var id = powerSaveBlocker.start('prevent-display-sleep');
console.log(powerSaveBlocker.isStarted(id));
powerSaveBlocker.stop(id);
powerSaveBlocker
has the following approach:
powerSaveBlocker.start(type)
type
String - Force save blocking type.
prevent-app-suspension
- prevents apps from hanging. K
eep the system active but allow the screen not to light up.
Use case: Download a file or play audio.
prevent-display-sleep
- prevents the app from going into hibernation. K
eep the system and screen active and the screen is always on.
Use case: Play audio.
Start blocking the system from going into sleep mode. Returns an integer that identifies the blocker that remains active.
Note:
prevent-display-sleep
a higher
prevent-app-suspension
. O
nly the highest priority takes effect.
In
other words,
prevent-display-sleep
is always
prevent-app-suspension
.
For example, the
A request calls
prevent-app-suspension
and the B request
prevent-display-sleep
.
prevent-display-sleep
will work until B stops calling.
After that,
prevent-app-suspension
only worked.
powerSaveBlocker.stop(id)
id
Integer
- Keep active blocker id
powerSaveBlocker.start
Let the specified blocker stop active.
powerSaveBlocker.isStarted(id)
id
Integer
- Keep active blocker id
powerSaveBlocker.start
Return to boolean,
whether the
powerSaveBlocker
been started.