Skip to main content

powerMonitor

powerMonitor

监视电源状态变化。

¥Monitor power state changes.

进程:主进程

¥Process: Main

事件

¥Events

powerMonitor 模块发出以下事件:

¥The powerMonitor module emits the following events:

事件:'suspend'

¥Event: 'suspend'

当系统挂起时发出。

¥Emitted when the system is suspending.

事件:'resume'

¥Event: 'resume'

系统恢复时发出。

¥Emitted when system is resuming.

事件:'on-ac' macOS Windows

¥Event: 'on-ac' macOS Windows

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

¥Emitted when the system changes to AC power.

事件:'on-battery' macOS Windows

¥Event: 'on-battery' macOS Windows

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

¥Emitted when system changes to battery power.

事件:'thermal-state-change' macOS

¥Event: 'thermal-state-change' macOS

  • state 字符串 - 系统的新热状态。可以是 unknownnominalfairseriouscritical

    ¥state string - The system's new thermal state. Can be unknown, nominal, fair, serious, critical.

当系统的热状态发生变化时发出。系统热状态变化的通知,例如进入临界温度范围。根据严重程度,系统可能会采取措施降低所述温度,例如,限制 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

事件:'speed-limit-change' macOS Windows

¥Event: 'speed-limit-change' macOS Windows

  • limit 数字 - 操作系统公布的 CPU 速度限制(以百分比为单位)。

    ¥limit number - The operating system's advertised speed limit for CPUs, in percent.

操作系统公布的 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.

事件:'shutdown' Linux macOS

¥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().

事件:'lock-screen' macOS Windows

¥Event: 'lock-screen' macOS Windows

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

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

事件:'unlock-screen' macOS Windows

¥Event: 'unlock-screen' macOS Windows

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

¥Emitted as soon as the systems screen is unlocked.

事件:'user-did-become-active' macOS

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

激活登录会话时发出。请参阅 documentation 了解更多信息。

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

事件:'user-did-resign-active' macOS

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

当登录会话停用时发出。请参阅 documentation 了解更多信息。

¥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 整数

    ¥idleThreshold Integer

返回 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 属性。如果系统使用电池供电,则为 true。

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

参见 powerMonitor.isOnBatteryPower()

¥See powerMonitor.isOnBatteryPower().