跳过内容

开始获取

GitHub

您可以使用我们的AI辅助设置来安装插件。使用以下命令将Capgo技能添加到您的AI工具中:

终端窗口
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

然后使用以下提示:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-keep-awake` plugin in my project.

如果您更喜欢手动设置,请运行以下命令安装插件并遵循以下平台特定的说明:

终端窗口
bun add @capgo/capacitor-keep-awake
bunx cap sync
import { KeepAwake } from '@capgo/capacitor-keep-awake';

防止设备屏幕暗化

import { KeepAwake } from '@capgo/capacitor-keep-awake';
await KeepAwake.keepAwake();
console.log('Screen will stay awake');

允许设备降低屏幕亮度(禁用保持唤醒)。

import { KeepAwake } from '@capgo/capacitor-keep-awake';
await KeepAwake.allowSleep();
console.log('Screen can now dim');

检查当前平台上是否支持保持唤醒功能。

import { KeepAwake } from '@capgo/capacitor-keep-awake';
const { isSupported } = await KeepAwake.isSupported();
if (isSupported) {
console.log('Keep awake is supported');
}

检查设备是否当前正在保持唤醒。

import { KeepAwake } from '@capgo/capacitor-keep-awake';
const { isKeptAwake } = await KeepAwake.isKeptAwake();
console.log('Is kept awake:', isKeptAwake);

isSupported()方法的返回结果

export interface IsSupportedResult {
/**
* Whether keep awake is supported on the current platform.
*
* @since 1.0.0
*/
isSupported: boolean;
}

isKeptAwake()方法的返回结果

export interface IsKeptAwakeResult {
/**
* Whether the device is currently being kept awake.
*
* @since 1.0.0
*/
isKeptAwake: boolean;
}

本页面是由插件的 src/definitions.ts. 当公共API上游发生变化时,请重新运行同步。

If you are using Getting Started 为计划仪表板和API操作而设计 使用@capgo/capacitor-keep-awake 为native能力在使用@capgo/capacitor-keep-awake API概述 为API实现细节 介绍 为介绍实现细节 API密钥 为API密钥实现细节 设备 __CAPGO_KEEP_0__