- powerMonitor
- 事件
- Event: ‘suspend’
- Event: ‘resume’
- Event: ‘on-ac’ macOS Windows
- Event: ‘on-battery’ macOS Windows
- Event: ‘thermal-state-change’ macOS
- Event: ‘speed-limit-change’ macOS Windows
- Event: ‘shutdown’ Linux macOS
- Event: ‘lock-screen’ macOS Windows
- Event: ‘unlock-screen’ macOS Windows
- 事件: ‘user-did-groupe-active’ macOS
- 事件: ‘user-did-resign-active’ macOS
- 方法
- 属性
- 事件
powerMonitor
监视电源状态的改变。
进程:主进程
事件
powerMonitor
模块触发以下事件:
Event: ‘suspend’
在系统挂起时触发。
Event: ‘resume’
在系统恢复时触发。
Event: ‘on-ac’ macOS Windows
当系统变为交流电源时触发。
Event: ‘on-battery’ macOS Windows
当系统更改为电池电量时触发。
Event: ‘thermal-state-change’ macOS
state
string - The system’s new thermal state. Can beunknown
,nominal
,fair
,serious
,critical
.
Emitted when the thermal state of the system changes. Notification of a change in the thermal status of the system, such as entering a critical temperature range. Depending on the severity, the system might take steps to reduce said temperature, for example, throttling the CPU or switching on the fans if available.
Apps may react to the new state by reducing expensive computing tasks (e.g. video encoding), or notifying the user. The same state might be received repeatedly.
Event: ‘speed-limit-change’ macOS Windows
limit
number - The operating system’s advertised speed limit for CPUs, in percent.
Notification of a change in the operating system’s advertised speed limit for CPUs, in percent. Values below 100 indicate that the system is impairing processing power due to thermal management.
Event: ‘shutdown’ Linux macOS
当系统即将重启或关机时触发。 如果事件调用e.preventDefault()
, Electron 将会尝试延迟系统关机,以便 app 完全退出。 如果e.preventDefault()
被调用,在调用类似 app.quit()
后,app 会很快地退出。
Event: ‘lock-screen’ macOS Windows
当系统即将锁定屏幕时触发。
Event: ‘unlock-screen’ macOS Windows
当系统屏幕解锁,立即触发。
事件: ‘user-did-groupe-active’ macOS
当应用被激活时发出。 更多信息请访问 文档。
事件: ‘user-did-resign-active’ macOS
当应用被激活时发出。 更多信息请访问 文档。
方法
电源监视器
模块具有以下方法:
powerMonitor.getSystemIdleState(idleThreshold)
idleThreshold
Integer
Returns string
- The system’s current idle state. 可以是 active
、 idle
、 locked
或 unknown
。
计算系统空闲状态。 idleThreshold
是闲置之前 (秒内) 的时间量。 locked
仅在支持的系统上可用。
powerMonitor.getSystemIdleTime()
Returns Integer
- 几秒钟内的空闲时间
计算系统空闲时间以秒为单位。
powerMonitor.getCurrentThermalState()
macOS
Returns string
- The system’s current thermal state. 可以是 unknown
、nominal
、fair
、serious
或 critical
。
powerMonitor.isOnBatteryPower()
返回boolean
,表示系统是否使用电池电源。
要监视此属性的变化,请使用 on-battery
和 on-ac<
事件。
属性
powerMonitor.onBatteryPower
boolean
属性。 如果系统处于电池电源状态,则为 true。