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

50 lines
1.7 KiB
Markdown
Raw Normal View History

2015-06-21 13:14:49 +00:00
# power-save-blocker
The `power-save-blocker` module is used to block the system from entering
2015-06-22 02:23:58 +00:00
low-power(sleep) mode, allowing app to keep system and screen active.
2015-06-21 13:14:49 +00:00
An example is:
```javascript
var powerSaveBlocker = require('power-save-blocker');
2015-06-22 02:23:58 +00:00
var id = powerSaveBlocker.start(powerSaveBlocker.PREVENT_DISPLAY_SLEEP);
console.log(powerSaveBlocker.isStarted(id));
powerSaveBlocker.stop(id);
2015-06-21 13:14:49 +00:00
```
## powerSaveBlocker.start(type)
2015-06-22 02:23:58 +00:00
* `type` - Power save blocker type
2015-06-21 13:14:49 +00:00
* powerSaveBlocker.PREVENT_APP_SUSPENSION - Prevent the application from being
2015-06-22 02:23:58 +00:00
suspended. Keeps system active, but allows screen to be turned off.
2015-06-21 13:14:49 +00:00
Example use cases: downloading a file, playing audio.
* powerSaveBlocker.PREVENT_DISPLAY_SLEEP - Prevent the display from going to sleep.
2015-06-22 02:23:58 +00:00
Keeps system and screen active.
2015-06-21 13:14:49 +00:00
Example use case: playing video.
Starts the power save blocker preventing the system entering lower-power mode.
2015-06-22 02:23:58 +00:00
Returns an integer identified the power save blocker.
**Note:**
`PREVENT_DISPLAY_SLEEP` has higher precedence level than `PREVENT_APP_SUSPENSION`.
Only the highest precedence type takes effect. In other words, `PREVENT_DISPLAY_SLEEP`
always take precedence over `PREVENT_APP_SUSPENSION`.
For example, an API calling A requests for `PREVENT_APP_SUSPENSION`, and
another calling B requests for `PREVENT_DISPLAY_SLEEP`. `PREVENT_DISPLAY_SLEEP`
will be used until B stops its request. After that, `PREVENT_APP_SUSPENSION` is used.
## powerSaveBlocker.stop(id)
* `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-06-22 02:23:58 +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-06-22 02:23:58 +00:00
Returns whether the corresponding `powerSaveBlocker` starts.