Skip to main content

powerMonitor

Monitor power state changes.监控电源状态的变化。

Process:进程:Main

Events事件

The powerMonitor module emits the following events:powerMonitor模块会发出以下事件:

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: '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. 如果事件处理程序调用e.preventDefault(),Electron将尝试延迟系统关闭,以便应用程序干净地退出。If e.preventDefault() is called, the app should exit as soon as possible by calling something like app.quit().如果调用了e.preventDefault(),应用程序应该通过调用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方法

The powerMonitor module has the following methods:powerMonitor模块具有以下方法:

powerMonitor.getSystemIdleState(idleThreshold)

  • idleThreshold Integer

Returns返回string - The system's current state. 系统的当前状态。Can be active, idle, locked or unknown.可以是activeidlelockedunknown

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空闲时间(秒)

Calculate system idle time in seconds.以秒为单位计算系统空闲时间。

powerMonitor.isOnBatteryPower()

Returns返回boolean - Whether the system is on battery power.系统是否使用电池电源。

To monitor for changes in this property, use the on-battery and on-ac events.若要监视此属性的更改,请使用on-batteryon-ac事件。

Properties属性

powerMonitor.onBatteryPower

A boolean property. boolean属性。True if the system is on battery power.如果系统使用电池供电,则为True

See powerMonitor.isOnBatteryPower().请参阅电源监视器powerMonitor.isOnBatteryPower()