Prevent or allow device sleep in a Nativescript application
npm i --save @angelengineering/sleepcontrol


Nativescript Sleepcontrol apple android


This plugin allows you to keep your device awake while the current app is running, or allow it to sleep while the current app is running. This will not affect other apps, and the screen will be prevented from sleep only while the current application is running.



npm install @angelengineering/sleepcontrol --save


ns plugin add @angelengineering/sleepcontrol


The best way to explore the usage of the plugin is to inspect the demo app in the plugin repository. In apps/demo folder you can find the usage of the plugin for TypeScript non-Angular application. Refer to apps/demo/src/plugin-demos/sleepcontrol.ts.

In short here are the steps:

Import the plugin functions


import { allowSleep, denySleep, isSleepAllowed } from '@angelengineering/sleepcontrol';

Use the plugin

if (isSleepAllowed()) console.log("success!")

if (!isSleepAllowed()) console.log("success!")

Exposed functions

* Check if the current device can go into sleep mode after the current system idle time limit. Use denySleep() to disable sleep, and allowSleep() to enable sleep.
* @function isSleepAllowed
* @returns true if sleep is allowed, false if not
export function isSleepAllowed(): boolean;

* Disable device sleep mode
* @function denySleep
export function denySleep(): void;

* Enable device sleep mode
* @function allowSleep
export function allowSleep(): void;


Apache License Version 2.0