跳转至

powerMonitor

监视电源状态变化。

进程:主进程

事件

powerMonitor 模块会发出以下事件:

事件:'suspend'

当系统即将挂起时发出。

事件:'resume'

当系统恢复时发出。

事件:'on-ac' macOS Windows

当系统切换到交流电源时发出。

事件:'on-battery' macOS Windows

当系统切换到电池电源时发出。

事件:'thermal-state-change' macOS

返回值:

  • details Event\<>
  • state string - 系统的新热状态。可以是 unknown、nominal、fair、serious、critical。

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

应用可以通过减少高开销计算任务(例如视频编码)或通知用户来响应新状态。可能会重复收到相同的状态。

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

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

返回值:

  • details Event\<>
  • limit number - 操作系统为 CPU 公布的运行速度限制,以百分比表示。

用于通知操作系统为 CPU 公布的运行速度限制(以百分比表示)发生变化。低于 100 的值表示系统因热管理而降低了处理能力。

事件:'shutdown' Linux macOS

当系统即将重启或关机时发出。如果事件处理程序调用 e.preventDefault(),Electron 会尝试延迟系统关机,以便应用能够正常退出。如果调用了 e.preventDefault(),应用应尽快通过调用类似 app.quit() 的方法退出。

事件:'lock-screen' macOS Windows

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

事件:'unlock-screen' macOS Windows

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

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

当登录会话被激活时发出。更多信息请参见文档。

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

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

方法

powerMonitor 模块具有以下方法:

powerMonitor.getSystemIdleState(idleThreshold)

  • idleThreshold Integer

返回值 string - 系统当前的空闲状态。可以是 active、idle、locked 或 unknown。

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

powerMonitor.getSystemIdleTime()

返回值 Integer - 空闲时间(秒)

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

powerMonitor.getCurrentThermalState() macOS

返回值 string - 系统当前的热状态。可以是 unknown、nominal、fair、serious 或 critical。

powerMonitor.isOnBatteryPower()

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

要监视此属性的变化,请使用 on-battery 和 on-ac 事件。

属性

powerMonitor.onBatteryPower

一个 boolean 属性。如果系统使用电池电源,则为 true。

参见 powerMonitor.isOnBatteryPower()。

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 el/electron