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 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-insomnia-xjp

v0.0.53

Published

Commontime cordova insomnia plugin.

Downloads

4

Readme

cordova-plugin-insomnia-xjp

Cordova plugin for keeping your android and iOS device awake.

Important to bear in mind if using across both Android and iOS:

Due to platform limitations on iOS the plugin's behavior is limited to enabling or disabling background running when the app is dismissed by the user when pressing the home button. But compared to Android, when using this plugin on an iOS device:

  • Background running cannot be restarted if it is killed off by the user or OS
  • The app or background running cannot be started after the device has turned on or restarted
  • It is not possible to turn on the screen or unlock the device.

App store submission for iOS:

To achieve the insomnia ability the plugin private API's and therefore will most likely be rejected on an app store submission.

Android

Wake lock

If you need to keep the CPU running in order to complete some work before the device goes to sleep, you can use a PowerManager system service feature called wake locks. Wake locks allow your application to control the power state of the host device.

plugins.insomnia.acquireWakeLock( function() {
    console.info("done");
}, function(error) {
    console.error(error);
});
plugins.insomnia.releaseWakeLock( function() {
    console.info("done");
}, function(error) {
    console.error(error);
});

Battery optimization

Request to place the app on the battery optimization white-list. An app that is whitelisted can use the network and hold partial wake locks during Doze and App Standby. However, other restrictions still apply to the whitelisted app, just as they do to other apps.

https://developer.android.com/training/monitoring-device-state/doze-standby.html

plugins.insomnia.stopBatteryOptimization( function() {
    console.info("done");
}, function(error) {
    console.error(error);
});
plugins.insomnia.isIgnoringBatteryOptimization( function(response) {   
    console.log(response.isIgnoringBatteryOptimization);
}, function() {});

App Restart Service

Enables/disables a service that restarts the app if it is closed by the user or by the OS.

plugins.insomnia.enableRestartService( function(response) {   
    console.info("done");
}, function(error) {
    console.error(error);
}, {
    "enable": true
});

Foreground service

Enables/disables a the icon in the status bar that helps keep the app from being stopped.

https://developer.android.com/guide/components/services.html#Foreground

plugins.insomnia.enableForegroundService( function(response) {   
    console.info("done");
}, function(error) {
    console.error(error);
}, {
    "enable": true
});

eg:

plugins.insomnia.acquireWakeLock( function() {
    plugins.insomnia.stopBatteryOptimization( function() {
        connect();
    }, function() {
        alert("Rejected!");
    });       
}, function() {
    alert("broken!");
});

Alternatively, you can start the wakelock and stop battery optimizations on start-up by using plugin variables:

cordova plugins add ../cordova-plugin-insomnia-xjp 
    --variable WAKELOCK=true
    --variable BATTOP=true
    --variable FGSERVICEENABLED=true
    --variable FGSERVICEMAIN="Foreground service"
    --variable FGSERVICESUB="..."
    --variable APPRESTARTSERVICE=true
    --variable STARTONBOOT=true
    --save
<plugin name="cordova-plugin-insomnia-xjp" spec="../cordova-plugin-insomnia-xjp">
    <variable name="WAKELOCK" value="true"/>
    <variable name="BATTOP" value="true"/>
    <variable name="FGSERVICEENABLED" value="true"/>
    <variable name="FGSERVICEMAIN" value="Incident Responder"/>
    <variable name="FGSERVICESUB" value="..."/>
    <variable name="APPRESTARTSERVICE" value="true"/>
    <variable name="STARTONBOOT" value="true"/>
</plugin>

Turning on the screen and unlocking for app

plugins.insomnia.switchOnScreenAndForeground(function() {console.log("done");}, function() {console.error("error");}, {
  "showWhenLocked": true,  // default true
  "turnScreenOn": true,    // default true
  "dismissKeyGuard": true, // default true
  "keepScreenOn": true     // default true
});

showWhenLocked:

Flag to let windows be shown when the screen is locked. This will let application windows take precedence over key guard or any other lock screens. Can be used with keepScreenOn to turn screen on and display windows directly before showing the key guard window. Can be used with dismissKeyGuard to automatically fully dismisss non-secure keyguards.

turnScreenOn:

Poke the power manager's user activity (as if the user had woken up the device) to turn the screen on.

dismissKeyGuard:

Cause the keyguard to be dismissed, only if it is not a secure lock keyguard. Because such a keyguard is not needed for security, it will never re-appear if the user navigates to another window (in contrast to showWhenLocked, which will only temporarily hide both secure and non-secure keyguards but ensure they reappear when the user moves to another UI that doesn't hide them). If the keyguard is currently active and is secure (requires an unlock credential) than the user will still need to confirm it before seeing this window, unless showWhenLocked has also been set.

keepScreenOn:

As long as this window is visible to the user, keep the device's screen turned on and bright.

plugins.insomnia.clearKeepScreenOn(function() {console.log("done");}, function() {console.error("failed!"});

Allows the screen to go off again

iOS

Funtionality on iOS is very limited; it is only possible to enbale or disable the insomnia ability. Please note that the following functions are iOS only. If you try to call them from an Android device the error callback will be fired along with the message "iOS Only". The same principle applies if you are on an iOS device and try to call a function under the Android section. In this case you will get the message "Android Only" in the error callback.

enable:

plugins.insomnia.enable( function(response) {   
    console.info("done");
}, function(error) {
    console.error(error);
}, {
    "enable": true
});

disable

plugins.insomnia.disable( function(response) {   
    console.info("done");
}, function(error) {
    console.error(error);
}, {
    "enable": false
});

Foregrounding the app

plugins.insomnia.switchOnScreenAndForeground(function() {console.log("done");}, function() {console.error("error");});