Skip to main content

powerMonitor

监控电源状态变化。

进程:主进程

🌐 Process: Main

事件

🌐 Events

powerMonitor 模块会触发以下事件:

🌐 The powerMonitor module emits the following events:

Event: 'suspend'

当系统挂起时发出。

🌐 Emitted when the system is suspending.

Event: 'resume'

系统恢复时发出。

🌐 Emitted when system is resuming.

Event: 'on-ac' macOS Windows

当系统更改为交流电源时发出。

🌐 Emitted when the system changes to AC power.

Event: 'on-battery' macOS Windows

当系统更改为电池电源时发出。

🌐 Emitted when system changes to battery power.

Event: 'thermal-state-change' macOS

返回:

🌐 Returns:

  • “details”事件<>
    • state 字符串 - 系统的新热状态。可以是 unknownnominalfairseriouscritical

当系统的热状态发生变化时发出。通知系统热状态的变化,例如进入临界温度范围。根据严重程度,系统可能会采取措施降低温度,例如限制CPU性能或开启可用的风扇。

🌐 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.

请参阅 https://developer.apple.com/library/archive/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/RespondToThermalStateChanges.html

🌐 See https://developer.apple.com/library/archive/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/RespondToThermalStateChanges.html

Event: 'speed-limit-change' macOS Windows

返回:

🌐 Returns:

  • “details”事件<>
    • limit 数字 - 操作系统所宣传的 CPU 速度上限,以百分比表示。

通知操作系统中CPU广告速度限制的变化,以百分比表示。低于100的值表示系统由于热管理而降低了处理能力。

🌐 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 将尝试延迟系统关闭,以便应用能干净地退出。如果调用了 e.preventDefault(),应用应尽快通过调用类似 app.quit() 的方法退出。

🌐 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

当系统即将锁定屏幕时发出。

🌐 Emitted when the system is about to lock the screen.

Event: 'unlock-screen' macOS Windows

系统屏幕解锁后立即发出。

🌐 Emitted as soon as the systems screen is unlocked.

Event: 'user-did-become-active' macOS

当登录会话被激活时触发。有关更多信息,请参阅文档

🌐 Emitted when a login session is activated. See documentation for more information.

Event: 'user-did-resign-active' macOS

当登录会话被停用时触发。更多信息请参见文档

🌐 Emitted when a login session is deactivated. See documentation for more information.

方法

🌐 Methods

powerMonitor 模块具有以下方法:

🌐 The powerMonitor module has the following methods:

powerMonitor.getSystemIdleState(idleThreshold)

  • idleThreshold 整数

返回 string - 系统当前的空闲状态。可以是 activeidlelockedunknown

🌐 Returns string - The system's current idle state. Can be active, idle, locked or unknown.

计算系统空闲状态。idleThreshold 是被认为空闲之前的时间(以秒为单位)。locked 仅在支持的系统上可用。

🌐 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()

返回 Integer - 空闲时间(秒)

🌐 Returns Integer - Idle time in seconds

计算系统空闲时间(以秒为单位)。

🌐 Calculate system idle time in seconds.

powerMonitor.getCurrentThermalState() macOS

返回 string - 系统当前的热状态。可以是 unknownnominalfairseriouscritical

🌐 Returns string - The system's current thermal state. Can be unknown, nominal, fair, serious, or critical.

powerMonitor.isOnBatteryPower()

返回 boolean - 系统是否正在使用电池电源。

🌐 Returns boolean - Whether the system is on battery power.

要监控此属性的变化,请使用 on-batteryon-ac 事件。

🌐 To monitor for changes in this property, use the on-battery and on-ac events.

属性

🌐 Properties

powerMonitor.onBatteryPower

boolean 属性。如果系统使用电池供电,则为真。

🌐 A boolean property. True if the system is on battery power.

请参见 powerMonitor.isOnBatteryPower()

🌐 See powerMonitor.isOnBatteryPower().