parent
dd4a31633f
commit
547add94d0
3 changed files with 36 additions and 12 deletions
|
@ -84,19 +84,19 @@ void PowerMonitor::OnResume() {
|
||||||
Emit("resume");
|
Emit("resume");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerMonitor::QuerySystemIdleState(v8::Isolate* isolate,
|
ui::IdleState PowerMonitor::QuerySystemIdleState(v8::Isolate* isolate,
|
||||||
int idle_threshold,
|
int idle_threshold) {
|
||||||
const ui::IdleCallback& callback) {
|
|
||||||
if (idle_threshold > 0) {
|
if (idle_threshold > 0) {
|
||||||
ui::CalculateIdleState(idle_threshold, callback);
|
return ui::CalculateIdleState(idle_threshold);
|
||||||
} else {
|
} else {
|
||||||
isolate->ThrowException(v8::Exception::TypeError(mate::StringToV8(
|
isolate->ThrowException(v8::Exception::TypeError(mate::StringToV8(
|
||||||
isolate, "Invalid idle threshold, must be greater than 0")));
|
isolate, "Invalid idle threshold, must be greater than 0")));
|
||||||
|
return ui::IDLE_STATE_UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerMonitor::QuerySystemIdleTime(const ui::IdleTimeCallback& callback) {
|
int PowerMonitor::QuerySystemIdleTime() {
|
||||||
ui::CalculateIdleTime(callback);
|
return ui::CalculateIdleTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
@ -122,8 +122,8 @@ void PowerMonitor::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("blockShutdown", &PowerMonitor::BlockShutdown)
|
.SetMethod("blockShutdown", &PowerMonitor::BlockShutdown)
|
||||||
.SetMethod("unblockShutdown", &PowerMonitor::UnblockShutdown)
|
.SetMethod("unblockShutdown", &PowerMonitor::UnblockShutdown)
|
||||||
#endif
|
#endif
|
||||||
.SetMethod("querySystemIdleState", &PowerMonitor::QuerySystemIdleState)
|
.SetMethod("_querySystemIdleState", &PowerMonitor::QuerySystemIdleState)
|
||||||
.SetMethod("querySystemIdleTime", &PowerMonitor::QuerySystemIdleTime);
|
.SetMethod("_querySystemIdleTime", &PowerMonitor::QuerySystemIdleTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
|
@ -46,10 +46,8 @@ class PowerMonitor : public mate::TrackableObject<PowerMonitor>,
|
||||||
void OnResume() override;
|
void OnResume() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void QuerySystemIdleState(v8::Isolate* isolate,
|
ui::IdleState QuerySystemIdleState(v8::Isolate* isolate, int idle_threshold);
|
||||||
int idle_threshold,
|
int QuerySystemIdleTime();
|
||||||
const ui::IdleCallback& callback);
|
|
||||||
void QuerySystemIdleTime(const ui::IdleTimeCallback& callback);
|
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
// Static callback invoked when a message comes in to our messaging window.
|
// Static callback invoked when a message comes in to our messaging window.
|
||||||
|
|
|
@ -22,4 +22,30 @@ if (process.platform === 'linux') {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(deepak1556): Deprecate async api in favor of sync version in 5.0
|
||||||
|
powerMonitor.querySystemIdleState = function (threshold, callback) {
|
||||||
|
if (typeof threshold !== 'number') {
|
||||||
|
throw new Error('Must pass threshold as a number')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof callback !== 'function') {
|
||||||
|
throw new Error('Must pass callback as a function argument')
|
||||||
|
}
|
||||||
|
|
||||||
|
const idleState = this._querySystemIdleState(threshold)
|
||||||
|
|
||||||
|
process.nextTick(() => callback(idleState))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(deepak1556): Deprecate async api in favor of sync version in 5.0
|
||||||
|
powerMonitor.querySystemIdleTime = function (callback) {
|
||||||
|
if (typeof callback !== 'function') {
|
||||||
|
throw new Error('Must pass function as an argument')
|
||||||
|
}
|
||||||
|
|
||||||
|
const idleTime = this._querySystemIdleTime()
|
||||||
|
|
||||||
|
process.nextTick(() => callback(idleTime))
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = powerMonitor
|
module.exports = powerMonitor
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue