npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cordova-ohos/cordova-plugin-insomnia

v4.3.0

Published

Cordova Insomnia Plugin

Readme

cordova-plugin-insomnia

一个为Cordova应用提供屏幕常亮控制能力的插件,支持Android和iOS双平台,可灵活开启或关闭屏幕常亮模式。本文档主要说明在OHOS系统中的应用。

概述

在Cordova应用开发过程中,部分场景(如视频播放、扫码支付、文档阅读、导航等)需要保持屏幕持续亮屏,避免因系统自动休眠影响用户体验。cordova-plugin-insomnia插件通过封装原生平台API,为开发者提供了极简的屏幕常亮控制接口,无需深入原生开发即可实现屏幕常亮的开启、关闭及状态查询功能,且适配主流Android、iOS和OHOS系统版本。

支持平台

  • Android:API 19及以上(Android 4.4+)

  • iOS:10.0及以上

  • OHOS:5.0及以上

安装

通过Cordova CLI或Ionic CLI即可快速安装插件,支持从npm仓库或GitHub仓库获取。

从npm安装(推荐)


# hcordova
npm install -g hcordova

# Cordova CLI
hcordova plugin add cordova-plugin-insomnia

从GitCode安装(开发版本)


hcordova plugin add https://gitcode.com/OpenHarmony-Cordova/cordova-plugin-insomnia.git --platform ohos

安装指定版本


hcordova plugin add [email protected] --platform ohos

卸载


# Cordova CLI
hcordova plugin remove cordova-plugin-insomnia
# 指定OHOS卸载
hcordova plugin remove cordova-plugin-insomnia --platform ohos 

核心API

插件在全局对象window.insomnia下暴露所有功能接口,所有API均支持Promise和传统回调函数两种调用方式,满足不同开发习惯需求。

1. 开启屏幕常亮

调用该方法后,应用将保持屏幕常亮,直至调用关闭方法或应用退出前台。

方法签名


// 回调函数方式
window.insomnia.keepAwake(successCallback, errorCallback)

参数说明

|参数名|类型|说明| |---|---|---| |successCallback|Function|成功回调,无参数,仅表示常亮模式已开启| |errorCallback|Function|失败回调,参数为错误对象(含code和message属性)|

2. 关闭屏幕常亮

调用该方法后,应用将恢复系统默认的屏幕休眠策略。

方法签名


// 回调函数方式
window.insomnia.allowSleepAgain(successCallback, errorCallback)

参数说明

|参数名|类型|说明| |---|---|---| |successCallback|Function|成功回调,无参数,仅表示常亮模式已关闭| |errorCallback|Function|失败回调,参数为错误对象(含code和message属性)|

使用示例

示例1:基础使用

在页面加载时开启屏幕常亮,离开页面时关闭,适配单页面应用场景。

//设置屏幕常量
function setWindowKeepScreenOn() {
    window.plugins.insomnia.keepAwake(function(){
        document.getElementById("keepOn1").innerHTML = "设置成功";
    });
}

//关闭屏幕常量
function setWindowKeepScreenOff() {
    window.plugins.insomnia.allowSleepAgain(function(){
        document.getElementById("keepOn2").innerHTML = "设置成功";
    });
}

许可证

本插件基于 Apache License 开源,详见 LICENSE 文件。

资源参考

  1. OHOShttps://gitcode.com/OpenHarmony-Cordova/cordova-plugin-insomnia

  2. Android、ios插件说明https://www.npmjs.com/package/cordova-plugin-insomnia