@capacitor-community/keep-awake

中文文档
8.0.1发布于 2026/04/16MITTypeScriptESM + CJS零依赖近 30 天下载 80.8万

Prevent your screen from getting some sleep!

原始使用文档
文档目录14 节
  1. Keep Awake
  2. Maintainers
  3. Installation
  4. Configuration
  5. Demo
  6. Usage
  7. API
  8. keepAwake()
  9. allowSleep()
  10. isSupported()
  11. isKeptAwake()
  12. Interfaces
  13. Changelog
  14. License


Keep Awake

@capacitor-community/keep-awake

⚡️ Capacitor plugin to prevent devices from dimming or locking the screen.


Maintainers

MaintainerGitHubSocial
Kevin Boostenkevinboosten@kevinboosten
Robin Genzrobingenz@robin_genz

Installation

npm install @capacitor-community/keep-awake
npx cap sync

Configuration

No configuration required for this plugin.

Demo

A working example can be found in example-app folder.

Usage

import { KeepAwake } from '@capacitor-community/keep-awake';

const keepAwake = async () => {
  await KeepAwake.keepAwake();
};

const allowSleep = async () => {
  await KeepAwake.allowSleep();
};

const isSupported = async () => {
  const result = await KeepAwake.isSupported();
  return result.isSupported;
};

const isKeptAwake = async () => {
  const result = await KeepAwake.isKeptAwake();
  return result.isKeptAwake;
};

API

keepAwake()

keepAwake() => Promise<void>

Prevent the device from dimming the screen.


allowSleep()

allowSleep() => Promise<void>

Allow the device to dim the screen.


isSupported()

isSupported() => Promise<IsSupportedResult>

Whether keep awake is supported or not.

Returns: Promise<IsSupportedResult>


isKeptAwake()

isKeptAwake() => Promise<IsKeptAwakeResult>

Check if the device is kept awake.

Returns: Promise<IsKeptAwakeResult>


Interfaces

IsSupportedResult

PropType
isSupportedboolean

IsKeptAwakeResult

PropType
isKeptAwakeboolean

Changelog

See CHANGELOG.md.

License

See LICENSE.

版本与发布记录

@capacitor-community/keep-awake 共发布 23 个版本,首次发布于 2020/10/07;过去 12 个月发布了 2 个版本。

版本发布日期距今
8.0.1latest2026/04/166 个月前
8.0.02025/12/2010 个月前
7.1.02025/06/201.4 年前
7.0.02025/02/071.8 年前
6.0.02025/01/291.8 年前
5.0.1-dev.a09f5c3.1738003115dev2025/01/281.8 年前

关于 @capacitor-community/keep-awake 的常见问题

@capacitor-community/keep-awake 是什么?

Prevent your screen from getting some sleep!

如何安装 @capacitor-community/keep-awake?

在项目目录运行 npm install @capacitor-community/keep-awake,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capacitor-community/keep-awake 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capacitor-community/keep-awake 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capacitor-community/keep-awake 可以商用吗?

@capacitor-community/keep-awake 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@capacitor-community/keep-awake 的下载量有多少?

根据 npm 官方下载统计,@capacitor-community/keep-awake 在 2026/10/09 – 2026/11/07 这 30 天内被下载 807,702 次,日均约 26,923 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capacitor-community/keep-awake 还在维护吗?

最新版本 8.0.1 发布于 2026/04/16(6 个月前);至今共发布 23 个版本,其中过去 12 个月发布了 2 个;首次发布于 2020/10/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。