powerSaveBlocker
阻止系统进入低功耗(睡眠)模式。
¥Block the system from entering low-power (sleep) mode.
进程:主进程
¥Process: Main
例如:
¥For example:
const { powerSaveBlocker } = require('electron')
const id = powerSaveBlocker.start('prevent-display-sleep')
console.log(powerSaveBlocker.isStarted(id))
powerSaveBlocker.stop(id)
方法
¥Methods
powerSaveBlocker
模块有以下方法:
¥The powerSaveBlocker
module has the following methods:
powerSaveBlocker.start(type)
-
type
字符串 - 省电拦截器类型。¥
type
string - Power save blocker type.-
prevent-app-suspension
- 防止应用被暂停。保持系统活动但允许屏幕关闭。示例用例:下载文件或播放音频。¥
prevent-app-suspension
- Prevent the application from being suspended. Keeps system active but allows screen to be turned off. Example use cases: downloading a file or playing audio. -
prevent-display-sleep
- 防止显示器进入睡眠状态。保持系统和屏幕处于活动状态。示例用例:播放视频。¥
prevent-display-sleep
- Prevent the display from going to sleep. Keeps system and screen active. Example use case: playing video.
-
返回 Integer
- 分配给该电源阻断器的阻断器 ID。
¥Returns Integer
- The blocker ID that is assigned to this power blocker.
开始阻止系统进入低功耗模式。返回一个整数,标识节能阻止程序。
¥Starts preventing the system from entering lower-power mode. Returns an integer identifying the power save blocker.
注意:prevent-display-sleep
的优先级高于 prevent-app-suspension
。仅最高优先级类型生效。换句话说,prevent-display-sleep
始终优先于 prevent-app-suspension
。
¥Note: prevent-display-sleep
has higher precedence over
prevent-app-suspension
. Only the highest precedence type takes effect. In
other words, prevent-display-sleep
always takes precedence over
prevent-app-suspension
.
例如,调用 A 的 API 请求 prevent-app-suspension
,另一个调用 B 的 API 请求 prevent-display-sleep
。prevent-display-sleep
将被使用,直到 B 停止其请求。之后,使用 prevent-app-suspension
。
¥For example, an API calling A requests for prevent-app-suspension
, and
another calling B requests for prevent-display-sleep
. prevent-display-sleep
will be used until B stops its request. After that, prevent-app-suspension
is used.
powerSaveBlocker.stop(id)
-
id
整数 -powerSaveBlocker.start
返回的省电阻止程序 ID。¥
id
Integer - The power save blocker id returned bypowerSaveBlocker.start
.
停止指定的省电阻止程序。
¥Stops the specified power save blocker.
返回 boolean
- 指定的 powerSaveBlocker
是否已停止。
¥Returns boolean
- Whether the specified powerSaveBlocker
has been stopped.
powerSaveBlocker.isStarted(id)
-
id
整数 -powerSaveBlocker.start
返回的省电阻止程序 ID。¥
id
Integer - The power save blocker id returned bypowerSaveBlocker.start
.
返回 boolean
- 对应的 powerSaveBlocker
是否已经启动。
¥Returns boolean
- Whether the corresponding powerSaveBlocker
has started.