Skip to content

Commit dc10aa9

Browse files
initial version
0 parents  commit dc10aa9

File tree

6 files changed

+135
-0
lines changed

6 files changed

+135
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
The MIT License (MIT)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# NativeScript Insomnia
2+
3+
Make the screen not dim (and eventually lock the device) while Insomnia is active.
4+
5+
## Installation
6+
From the command prompt go to your app's `app` folder and execute:
7+
8+
```
9+
npm install nativescript-insomnia
10+
```
11+
12+
## Usage
13+
14+
### keepAwake
15+
16+
```js
17+
var insomnia = require( "./node_modules/nativescript-insomnia/insomnia" );
18+
19+
insomnia.keepAwake().then(function() {
20+
console.log("Insomnia is active");
21+
})
22+
```
23+
24+
### allowSleepAgain
25+
26+
```js
27+
var insomnia = require( "./node_modules/nativescript-insomnia/insomnia" );
28+
29+
insomnia.allowSleepAgain().then(function() {
30+
console.log("Insomnia is inactive, good night!");
31+
})
32+
```

insomnia.android.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var appModule = require("application");
2+
3+
exports.keepAwake = function () {
4+
return new Promise(function (resolve, reject) {
5+
try {
6+
var window = appModule.android.currentContext.getWindow();
7+
window.addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
8+
resolve();
9+
} catch (ex) {
10+
console.log("Error in insomnia.keepAwake: " + ex);
11+
reject(ex);
12+
}
13+
});
14+
};
15+
16+
exports.allowSleepAgain = function () {
17+
return new Promise(function (resolve, reject) {
18+
try {
19+
var window = appModule.android.currentContext.getWindow();
20+
window.clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
21+
resolve();
22+
} catch (ex) {
23+
console.log("Error in insomnia.allowSleepAgain: " + ex);
24+
reject(ex);
25+
}
26+
});
27+
};

insomnia.ios.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
exports.keepAwake = function () {
2+
return new Promise(function (resolve, reject) {
3+
try {
4+
var app = UIApplication.sharedApplication();
5+
if (!app.idleTimerDisabled) {
6+
app.idleTimerDisabled = true;
7+
}
8+
resolve();
9+
} catch (ex) {
10+
console.log("Error in insomnia.keepAwake: " + ex);
11+
reject(ex);
12+
}
13+
});
14+
};
15+
16+
exports.allowSleepAgain = function () {
17+
return new Promise(function (resolve, reject) {
18+
try {
19+
var app = UIApplication.sharedApplication();
20+
if (app.idleTimerDisabled) {
21+
app.idleTimerDisabled = false;
22+
}
23+
resolve();
24+
} catch (ex) {
25+
console.log("Error in insomnia.allowSleepAgain: " + ex);
26+
reject(ex);
27+
}
28+
});
29+
};

package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "nativescript-insomnia",
3+
"version": "1.0.0",
4+
"description": "Make the screen not dim (and eventually lock the device) while Insomnia is active",
5+
"main": "insomnia.js",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/eddyverbruggen/nativescript-insomnia.git"
9+
},
10+
"keywords": [
11+
"NativeScript"
12+
],
13+
"author": {
14+
"name": "Eddy Verbruggen",
15+
"email": "[email protected]",
16+
"url": "http://x-services.nl/"
17+
},
18+
"license": {
19+
"type": "MIT",
20+
"url": "https://github.com/eddyverbruggen/nativescript-insomnia/blob/master/LICENSE"
21+
},
22+
"bugs": {
23+
"url": "https://github.com/eddyverbruggen/nativescript-insomnia/issues"
24+
},
25+
"homepage": "https://github.com/eddyverbruggen/nativescript-insomnia",
26+
"readmeFilename": "README.md"
27+
}

0 commit comments

Comments
 (0)