powerSaveBlocker
阻止系统进入低功耗(睡眠)模式。
进程:主进程
🌐 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字符串 - 节能阻止器类型。prevent-app-suspension- 防止应用被挂起。保持系统活跃,但允许关闭屏幕。示例用例:下载文件或播放音频。prevent-display-sleep- 防止显示屏进入睡眠状态。保持系统和屏幕处于活动状态。使用示例:播放视频。
返回 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。
例如,一个调用 A 的 API 请求 prevent-app-suspension,另一个调用 B 的 API 请求 prevent-display-sleep。在 B 停止请求之前,将使用 prevent-display-sleep。之后,将使用 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。
停止指定的省电阻止程序。
🌐 Stops the specified power save blocker.
返回 boolean - 指定的 powerSaveBlocker 是否已被停止。
🌐 Returns boolean - Whether the specified powerSaveBlocker has been stopped.
powerSaveBlocker.isStarted(id)
id整数 - 由powerSaveBlocker.start返回的省电阻止器 ID。
返回 boolean - 对应的 powerSaveBlocker 是否已开始。
🌐 Returns boolean - Whether the corresponding powerSaveBlocker has started.