电源监视器
监视电源状态的改变。
进程:主进程
在 app
模块发出 ready
事件之前, 您不能引用或者使用此模块。
例如:
const electron = require('electron')
const { app } = electron
app.on('ready', () => {
electron.powerMonitor.on('suspend', () => {
console.log('The system is going to sleep')
})
})
powerMonitor
Monitor power state changes.
Process: Main
You cannot require or use this module until the ready
event of the app
module is emitted.
For example:
const electron = require('electron')
const { app } = electron
app.on('ready', () => {
electron.powerMonitor.on('suspend', () => {
console.log('The system is going to sleep')
})
})
事件
powerMonitor
模块触发以下事件:
Events
The powerMonitor
module emits the following events:
Event: 'suspend'
在系统挂起时触发。
Event: 'suspend'
Emitted when the system is suspending.
Event: 'resume'
在系统恢复时触发。
Event: 'resume'
Emitted when system is resuming.
Event: 'on-ac' Windows
当系统变为交流电源时触发。
Event: 'on-ac' Windows
Emitted when the system changes to AC power.
Event: 'on-battery' Windows
当系统更改为电池电量时触发。
Event: 'on-battery' Windows
Emitted when system changes to battery power.
Event: 'shutdown' Linux macOS
当系统即将重启或关机时出发 如果事件调用e.preventDefault()
, Electron 将会尝试延迟系统关机,以便 app 完全退出。 如果e.preventDefault()
被调用,在调用类似 app.quit()
后,app 会很快地退出。
Event: 'shutdown' Linux macOS
Emitted when the system is about to reboot or shut down. If the event handler invokes e.preventDefault()
, Electron will attempt to delay system shutdown in order for the app to exit cleanly. If e.preventDefault()
is called, the app should exit as soon as possible by calling something like app.quit()
.
Event: 'lock-screen' macOS Windows
当系统即将锁定屏幕时触发。
Event: 'lock-screen' macOS Windows
Emitted when the system is about to lock the screen.
Event: 'unlock-screen' macOS Windows
当系统屏幕解锁,立即触发。
Event: 'unlock-screen' macOS Windows
Emitted as soon as the systems screen is unlocked.
方法
电源监视器
模块具有以下方法:
Methods
The powerMonitor
module has the following methods:
powerMonitor.querySystemIdleState(idleThreshold, callback)
(Deprecated)
idleThreshold
Integercallback
FunctionidleState
String - Can beactive
,idle
,locked
orunknown
计算系统空闲状态。 idleThreshold
is the amount of time (in seconds) before considered idle. 回调函数
将在一些系统上同步 ,并与 idleState
参数相同,描述系统的状态。 锁定
是 仅可用于支持的系统。
powerMonitor.querySystemIdleState(idleThreshold, callback)
(Deprecated)
idleThreshold
Integercallback
FunctionidleState
String - Can beactive
,idle
,locked
orunknown
Calculate the system idle state. idleThreshold
is the amount of time (in seconds) before considered idle. callback
will be called synchronously on some systems and with an idleState
argument that describes the system's state. locked
is available on supported systems only.
powerMonitor.querySystemIdleTime(callback)
(Deprecated)
callback
FunctionidleTime
Integer - 空闲秒数
计算系统空闲时间以秒为单位。
powerMonitor.querySystemIdleTime(callback)
(Deprecated)
callback
FunctionidleTime
Integer - Idle time in seconds
Calculate system idle time in seconds.
powerMonitor.getSystemIdleState(idleThreshold)
idleThreshold
Integer
Returns String
- The system's current state. Can be active
, idle
, locked
or unknown
.
Calculate the system idle state. idleThreshold
is the amount of time (in seconds) before considered idle. locked
is available on supported systems only.
powerMonitor.getSystemIdleState(idleThreshold)
idleThreshold
Integer
Returns String
- The system's current state. Can be active
, idle
, locked
or unknown
.
Calculate the system idle state. idleThreshold
is the amount of time (in seconds) before considered idle. locked
is available on supported systems only.
powerMonitor.getSystemIdleTime()
Returns Integer
- Idle time in seconds
计算系统空闲时间以秒为单位。
powerMonitor.getSystemIdleTime()
Returns Integer
- Idle time in seconds
Calculate system idle time in seconds.