├── .npmignore ├── .github ├── FUNDING.yml └── issue_template.md ├── plugin ├── .npmignore ├── CHANGELOG.md └── package.json ├── .prettierrc ├── src ├── references.d.ts ├── index.d.ts ├── insomnia.ios.ts └── insomnia.android.ts ├── references.d.ts ├── lerna.json ├── .gitignore ├── CHANGELOG.md ├── README.md ├── tsconfig.json ├── package.json └── .eslintrc.js /.npmignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .vscode -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [farfromrefug] 2 | -------------------------------------------------------------------------------- /plugin/.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | src/ 3 | bin/ 4 | hooks/ 5 | *.ts 6 | *.old 7 | tsconfig.json 8 | !*.d.ts -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 130, 3 | "semi": true, 4 | "tabWidth": 4, 5 | "singleQuote": true 6 | } -------------------------------------------------------------------------------- /src/references.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /references.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | "plugin" 4 | ], 5 | "version": "2.0.2", 6 | "command": { 7 | "publish": { 8 | "conventionalCommits": true 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Make the screen not dim (and eventually lock the device). 3 | */ 4 | export function keepAwake(): Promise; 5 | 6 | /** 7 | * Be a good citizen and allow the device some sleep when you're done. 8 | */ 9 | export function allowSleepAgain(): Promise; 10 | -------------------------------------------------------------------------------- /src/insomnia.ios.ts: -------------------------------------------------------------------------------- 1 | export async function keepAwake() { 2 | const app = UIApplication.sharedApplication; 3 | if (!app.idleTimerDisabled) { 4 | app.idleTimerDisabled = true; 5 | } 6 | } 7 | 8 | export async function allowSleepAgain() { 9 | const app = UIApplication.sharedApplication; 10 | if (app.idleTimerDisabled) { 11 | app.idleTimerDisabled = false; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .vscode 3 | node_modules 4 | platforms 5 | hooks 6 | package-lock.json 7 | .DS_Store 8 | npm-debug.log.* 9 | demo*/app/**/*.js 10 | demo*/typings 11 | *.framework 12 | **/*.js.map 13 | src/**/*.js 14 | plugin/**/*.js 15 | plugin/**/*.d.ts 16 | bin 17 | build 18 | Pods 19 | !plugin/platforms 20 | /plugin/platforms/android/nativescript_*.aar 21 | *.xcuserdatad 22 | 23 | plugin/**/*js.map 24 | plugin/**/*js 25 | /plugin/README.md 26 | -------------------------------------------------------------------------------- /plugin/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [2.0.2](https://github.com/nativescript-community/insomnia/compare/v2.0.1...v2.0.2) (2021-01-24) 7 | 8 | **Note:** Version bump only for package @nativescript-community/insomnia 9 | 10 | 11 | 12 | 13 | 14 | ## 2.0.1 (2021-01-05) 15 | 16 | **Note:** Version bump only for package @nativescript-community/insomnia 17 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [2.0.2](https://github.com/nativescript-community/insomnia/compare/v2.0.1...v2.0.2) (2021-01-24) 7 | 8 | 9 | ### Bug Fixes 10 | 11 | * typings fix ([abbebfb](https://github.com/nativescript-community/insomnia/commit/abbebfb229e32354de1f52b4af932dfb1952f5ee)) 12 | 13 | 14 | 15 | 16 | 17 | ## 2.0.1 (2021-01-05) 18 | 19 | 20 | 21 | # 2.0.0 (2020-09-16) 22 | 23 | 24 | 25 | ## 1.2.3 (2019-06-13) 26 | 27 | 28 | 29 | ## 1.2.2 (2018-08-05) 30 | 31 | 32 | 33 | ## 1.2.1 (2017-02-10) 34 | 35 | 36 | 37 | # 1.2.0 (2016-09-23) 38 | 39 | 40 | 41 | ## 1.1.1 (2016-02-27) 42 | 43 | 44 | 45 | # 1.1.0 (2015-07-11) 46 | 47 | **Note:** Version bump only for package @nativescript-community/insomnia 48 | -------------------------------------------------------------------------------- /src/insomnia.android.ts: -------------------------------------------------------------------------------- 1 | import { Application } from '@nativescript/core'; 2 | 3 | function keepScreenOn(activity: androidx.appcompat.app.AppCompatActivity) { 4 | const window = activity.getWindow(); 5 | window.addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 6 | } 7 | export async function keepAwake() { 8 | const activity = Application.android.foregroundActivity || Application.android.startActivity; 9 | if (activity) { 10 | keepScreenOn(activity); 11 | } else { 12 | Application.android.once('activityStarted', () => keepScreenOn(activity)); 13 | } 14 | } 15 | 16 | export async function allowSleepAgain() { 17 | const activity = Application.android.foregroundActivity || Application.android.startActivity; 18 | if (activity) { 19 | const window = activity.getWindow(); 20 | window.clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@nativescript-community/insomnia", 3 | "version": "2.0.2", 4 | "description": "Make the screen not dim (and eventually lock the device) while Insomnia is active.", 5 | "main": "./insomnia", 6 | "sideEffects": false, 7 | "typings": "./index.d.ts", 8 | "nativescript": { 9 | "platforms": { 10 | "ios": "7.0.0", 11 | "android": "7.0.0" 12 | } 13 | }, 14 | "keywords": [ 15 | "NativeScript", 16 | "Insomnia", 17 | "Screen dim", 18 | "dim", 19 | "lock", 20 | "sleep" 21 | ], 22 | "author": { 23 | "name": "Eddy Verbruggen", 24 | "email": "eddyverbruggen@gmail.com" 25 | }, 26 | "bugs": { 27 | "url": "https://github.com/nativescript-community/insomnia/issues" 28 | }, 29 | "license": "MIT", 30 | "homepage": "https://github.com/nativescript-community/insomnia", 31 | "readmeFilename": "README.md" 32 | } 33 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | ### Make sure to check the demo app(s) for sample usage 2 | 3 | ### Make sure to check the existing issues in this repository 4 | 5 | ### If the demo apps cannot help and there is no issue for your problem, tell us about it 6 | Please, ensure your title is less than 63 characters long and starts with a capital 7 | letter. 8 | 9 | ### Which platform(s) does your issue occur on? 10 | - iOS/Android/Both 11 | - iOS/Android versions 12 | - emulator or device. What type of device? 13 | 14 | ### Please, provide the following version numbers that your issue occurs with: 15 | 16 | - CLI: (run `tns --version` to fetch it) 17 | - Cross-platform modules: (check the 'version' attribute in the 18 | `node_modules/tns-core-modules/package.json` file in your project) 19 | - Runtime(s): (look for the `"tns-android"` and `"tns-ios"` properties in the `package.json` file of your project) 20 | - Plugin(s): (look for the version numbers in the `package.json` file of your 21 | project and paste your dependencies and devDependencies here) 22 | 23 | ### Please, tell us how to recreate the issue in as much detail as possible. 24 | Describe the steps to reproduce it. 25 | 26 | ### Is there any code involved? 27 | - provide a code example to recreate the problem 28 | - (EVEN BETTER) provide a .zip with application or refer to a repository with application where the problem is reproducible. 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NativeScript Insomnia 2 | 3 | 4 | [npm-image]:http://img.shields.io/npm/v/nativescript-community/insomnia.svg 5 | [npm-url]:https://npmjs.org/package/nativescript-community/insomnia 6 | [downloads-image]:http://img.shields.io/npm/dm/nativescript-community/insomnia.svg 7 | 8 | > 💡 Plugin version 2.0.0+ is compatible with NativeScript 7+. If you need to target older NativeScript versions, please stick to plugin version 1.2.3. 9 | 10 | ## Demo app (Angular) 11 | This plugin is part of the [plugin showcase app](https://github.com/EddyVerbruggen/nativescript-pluginshowcase/tree/master/app/ar) I built using Angular. 12 | 13 | ## Installation 14 | Run the following command from the root of your project: 15 | 16 | ``` 17 | tns plugin add @nativescript-community/insomnia 18 | ``` 19 | 20 | ## Usage 21 | 22 | To use this plugin you must first require() it: 23 | 24 | #### JavaScript 25 | ```js 26 | var insomnia = require("@nativescript-community/insomnia"); 27 | ``` 28 | 29 | #### TypeScript 30 | You could do the same as in JS, but this looks fancier, right? 31 | 32 | ```typescript 33 | import { keepAwake, allowSleepAgain } from "@nativescript-community/insomnia"; 34 | ``` 35 | 36 | ### keepAwake 37 | 38 | ```typescript 39 | insomnia.keepAwake().then(function() { 40 | console.log("Insomnia is active"); 41 | }) 42 | ``` 43 | 44 | ### allowSleepAgain 45 | 46 | ```typescript 47 | insomnia.allowSleepAgain().then(function() { 48 | console.log("Insomnia is inactive, good night!"); 49 | }) 50 | ``` 51 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2017", 4 | "module": "esnext", 5 | "moduleResolution": "node", 6 | "removeComments": false, 7 | "noLib": false, 8 | "emitDecoratorMetadata": false, 9 | "experimentalDecorators": true, 10 | "lib": ["es6", "dom"], 11 | "sourceMap": true, 12 | "pretty": true, 13 | "allowUnreachableCode": false, 14 | "allowUnusedLabels": false, 15 | "noEmitHelpers": true, 16 | "noEmitOnError": false, 17 | "noImplicitAny": false, 18 | "noImplicitReturns": true, 19 | "noImplicitUseStrict": true, 20 | "noFallthroughCasesInSwitch": true, 21 | "sourceRoot": "../src", 22 | "baseUrl": ".", 23 | "outDir": "./plugin", 24 | "paths": { 25 | "tns-core-modules": ["./node_modules/@nativescript/core"], 26 | "tns-core-modules/*": ["./node_modules/@nativescript/core/*"], 27 | "@nativescript-community/insomnia": ["src/index"], 28 | "@nativescript-community/insomnia/*": ["src/*"], 29 | "*": ["node_modules/*"] 30 | }, 31 | "plugins": [ 32 | { "transform": "./node_modules/@nativescript/webpack/transformers/ns-transform-native-classes", "type": "raw" } 33 | ] 34 | }, 35 | "include": ["src/**/*", "./references.d.ts"], 36 | "exclude": ["node_modules", "platforms"], 37 | "compileOnSave": false, 38 | "angularCompilerOptions": { 39 | "skipTemplateCodegen": true 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@nativescript-community/insomnia", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "setup": "ts-patch install", 6 | "prepare": "npm run setup", 7 | "tsc": "cp src/index.d.ts plugin && tsc -skipLibCheck -d", 8 | "build": "cp README.md plugin && rm -f .tsbuildinfo && npm run tsc", 9 | "publish": "npm run setup && npm run build && lerna publish --create-release=github", 10 | "clean": "rimraf plugin/ios plugin/android plugin/**/*.d.ts plugin/**/*.js plugin/**/*.js.map plugin/node_modules plugin/package-lock.json", 11 | "plugin.watch.tsc": "npm run tsc -- -w", 12 | "plugin.watch.android": "npm i && npm-watch build.android", 13 | "plugin.watch.ios": "npm i && npm-watch build.ios", 14 | "plugin.watch": "npm run plugin.watch.tsc & npm run plugin.watch.android & npm run plugin.watch.ios" 15 | }, 16 | "devDependencies": { 17 | "@commitlint/cli": "^11.0.0", 18 | "@commitlint/config-conventional": "^11.0.0", 19 | "@nativescript/core": "7.1.0", 20 | "@nativescript/types-android": "7.1.0", 21 | "@nativescript/types-ios": "7.1.0", 22 | "@nativescript/webpack": "~4.0.0", 23 | "@types/node": "^10.12.21", 24 | "@typescript-eslint/eslint-plugin": "4.12.0", 25 | "@typescript-eslint/parser": "4.12.0", 26 | "eslint": "7.17.0", 27 | "eslint-config-prettier": "^7.1.0", 28 | "eslint-plugin-prettier": "^3.3.1", 29 | "husky": "^4.3.6", 30 | "lerna": "^3.22.1", 31 | "npm-watch": "^0.7.0", 32 | "prettier": "^2.2.1", 33 | "prompt": "^1.1.0", 34 | "rimraf": "^3.0.2", 35 | "ts-patch": "1.3.1", 36 | "typescript": "~3.9.7" 37 | }, 38 | "repository": { 39 | "type": "git", 40 | "url": "git+https://github.com/nativescript-community/insomnia.git" 41 | }, 42 | "author": "Eddy Verbruggen (https://github.com/EddyVerbruggen)", 43 | "license": "MIT", 44 | "bugs": { 45 | "url": "https://github.com/nativescript-community/insomnia/issues" 46 | }, 47 | "homepage": "https://github.com/nativescript-community/insomnia#readme", 48 | "dependencies": { 49 | "ts-node": "^9.1.1" 50 | } 51 | } -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['plugin:prettier/recommended'], 3 | plugins: ['prettier', '@typescript-eslint'], 4 | parser: '@typescript-eslint/parser', 5 | parserOptions: { 6 | createDefaultProgram: true, 7 | project: './tsconfig.json', 8 | }, 9 | rules: { 10 | 'prettier/prettier': 'warn', 11 | '@typescript-eslint/adjacent-overload-signatures': 'error', 12 | '@typescript-eslint/array-type': 'error', 13 | '@typescript-eslint/await-thenable': 'error', 14 | '@typescript-eslint/ban-types': 'off', 15 | '@typescript-eslint/class-name-casing': 'off', 16 | '@typescript-eslint/consistent-type-assertions': 'error', 17 | '@typescript-eslint/consistent-type-definitions': 'error', 18 | '@typescript-eslint/explicit-member-accessibility': [ 19 | 'off', 20 | { 21 | accessibility: 'explicit', 22 | }, 23 | ], 24 | 25 | '@typescript-eslint/interface-name-prefix': 'off', 26 | '@typescript-eslint/member-delimiter-style': 'error', 27 | '@typescript-eslint/member-ordering': 'off', 28 | '@typescript-eslint/no-empty-function': 'off', 29 | '@typescript-eslint/no-empty-interface': 'off', 30 | '@typescript-eslint/no-explicit-any': 'off', 31 | '@typescript-eslint/no-floating-promises': 'off', 32 | '@typescript-eslint/no-inferrable-types': 'off', 33 | '@typescript-eslint/no-misused-new': 'off', 34 | '@typescript-eslint/no-namespace': 'off', 35 | '@typescript-eslint/no-parameter-properties': 'off', 36 | '@typescript-eslint/no-require-imports': 'off', 37 | '@typescript-eslint/no-unnecessary-qualifier': 'error', 38 | '@typescript-eslint/no-unnecessary-type-assertion': 'error', 39 | '@typescript-eslint/no-use-before-declare': 'off', 40 | '@typescript-eslint/no-var-requires': 'off', 41 | '@typescript-eslint/prefer-for-of': 'off', 42 | '@typescript-eslint/prefer-function-type': 'error', 43 | '@typescript-eslint/prefer-namespace-keyword': 'error', 44 | '@typescript-eslint/quotes': [ 45 | 'error', 46 | 'single', 47 | { 48 | avoidEscape: true, 49 | }, 50 | ], 51 | '@typescript-eslint/semi': ['error'], 52 | '@typescript-eslint/space-within-parens': ['off', 'never'], 53 | '@typescript-eslint/triple-slash-reference': 'off', 54 | '@typescript-eslint/type-annotation-spacing': 'error', 55 | '@typescript-eslint/unified-signatures': 'error', 56 | 'arrow-body-style': 'error', 57 | 'arrow-parens': ['off', 'as-needed'], 58 | camelcase: 'off', 59 | 'capitalized-comments': 'off', 60 | complexity: 'off', 61 | 'constructor-super': 'error', 62 | curly: ['error', 'multi-line'], 63 | 'dot-notation': 'off', 64 | 'eol-last': 'error', 65 | eqeqeq: ['error', 'smart'], 66 | 'guard-for-in': 'off', 67 | 'id-blacklist': ['error', 'any', 'string', 'boolean', 'Undefined'], 68 | 'id-match': 'error', 69 | 'sort-imports': [ 70 | 'error', 71 | { 72 | ignoreCase: false, 73 | ignoreDeclarationSort: true, 74 | ignoreMemberSort: false, 75 | memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'], 76 | }, 77 | ], 78 | 'linebreak-style': 'off', 79 | 'max-classes-per-file': 'off', 80 | 'max-len': [ 81 | 'off', 82 | { 83 | ignorePattern: '^import |^export {(.*?)}', 84 | code: 200, 85 | }, 86 | ], 87 | 'new-parens': 'off', 88 | 'newline-per-chained-call': 'off', 89 | 'no-bitwise': 'off', 90 | 'no-caller': 'error', 91 | 'no-cond-assign': 'off', 92 | 'no-console': [ 93 | 'off', 94 | { 95 | allow: [ 96 | 'log', 97 | 'warn', 98 | 'dir', 99 | 'timeLog', 100 | 'assert', 101 | 'clear', 102 | 'count', 103 | 'countReset', 104 | 'group', 105 | 'groupEnd', 106 | 'table', 107 | 'debug', 108 | 'dirxml', 109 | 'error', 110 | 'groupCollapsed', 111 | 'Console', 112 | 'profile', 113 | 'profileEnd', 114 | 'timeStamp', 115 | 'context', 116 | ], 117 | }, 118 | ], 119 | 'no-constant-condition': 'error', 120 | 'no-control-regex': 'off', 121 | 'no-debugger': 'error', 122 | 'no-duplicate-imports': 'error', 123 | 'no-empty': 'off', 124 | 'no-eval': 'off', 125 | 'no-extra-semi': 'off', 126 | 'no-fallthrough': 'error', 127 | 'no-invalid-regexp': 'error', 128 | 'no-invalid-this': 'off', 129 | 'no-irregular-whitespace': 'off', 130 | 'no-multiple-empty-lines': 'off', 131 | 'no-new-wrappers': 'error', 132 | 'no-redeclare': ['error', { builtinGlobals: false }], 133 | 'no-regex-spaces': 'error', 134 | 'no-return-await': 'error', 135 | 'no-shadow': [ 136 | 'off', 137 | { 138 | hoist: 'all', 139 | }, 140 | ], 141 | 'no-throw-literal': 'error', 142 | 'no-trailing-spaces': 'error', 143 | 'no-undef-init': 'error', 144 | 'no-underscore-dangle': 'off', 145 | 'no-unsafe-finally': 'error', 146 | 'no-unused-expressions': [ 147 | 'error', 148 | { 149 | allowTaggedTemplates: true, 150 | allowShortCircuit: true, 151 | }, 152 | ], 153 | 'no-unused-labels': 'error', 154 | 'no-var': 'error', 155 | 'object-shorthand': 'error', 156 | 'one-var': ['off', 'never'], 157 | 'prefer-arrow/prefer-arrow-functions': 'off', 158 | 'prefer-const': 'error', 159 | 'quote-props': 'off', 160 | radix: 'error', 161 | 'space-before-function-paren': 'off', 162 | 'use-isnan': 'error', 163 | 'valid-typeof': 'off', 164 | }, 165 | }; 166 | --------------------------------------------------------------------------------