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

59 lines
1.9 KiB
Markdown
Raw Normal View History

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
2016-11-23 19:20:56 +00:00
Process: [Main](../glossary.md#main-process)
2016-11-03 17:26:00 +00:00
2015-08-29 04:44:13 +00:00
For example:
2015-06-21 13:14:49 +00:00
```javascript
2018-09-13 16:10:51 +00:00
const { powerSaveBlocker } = require('electron')
2015-06-21 13:14:49 +00:00
const id = powerSaveBlocker.start('prevent-display-sleep')
console.log(powerSaveBlocker.isStarted(id))
2015-06-22 02:23:58 +00:00
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.
* `prevent-app-suspension` - Prevent the application from being suspended.
2017-11-29 10:58:24 +00:00
Keeps system active but allows screen to be turned off. Example use cases:
2015-08-29 04:44:13 +00:00
downloading a file or playing audio.
2016-08-22 18:17:05 +00:00
* `prevent-display-sleep` - Prevent the display from going to sleep. Keeps
2017-11-29 10:58:24 +00:00
system and screen active. Example use case: playing video.
2015-06-21 13:14:49 +00:00
Returns `Integer` - The blocker ID that is assigned to this power blocker.
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
2016-05-12 02:08:01 +00:00
**Note:** `prevent-display-sleep` has higher precedence over
2015-08-29 04:44:13 +00:00
`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
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
Returns `boolean` - Whether the specified `powerSaveBlocker` has been stopped.
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
Returns `boolean` - Whether the corresponding `powerSaveBlocker` has started.