@gachlab/capacitor-keep-awake-plugin 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/GachlabCapacitorKeepAwakePlugin.podspec +17 -0
- package/Package.swift +28 -0
- package/README.md +45 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/gachlab/capacitor/keepawake/KeepAwake.java +34 -0
- package/android/src/main/java/com/gachlab/capacitor/keepawake/KeepAwakePlugin.java +36 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +35 -0
- package/dist/esm/definitions.d.ts +8 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +10 -0
- package/dist/esm/web.js +10 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +26 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +29 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/KeepAwakePlugin/KeepAwake.swift +14 -0
- package/ios/Sources/KeepAwakePlugin/KeepAwakePlugin.swift +29 -0
- package/ios/Tests/KeepAwakePluginTests/KeepAwakePluginTests.swift +15 -0
- package/package.json +80 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'GachlabCapacitorKeepAwakePlugin'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '13.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/Package.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "GachlabCapacitorKeepAwakePlugin",
|
|
6
|
+
platforms: [.iOS(.v13)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "GachlabCapacitorKeepAwakePlugin",
|
|
10
|
+
targets: ["KeepAwakePlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", branch: "main")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "KeepAwakePlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Sources/KeepAwakePlugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "KeepAwakePluginTests",
|
|
25
|
+
dependencies: ["KeepAwakePlugin"],
|
|
26
|
+
path: "ios/Tests/KeepAwakePluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @gachlab/capacitor-keep-awake-plugin
|
|
2
|
+
|
|
3
|
+
A plugin to keep awake the device screen
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @gachlab/capacitor-keep-awake-plugin
|
|
9
|
+
npx cap sync
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## API
|
|
13
|
+
|
|
14
|
+
<docgen-index>
|
|
15
|
+
|
|
16
|
+
* [`dontAllowSleep()`](#dontallowsleep)
|
|
17
|
+
* [`allowSleep()`](#allowsleep)
|
|
18
|
+
|
|
19
|
+
</docgen-index>
|
|
20
|
+
|
|
21
|
+
<docgen-api>
|
|
22
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
23
|
+
|
|
24
|
+
### dontAllowSleep()
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
dontAllowSleep() => Promise<{ isAllowdSleep: boolean; }>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Returns:** <code>Promise<{ isAllowdSleep: boolean; }></code>
|
|
31
|
+
|
|
32
|
+
--------------------
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
### allowSleep()
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
allowSleep() => Promise<{ isAllowdSleep: boolean; }>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Returns:** <code>Promise<{ isAllowdSleep: boolean; }></code>
|
|
42
|
+
|
|
43
|
+
--------------------
|
|
44
|
+
|
|
45
|
+
</docgen-api>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.2.1'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace "com.gachlab.capacitor.keepawake"
|
|
22
|
+
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
testImplementation "junit:junit:$junitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
package com.gachlab.capacitor.keepawake;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.util.Log;
|
|
5
|
+
import android.view.WindowManager;
|
|
6
|
+
|
|
7
|
+
import androidx.appcompat.app.AppCompatActivity;
|
|
8
|
+
|
|
9
|
+
public class KeepAwake {
|
|
10
|
+
|
|
11
|
+
public boolean dontAllowSleep(AppCompatActivity activity) {
|
|
12
|
+
Log.i("KeepAwake", "Disabling Sleep");
|
|
13
|
+
activity.runOnUiThread(new Runnable() {
|
|
14
|
+
@Override
|
|
15
|
+
public void run() {
|
|
16
|
+
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
Log.i("KeepAwake", "Sleep Disabled");
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public boolean allowSleep(AppCompatActivity activity) {
|
|
24
|
+
Log.i("KeepAwake", "Enabling Sleep");
|
|
25
|
+
activity.runOnUiThread(new Runnable() {
|
|
26
|
+
@Override
|
|
27
|
+
public void run() {
|
|
28
|
+
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Log.i("KeepAwake", "Sleep Enabled");
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
package com.gachlab.capacitor.keepawake;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.util.Log;
|
|
5
|
+
import android.view.WindowManager;
|
|
6
|
+
|
|
7
|
+
import androidx.appcompat.app.AppCompatActivity;
|
|
8
|
+
|
|
9
|
+
import com.getcapacitor.JSObject;
|
|
10
|
+
import com.getcapacitor.Plugin;
|
|
11
|
+
import com.getcapacitor.PluginCall;
|
|
12
|
+
import com.getcapacitor.PluginMethod;
|
|
13
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
14
|
+
|
|
15
|
+
@CapacitorPlugin(name = "KeepAwake")
|
|
16
|
+
public class KeepAwakePlugin extends Plugin {
|
|
17
|
+
|
|
18
|
+
private KeepAwake implementation = new KeepAwake();
|
|
19
|
+
|
|
20
|
+
@PluginMethod
|
|
21
|
+
public void dontAllowSleep(PluginCall call) {
|
|
22
|
+
String value = call.getString("value");
|
|
23
|
+
AppCompatActivity activity=getActivity();
|
|
24
|
+
JSObject ret = new JSObject();
|
|
25
|
+
ret.put("isAllowedSleep",implementation.dontAllowSleep(activity));
|
|
26
|
+
call.resolve(ret);
|
|
27
|
+
}
|
|
28
|
+
@PluginMethod
|
|
29
|
+
public void allowSleep(PluginCall call) {
|
|
30
|
+
String value = call.getString("value");
|
|
31
|
+
AppCompatActivity activity=getActivity();
|
|
32
|
+
JSObject ret = new JSObject();
|
|
33
|
+
ret.put("isAllowedSleep",implementation.allowSleep(activity));
|
|
34
|
+
call.resolve(ret);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
File without changes
|
package/dist/docs.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"api": {
|
|
3
|
+
"name": "KeepAwakePlugin",
|
|
4
|
+
"slug": "keepawakeplugin",
|
|
5
|
+
"docs": "",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"methods": [
|
|
8
|
+
{
|
|
9
|
+
"name": "dontAllowSleep",
|
|
10
|
+
"signature": "() => Promise<{ isAllowdSleep: boolean; }>",
|
|
11
|
+
"parameters": [],
|
|
12
|
+
"returns": "Promise<{ isAllowdSleep: boolean; }>",
|
|
13
|
+
"tags": [],
|
|
14
|
+
"docs": "",
|
|
15
|
+
"complexTypes": [],
|
|
16
|
+
"slug": "dontallowsleep"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "allowSleep",
|
|
20
|
+
"signature": "() => Promise<{ isAllowdSleep: boolean; }>",
|
|
21
|
+
"parameters": [],
|
|
22
|
+
"returns": "Promise<{ isAllowdSleep: boolean; }>",
|
|
23
|
+
"tags": [],
|
|
24
|
+
"docs": "",
|
|
25
|
+
"complexTypes": [],
|
|
26
|
+
"slug": "allowsleep"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"properties": []
|
|
30
|
+
},
|
|
31
|
+
"interfaces": [],
|
|
32
|
+
"enums": [],
|
|
33
|
+
"typeAliases": [],
|
|
34
|
+
"pluginConfigs": []
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface KeepAwakePlugin {\n dontAllowSleep(): Promise<{ isAllowdSleep: boolean }>;\n allowSleep(): Promise<{ isAllowdSleep: boolean }>;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,SAAS,GAAG,cAAc,CAAkB,WAAW,EAAE;IAC7D,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,CAAC;CAC3D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { KeepAwakePlugin } from './definitions';\n\nconst KeepAwake = registerPlugin<KeepAwakePlugin>('KeepAwake', {\n web: () => import('./web').then(m => new m.KeepAwakeWeb()),\n});\n\nexport * from './definitions';\nexport { KeepAwake };\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { KeepAwakePlugin } from './definitions';
|
|
3
|
+
export declare class KeepAwakeWeb extends WebPlugin implements KeepAwakePlugin {
|
|
4
|
+
dontAllowSleep(): Promise<{
|
|
5
|
+
isAllowdSleep: boolean;
|
|
6
|
+
}>;
|
|
7
|
+
allowSleep(): Promise<{
|
|
8
|
+
isAllowdSleep: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class KeepAwakeWeb extends WebPlugin {
|
|
3
|
+
dontAllowSleep() {
|
|
4
|
+
throw new Error('Method not implemented for Web.');
|
|
5
|
+
}
|
|
6
|
+
allowSleep() {
|
|
7
|
+
throw new Error('Method not implemented for Web.');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,YAAa,SAAQ,SAAS;IACzC,cAAc;QACZ,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IACD,UAAU;QACR,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;CAEF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { KeepAwakePlugin } from './definitions';\n\nexport class KeepAwakeWeb extends WebPlugin implements KeepAwakePlugin {\n dontAllowSleep(): Promise<{ isAllowdSleep: boolean; }> {\n throw new Error('Method not implemented for Web.');\n }\n allowSleep(): Promise<{ isAllowdSleep: boolean; }> {\n throw new Error('Method not implemented for Web.');\n }\n \n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('@capacitor/core');
|
|
6
|
+
|
|
7
|
+
const KeepAwake = core.registerPlugin('KeepAwake', {
|
|
8
|
+
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.KeepAwakeWeb()),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
class KeepAwakeWeb extends core.WebPlugin {
|
|
12
|
+
dontAllowSleep() {
|
|
13
|
+
throw new Error('Method not implemented for Web.');
|
|
14
|
+
}
|
|
15
|
+
allowSleep() {
|
|
16
|
+
throw new Error('Method not implemented for Web.');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
21
|
+
__proto__: null,
|
|
22
|
+
KeepAwakeWeb: KeepAwakeWeb
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
exports.KeepAwake = KeepAwake;
|
|
26
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst KeepAwake = registerPlugin('KeepAwake', {\n web: () => import('./web').then(m => new m.KeepAwakeWeb()),\n});\nexport * from './definitions';\nexport { KeepAwake };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class KeepAwakeWeb extends WebPlugin {\n dontAllowSleep() {\n throw new Error('Method not implemented for Web.');\n }\n allowSleep() {\n throw new Error('Method not implemented for Web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AACK,MAAC,SAAS,GAAGA,mBAAc,CAAC,WAAW,EAAE;AAC9C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,YAAY,EAAE,CAAC;AAC9D,CAAC;;ACFM,MAAM,YAAY,SAASC,cAAS,CAAC;AAC5C,IAAI,cAAc,GAAG;AACrB,QAAQ,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;AAC3D,KAAK;AACL,IAAI,UAAU,GAAG;AACjB,QAAQ,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;AAC3D,KAAK;AACL;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var capacitorKeepAwake = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const KeepAwake = core.registerPlugin('KeepAwake', {
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.KeepAwakeWeb()),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
class KeepAwakeWeb extends core.WebPlugin {
|
|
9
|
+
dontAllowSleep() {
|
|
10
|
+
throw new Error('Method not implemented for Web.');
|
|
11
|
+
}
|
|
12
|
+
allowSleep() {
|
|
13
|
+
throw new Error('Method not implemented for Web.');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
18
|
+
__proto__: null,
|
|
19
|
+
KeepAwakeWeb: KeepAwakeWeb
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
exports.KeepAwake = KeepAwake;
|
|
23
|
+
|
|
24
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
25
|
+
|
|
26
|
+
return exports;
|
|
27
|
+
|
|
28
|
+
})({}, capacitorExports);
|
|
29
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst KeepAwake = registerPlugin('KeepAwake', {\n web: () => import('./web').then(m => new m.KeepAwakeWeb()),\n});\nexport * from './definitions';\nexport { KeepAwake };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class KeepAwakeWeb extends WebPlugin {\n dontAllowSleep() {\n throw new Error('Method not implemented for Web.');\n }\n allowSleep() {\n throw new Error('Method not implemented for Web.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,SAAS,GAAGA,mBAAc,CAAC,WAAW,EAAE;IAC9C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,YAAY,EAAE,CAAC;IAC9D,CAAC;;ICFM,MAAM,YAAY,SAASC,cAAS,CAAC;IAC5C,IAAI,cAAc,GAAG;IACrB,QAAQ,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IAC3D,KAAK;IACL,IAAI,UAAU,GAAG;IACjB,QAAQ,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IAC3D,KAAK;IACL;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
@objc public class KeepAwake: NSObject {
|
|
4
|
+
@objc public func dontAllowSleep() -> String {
|
|
5
|
+
print("Sleep Disabled",terminator: "\n")
|
|
6
|
+
UIApplication.shared.isIdleTimerDisabled = true
|
|
7
|
+
return false
|
|
8
|
+
}
|
|
9
|
+
@objc public func allowSleep() -> String {
|
|
10
|
+
print("Sleep Enabled",terminator: "\n")
|
|
11
|
+
UIApplication.shared.isIdleTimerDisabled = false
|
|
12
|
+
return true
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Please read the Capacitor iOS Plugin Development Guide
|
|
6
|
+
* here: https://capacitorjs.com/docs/plugins/ios
|
|
7
|
+
*/
|
|
8
|
+
@objc(KeepAwakePlugin)
|
|
9
|
+
public class KeepAwakePlugin: CAPPlugin, CAPBridgedPlugin {
|
|
10
|
+
public let identifier = "KeepAwakePlugin"
|
|
11
|
+
public let jsName = "KeepAwake"
|
|
12
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
13
|
+
CAPPluginMethod(name: "dontAllowSleep", returnType: CAPPluginReturnPromise),
|
|
14
|
+
CAPPluginMethod(name: "allowSleep", returnType: CAPPluginReturnPromise)
|
|
15
|
+
|
|
16
|
+
]
|
|
17
|
+
private let implementation = KeepAwake()
|
|
18
|
+
|
|
19
|
+
@objc func dontAllowSleep(_ call: CAPPluginCall) {
|
|
20
|
+
call.resolve([
|
|
21
|
+
"isAllowedSleep": implementation.dontAllowSleep()
|
|
22
|
+
])
|
|
23
|
+
}
|
|
24
|
+
@objc func allowSleep(_ call: CAPPluginCall) {
|
|
25
|
+
call.resolve([
|
|
26
|
+
"isAllowedSleep": implementation.allowSleep()
|
|
27
|
+
])
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import KeepAwakePlugin
|
|
3
|
+
|
|
4
|
+
class KeepAwakeTests: XCTestCase {
|
|
5
|
+
func testEcho() {
|
|
6
|
+
// This is an example of a functional test case for a plugin.
|
|
7
|
+
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
8
|
+
|
|
9
|
+
let implementation = KeepAwake()
|
|
10
|
+
let value = "Hello, World!"
|
|
11
|
+
let result = implementation.echo(value)
|
|
12
|
+
|
|
13
|
+
XCTAssertEqual(value, result)
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gachlab/capacitor-keep-awake-plugin",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A plugin to keep awake the device screen",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"android/src/main/",
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"dist/",
|
|
13
|
+
"ios/Sources",
|
|
14
|
+
"ios/Tests",
|
|
15
|
+
"Package.swift",
|
|
16
|
+
"GachlabCapacitorKeepAwakePlugin.podspec"
|
|
17
|
+
],
|
|
18
|
+
"author": "",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/gachlab/capacitor-keep-awake-plugin.git"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/gachlab/capacitor-keep-awake-plugin/issues"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"capacitor",
|
|
29
|
+
"plugin",
|
|
30
|
+
"native"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
34
|
+
"verify:ios": "xcodebuild -scheme GachlabCapacitorKeepAwakePlugin -destination generic/platform=iOS",
|
|
35
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
36
|
+
"verify:web": "npm run build",
|
|
37
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
38
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
39
|
+
"eslint": "eslint . --ext ts",
|
|
40
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
41
|
+
"swiftlint": "node-swiftlint",
|
|
42
|
+
"docgen": "docgen --api KeepAwakePlugin --output-readme README.md --output-json dist/docs.json",
|
|
43
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
|
|
44
|
+
"clean": "rimraf ./dist",
|
|
45
|
+
"watch": "tsc --watch",
|
|
46
|
+
"prepublishOnly": "npm run build"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@capacitor/android": "^6.0.0",
|
|
50
|
+
"@capacitor/core": "^6.0.0",
|
|
51
|
+
"@capacitor/docgen": "^0.2.2",
|
|
52
|
+
"@capacitor/ios": "^6.0.0",
|
|
53
|
+
"@ionic/eslint-config": "^0.4.0",
|
|
54
|
+
"@ionic/prettier-config": "^1.0.1",
|
|
55
|
+
"@ionic/swiftlint-config": "^1.1.2",
|
|
56
|
+
"eslint": "^8.57.0",
|
|
57
|
+
"prettier": "~2.3.0",
|
|
58
|
+
"prettier-plugin-java": "~1.0.2",
|
|
59
|
+
"rimraf": "^3.0.2",
|
|
60
|
+
"rollup": "^2.32.0",
|
|
61
|
+
"swiftlint": "^1.0.1",
|
|
62
|
+
"typescript": "~4.1.5"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"@capacitor/core": "^6.0.0"
|
|
66
|
+
},
|
|
67
|
+
"prettier": "@ionic/prettier-config",
|
|
68
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
69
|
+
"eslintConfig": {
|
|
70
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
71
|
+
},
|
|
72
|
+
"capacitor": {
|
|
73
|
+
"ios": {
|
|
74
|
+
"src": "ios"
|
|
75
|
+
},
|
|
76
|
+
"android": {
|
|
77
|
+
"src": "android"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|