2015-08-29 04:44:13 +00:00
|
|
|
# powerSaveBlocker
|
2015-06-21 13:14:49 +00:00
|
|
|
|
2016-04-21 22:39:12 +00:00
|
|
|
> Block the system from entering low-power (sleep) mode.
|
2015-06-21 13:14:49 +00:00
|
|
|
|
2015-08-29 04:44:13 +00:00
|
|
|
For example:
|
2015-06-21 13:14:49 +00:00
|
|
|
|
|
|
|
```javascript
|
2016-05-10 16:26:38 +00:00
|
|
|
const {powerSaveBlocker} = require('electron');
|
2015-06-21 13:14:49 +00:00
|
|
|
|
2016-05-04 17:59:02 +00:00
|
|
|
const id = powerSaveBlocker.start('prevent-display-sleep');
|
2015-06-22 02:23:58 +00:00
|
|
|
console.log(powerSaveBlocker.isStarted(id));
|
|
|
|
|
|
|
|
powerSaveBlocker.stop(id);
|
2015-06-21 13:14:49 +00:00
|
|
|
```
|
|
|
|
|
2015-08-29 04:44:13 +00:00
|
|
|
## Methods
|
2015-06-21 13:14:49 +00:00
|
|
|
|
2015-08-29 04:44:13 +00:00
|
|
|
The `powerSaveBlocker` module has the following methods:
|
|
|
|
|
|
|
|
### `powerSaveBlocker.start(type)`
|
|
|
|
|
|
|
|
* `type` String - Power save blocker type.
|
2015-06-24 04:49:43 +00:00
|
|
|
* `prevent-app-suspension` - Prevent the application from being suspended.
|
2015-08-29 04:44:13 +00:00
|
|
|
Keeps system active but allows screen to be turned off. Example use cases:
|
|
|
|
downloading a file or playing audio.
|
|
|
|
* `prevent-display-sleep`- Prevent the display from going to sleep. Keeps
|
|
|
|
system and screen active. Example use case: playing video.
|
2015-06-21 13:14:49 +00:00
|
|
|
|
2015-09-01 23:21:29 +00:00
|
|
|
Starts preventing the system from entering lower-power mode. Returns an integer
|
|
|
|
identifying the power save blocker.
|
2015-06-22 02:23:58 +00:00
|
|
|
|
2015-08-29 04:44:13 +00:00
|
|
|
**Note:** `prevent-display-sleep` has higher has precedence over
|
|
|
|
`prevent-app-suspension`. Only the highest precedence type takes effect. In
|
2015-09-01 23:21:29 +00:00
|
|
|
other words, `prevent-display-sleep` always takes precedence over
|
2015-08-29 04:44:13 +00:00
|
|
|
`prevent-app-suspension`.
|
2015-06-22 02:23:58 +00:00
|
|
|
|
2015-06-24 04:49:43 +00:00
|
|
|
For example, an API calling A requests for `prevent-app-suspension`, and
|
|
|
|
another calling B requests for `prevent-display-sleep`. `prevent-display-sleep`
|
2015-08-29 04:44:13 +00:00
|
|
|
will be used until B stops its request. After that, `prevent-app-suspension`
|
|
|
|
is used.
|
2015-06-22 02:23:58 +00:00
|
|
|
|
2015-08-29 04:44:13 +00:00
|
|
|
### `powerSaveBlocker.stop(id)`
|
2015-06-22 02:23:58 +00:00
|
|
|
|
|
|
|
* `id` Integer - The power save blocker id returned by `powerSaveBlocker.start`.
|
2015-06-21 13:14:49 +00:00
|
|
|
|
2015-06-22 02:23:58 +00:00
|
|
|
Stops the specified power save blocker.
|
2015-06-21 13:14:49 +00:00
|
|
|
|
2015-08-29 04:44:13 +00:00
|
|
|
### `powerSaveBlocker.isStarted(id)`
|
2015-06-21 13:14:49 +00:00
|
|
|
|
2015-06-22 02:23:58 +00:00
|
|
|
* `id` Integer - The power save blocker id returned by `powerSaveBlocker.start`.
|
2015-06-21 13:14:49 +00:00
|
|
|
|
2015-08-29 04:44:13 +00:00
|
|
|
Returns a boolean whether the corresponding `powerSaveBlocker` has started.
|