electron/docs/api/power-save-blocker.md

59 lines
1.9 KiB
Markdown
Raw Normal View History

2015-08-28 22:44:13 -06:00
# powerSaveBlocker
2015-06-21 07:14:49 -06:00
2016-04-21 16:39:12 -06:00
> Block the system from entering low-power (sleep) mode.
2015-06-21 07:14:49 -06:00
2016-11-23 12:20:56 -07:00
Process: [Main](../glossary.md#main-process)
2016-11-03 11:26:00 -06:00
2015-08-28 22:44:13 -06:00
For example:
2015-06-21 07:14:49 -06:00
```js
2018-09-13 10:10:51 -06:00
const { powerSaveBlocker } = require('electron')
2015-06-21 07:14:49 -06:00
const id = powerSaveBlocker.start('prevent-display-sleep')
console.log(powerSaveBlocker.isStarted(id))
2015-06-21 20:23:58 -06:00
powerSaveBlocker.stop(id)
2015-06-21 07:14:49 -06:00
```
2015-08-28 22:44:13 -06:00
## Methods
2015-06-21 07:14:49 -06:00
2015-08-28 22:44:13 -06:00
The `powerSaveBlocker` module has the following methods:
### `powerSaveBlocker.start(type)`
* `type` string - Power save blocker type.
* `prevent-app-suspension` - Prevent the application from being suspended.
2017-11-29 03:58:24 -07:00
Keeps system active but allows screen to be turned off. Example use cases:
2015-08-28 22:44:13 -06:00
downloading a file or playing audio.
2016-08-22 12:17:05 -06:00
* `prevent-display-sleep` - Prevent the display from going to sleep. Keeps
2017-11-29 03:58:24 -07:00
system and screen active. Example use case: playing video.
2015-06-21 07:14:49 -06:00
Returns `Integer` - The blocker ID that is assigned to this power blocker.
2015-09-01 17:21:29 -06:00
Starts preventing the system from entering lower-power mode. Returns an integer
identifying the power save blocker.
2015-06-21 20:23:58 -06:00
2016-05-11 20:08:01 -06:00
**Note:** `prevent-display-sleep` has higher precedence over
2015-08-28 22:44:13 -06:00
`prevent-app-suspension`. Only the highest precedence type takes effect. In
2015-09-01 17:21:29 -06:00
other words, `prevent-display-sleep` always takes precedence over
2015-08-28 22:44:13 -06:00
`prevent-app-suspension`.
2015-06-21 20:23:58 -06: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-28 22:44:13 -06:00
will be used until B stops its request. After that, `prevent-app-suspension`
is used.
2015-06-21 20:23:58 -06:00
2015-08-28 22:44:13 -06:00
### `powerSaveBlocker.stop(id)`
2015-06-21 20:23:58 -06:00
* `id` Integer - The power save blocker id returned by `powerSaveBlocker.start`.
2015-06-21 07:14:49 -06:00
2015-06-21 20:23:58 -06:00
Stops the specified power save blocker.
2015-06-21 07:14:49 -06:00
Returns `boolean` - Whether the specified `powerSaveBlocker` has been stopped.
2015-08-28 22:44:13 -06:00
### `powerSaveBlocker.isStarted(id)`
2015-06-21 07:14:49 -06:00
2015-06-21 20:23:58 -06:00
* `id` Integer - The power save blocker id returned by `powerSaveBlocker.start`.
2015-06-21 07:14:49 -06:00
Returns `boolean` - Whether the corresponding `powerSaveBlocker` has started.