More updates: use string instead of integer to identify blocker type.
This commit is contained in:
parent
532f75fcab
commit
13784e6551
4 changed files with 29 additions and 43 deletions
|
@ -4,18 +4,12 @@
|
|||
|
||||
#include "atom/browser/api/atom_api_power_save_blocker.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "content/public/browser/power_save_blocker.h"
|
||||
#include "native_mate/constructor.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
namespace {
|
||||
|
||||
const char kPowerSaveBlockerDescription[] = "Electron";
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace mate {
|
||||
|
||||
template<>
|
||||
|
@ -24,19 +18,15 @@ struct Converter<content::PowerSaveBlocker::PowerSaveBlockerType> {
|
|||
v8::Local<v8::Value> val,
|
||||
content::PowerSaveBlocker::PowerSaveBlockerType* out) {
|
||||
using content::PowerSaveBlocker;
|
||||
int type;
|
||||
std::string type;
|
||||
if (!ConvertFromV8(isolate, val, &type))
|
||||
return false;
|
||||
switch (static_cast<PowerSaveBlocker::PowerSaveBlockerType>(type)) {
|
||||
case PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension:
|
||||
*out = PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension;
|
||||
break;
|
||||
case PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep:
|
||||
*out = PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if (type == "prevent-app-suspension")
|
||||
*out = PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension;
|
||||
else if (type == "prevent-display-sleep")
|
||||
*out = PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep;
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
@ -47,7 +37,9 @@ namespace atom {
|
|||
|
||||
namespace api {
|
||||
|
||||
PowerSaveBlocker::PowerSaveBlocker() {
|
||||
PowerSaveBlocker::PowerSaveBlocker()
|
||||
: current_blocker_type_(
|
||||
content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension) {
|
||||
}
|
||||
|
||||
PowerSaveBlocker::~PowerSaveBlocker() {
|
||||
|
@ -81,7 +73,7 @@ void PowerSaveBlocker::UpdatePowerSaveBlocker() {
|
|||
content::PowerSaveBlocker::Create(
|
||||
new_blocker_type,
|
||||
content::PowerSaveBlocker::kReasonOther,
|
||||
kPowerSaveBlockerDescription);
|
||||
ATOM_PRODUCT_NAME);
|
||||
power_save_blocker_.swap(new_blocker);
|
||||
current_blocker_type_ = new_blocker_type;
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@ class PowerSaveBlocker : public mate::Wrappable {
|
|||
content::PowerSaveBlocker::PowerSaveBlockerType current_blocker_type_;
|
||||
|
||||
// Map from id to the corresponding blocker type for each request.
|
||||
typedef std::map<int, content::PowerSaveBlocker::PowerSaveBlockerType>
|
||||
PowerSaveBlockerTypeMap;
|
||||
using PowerSaveBlockerTypeMap =
|
||||
std::map<int, content::PowerSaveBlocker::PowerSaveBlockerType>;
|
||||
PowerSaveBlockerTypeMap power_save_blocker_types_;
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
bindings = process.atomBinding 'power_save_blocker'
|
||||
|
||||
powerSaveBlocker = bindings.powerSaveBlocker
|
||||
|
||||
powerSaveBlocker.PREVENT_APP_SUSPENSION = 0
|
||||
powerSaveBlocker.PREVENT_DISPLAY_SLEEP = 1
|
||||
|
||||
module.exports = powerSaveBlocker
|
||||
module.exports = bindings.powerSaveBlocker
|
||||
|
|
|
@ -8,7 +8,7 @@ An example is:
|
|||
```javascript
|
||||
var powerSaveBlocker = require('power-save-blocker');
|
||||
|
||||
var id = powerSaveBlocker.start(powerSaveBlocker.PREVENT_DISPLAY_SLEEP);
|
||||
var id = powerSaveBlocker.start('prevent-display-sleep');
|
||||
console.log(powerSaveBlocker.isStarted(id));
|
||||
|
||||
powerSaveBlocker.stop(id);
|
||||
|
@ -16,25 +16,24 @@ powerSaveBlocker.stop(id);
|
|||
|
||||
## powerSaveBlocker.start(type)
|
||||
|
||||
* `type` - Power save blocker type
|
||||
* powerSaveBlocker.PREVENT_APP_SUSPENSION - Prevent the application from being
|
||||
suspended. Keeps system active, but allows screen to be turned off.
|
||||
Example use cases: downloading a file, playing audio.
|
||||
* powerSaveBlocker.PREVENT_DISPLAY_SLEEP - Prevent the display from going to sleep.
|
||||
Keeps system and screen active.
|
||||
Example use case: playing video.
|
||||
* `type` String - Power save blocker type
|
||||
* `prevent-app-suspension` - Prevent the application from being suspended.
|
||||
Keeps system active, but allows screen to be turned off. Example use cases:
|
||||
downloading a file, playing audio.
|
||||
* `prevent-display-sleep`- Prevent the display from going to sleep. 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_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`.
|
||||
`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.
|
||||
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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue