Repository navigation
Power save blocker API - #2025
Conversation
|
While it is okay to put it in a separate module, It would've been ideal to have this inside the |
There was a problem hiding this comment.
This probably should return some kind of token you then pass to Stop, or at least does a refcount thing so that two Starts require two Stops to stop. Otherwise it's very hard to use this in a library without worrying if you're stomping somebody else's Power Save Block - i.e:
- App calls Start for a long process
- Some library also calls Start, for something short
- That library calls Stop
- Library accidentally stomps the App's Start call and has no way to not do that
There was a problem hiding this comment.
@paulcbetts 👍 Thanks for pointing out this. Having updated the APIs.
f433c64 to
0dfd277
Compare
There was a problem hiding this comment.
why log at ERROR level here ?
0dfd277 to
532f75f
Compare
There was a problem hiding this comment.
You can use the ATOM_PRODUCT_NAME macro.
|
API returning an ID usually means the API can be started for infinite times, like We can just use APIs like this: powerSaveBlocker.preventAppSuspension();
powerSaveBlocker.allowAppSuspension();
powerSaveBlocker.isAppSuspensionPrevented();
powerSaveBlocker.preventDisplaySleep();
powerSaveBlocker.allowDisplaySleep();
powerSaveBlocker.isDisplaySleepPrevented();It is very simple to use and implement, and there is no complex logic involved. |
But the stomping problem pointed by @paulcbetts still exites under this set of APIs. |
Ah I missed that, the design looks good then. |
There was a problem hiding this comment.
I think we should use String as parameter name, like the clipboard and dialog module:
powerSaveBlocker.start('prevent-display-sleep');It is very rare to use constant integers as parameters in JavaScript.
|
👍 |
The PR introduces a new type
powerSaveBlockerAPI. Fixes #1936API details:
power-save-blocker
The
power-save-blockermodule is used to block the system from enteringlow-power(sleep) mode, allowing app to keep system and screen active.
An example is:
powerSaveBlocker.start(type)
type- Power save blocker typesuspended. Keeps system active, but allows screen to be turned off.
Example use cases: downloading a file, playing audio.
Keeps system and screen active.
Example use case: playing video.
Starts the power save blocker preventing the system entering lower-power mode.
Returns an integer identified the power save blocker.
Note:
PREVENT_DISPLAY_SLEEPhas higher precedence level thanPREVENT_APP_SUSPENSION.Only the highest precedence type takes effect. In other words,
PREVENT_DISPLAY_SLEEPalways take precedence over
PREVENT_APP_SUSPENSION.For example, an API calling A requests for
PREVENT_APP_SUSPENSION, andanother calling B requests for
PREVENT_DISPLAY_SLEEP.PREVENT_DISPLAY_SLEEPwill be used until B stops its request. After that,
PREVENT_APP_SUSPENSIONis used.powerSaveBlocker.stop(id)
idInteger - The power save blocker id returned bypowerSaveBlocker.start.Stops the specified power save blocker.
powerSaveBlocker.isStarted(id)
idInteger - The power save blocker id returned bypowerSaveBlocker.start.Returns whether the corresponding
powerSaveBlockerstarts.