File tree Expand file tree Collapse file tree 3 files changed +25
-9
lines changed
Expand file tree Collapse file tree 3 files changed +25
-9
lines changed Original file line number Diff line number Diff line change 1- var appModule = require ( "application" ) ;
1+ var app = require ( "tns-core-modules/ application" ) ;
22
33exports . keepAwake = function ( ) {
4+
5+ var keepScreenOn = function ( ) {
6+ var activity = app . android . foregroundActivity || app . android . startActivity ;
7+ var window = activity . getWindow ( ) ;
8+ window . addFlags ( android . view . WindowManager . LayoutParams . FLAG_KEEP_SCREEN_ON ) ;
9+ } ;
10+
411 return new Promise ( function ( resolve , reject ) {
512 try {
6- var window = appModule . android . currentContext . getWindow ( ) ;
7- window . addFlags ( android . view . WindowManager . LayoutParams . FLAG_KEEP_SCREEN_ON ) ;
8- resolve ( ) ;
13+
14+ if ( app . android . foregroundActivity || app . android . startActivity ) {
15+ keepScreenOn ( ) ;
16+ resolve ( ) ;
17+ } else {
18+ app . android . on ( "activityStarted" , function ( args ) {
19+ keepScreenOn ( ) ;
20+ resolve ( ) ;
21+ } ) ;
22+ }
23+
924 } catch ( ex ) {
1025 console . log ( "Error in insomnia.keepAwake: " + ex ) ;
1126 reject ( ex ) ;
@@ -16,12 +31,13 @@ exports.keepAwake = function () {
1631exports . allowSleepAgain = function ( ) {
1732 return new Promise ( function ( resolve , reject ) {
1833 try {
19- var window = appModule . android . currentContext . getWindow ( ) ;
34+ var activity = app . android . foregroundActivity || app . android . startActivity ;
35+ var window = activity . getWindow ( ) ;
2036 window . clearFlags ( android . view . WindowManager . LayoutParams . FLAG_KEEP_SCREEN_ON ) ;
2137 resolve ( ) ;
2238 } catch ( ex ) {
2339 console . log ( "Error in insomnia.allowSleepAgain: " + ex ) ;
2440 reject ( ex ) ;
2541 }
2642 } ) ;
27- } ;
43+ } ;
Original file line number Diff line number Diff line change 1- var utils = require ( "utils/utils" ) ;
1+ var utils = require ( "tns-core-modules/ utils/utils" ) ;
22
33exports . keepAwake = function ( ) {
44 return new Promise ( function ( resolve , reject ) {
@@ -28,4 +28,4 @@ exports.allowSleepAgain = function () {
2828 reject ( ex ) ;
2929 }
3030 } ) ;
31- } ;
31+ } ;
Original file line number Diff line number Diff line change 11{
22 "name" : " nativescript-insomnia" ,
3- "version" : " 1.2.1 " ,
3+ "version" : " 1.2.2 " ,
44 "description" : " Make the screen not dim (and eventually lock the device) while Insomnia is active" ,
55 "main" : " insomnia" ,
66 "typings" : " index.d.ts" ,
You can’t perform that action at this time.
0 commit comments