@capawesome/capacitor-keep-awake 0.0.1

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.
Files changed (33) hide show
  1. package/CapawesomeCapacitorKeepAwake.podspec +17 -0
  2. package/LICENSE +21 -0
  3. package/Package.swift +28 -0
  4. package/README.md +204 -0
  5. package/android/build.gradle +58 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/keepawake/KeepAwake.java +40 -0
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/keepawake/KeepAwakePlugin.java +86 -0
  9. package/android/src/main/java/io/capawesome/capacitorjs/plugins/keepawake/classes/results/IsAvailableResult.java +22 -0
  10. package/android/src/main/java/io/capawesome/capacitorjs/plugins/keepawake/classes/results/IsKeptAwakeResult.java +22 -0
  11. package/android/src/main/java/io/capawesome/capacitorjs/plugins/keepawake/interfaces/Result.java +7 -0
  12. package/android/src/main/res/.gitkeep +0 -0
  13. package/dist/docs.json +132 -0
  14. package/dist/esm/definitions.d.ts +65 -0
  15. package/dist/esm/definitions.js +2 -0
  16. package/dist/esm/definitions.js.map +1 -0
  17. package/dist/esm/index.d.ts +4 -0
  18. package/dist/esm/index.js +7 -0
  19. package/dist/esm/index.js.map +1 -0
  20. package/dist/esm/web.d.ts +16 -0
  21. package/dist/esm/web.js +53 -0
  22. package/dist/esm/web.js.map +1 -0
  23. package/dist/plugin.cjs.js +67 -0
  24. package/dist/plugin.cjs.js.map +1 -0
  25. package/dist/plugin.js +70 -0
  26. package/dist/plugin.js.map +1 -0
  27. package/ios/Plugin/Classes/Results/IsAvailableResult.swift +16 -0
  28. package/ios/Plugin/Classes/Results/IsKeptAwakeResult.swift +16 -0
  29. package/ios/Plugin/Info.plist +24 -0
  30. package/ios/Plugin/KeepAwake.swift +35 -0
  31. package/ios/Plugin/KeepAwakePlugin.swift +57 -0
  32. package/ios/Plugin/Protocols/Result.swift +5 -0
  33. package/package.json +91 -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 = 'CapawesomeCapacitorKeepAwake'
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/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '15.0'
15
+ s.dependency 'Capacitor'
16
+ s.swift_version = '5.1'
17
+ end
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Robin Genz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/Package.swift ADDED
@@ -0,0 +1,28 @@
1
+ // swift-tools-version: 5.9
2
+ import PackageDescription
3
+
4
+ let package = Package(
5
+ name: "CapawesomeCapacitorKeepAwake",
6
+ platforms: [.iOS(.v15)],
7
+ products: [
8
+ .library(
9
+ name: "CapawesomeCapacitorKeepAwake",
10
+ targets: ["KeepAwakePlugin"])
11
+ ],
12
+ dependencies: [
13
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
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/Plugin"),
23
+ .testTarget(
24
+ name: "KeepAwakePluginTests",
25
+ dependencies: ["KeepAwakePlugin"],
26
+ path: "ios/PluginTests")
27
+ ]
28
+ )
package/README.md ADDED
@@ -0,0 +1,204 @@
1
+ # @capawesome/capacitor-keep-awake
2
+
3
+ Capacitor plugin to keep the screen awake.
4
+
5
+ <div class="capawesome-z29o10a">
6
+ <a href="https://cloud.capawesome.io/" target="_blank">
7
+ <img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.png?t=1" />
8
+ </a>
9
+ </div>
10
+
11
+ ## Features
12
+
13
+ - 🌙 **Keep awake**: Prevent the screen from dimming or turning off.
14
+ - 💤 **Allow sleep**: Restore the default screen sleep behavior at any time.
15
+ - 🔍 **State**: Read whether the screen is currently kept awake.
16
+ - 🌐 **Cross-platform**: Supports Android, iOS and Web (via the Screen Wake Lock API).
17
+ - 📦 **CocoaPods & SPM**: Supports CocoaPods and Swift Package Manager for iOS.
18
+ - 🔁 **Up-to-date**: Always supports the latest Capacitor version.
19
+
20
+ Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
21
+
22
+ ## Newsletter
23
+
24
+ Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
25
+
26
+ ## Compatibility
27
+
28
+ | Plugin Version | Capacitor Version | Status |
29
+ | -------------- | ----------------- | -------------- |
30
+ | 0.x.x | >=8.x.x | Active support |
31
+
32
+ ## Installation
33
+
34
+ You can use our **AI-Assisted Setup** to install the plugin.
35
+ Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:
36
+
37
+ ```bash
38
+ npx skills add capawesome-team/skills --skill capacitor-plugins
39
+ ```
40
+
41
+ Then use the following prompt:
42
+
43
+ ```
44
+ Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-keep-awake` plugin in my project.
45
+ ```
46
+
47
+ If you prefer **Manual Setup**, install the plugin by running the following commands:
48
+
49
+ ```bash
50
+ npm install @capawesome/capacitor-keep-awake
51
+ npx cap sync
52
+ ```
53
+
54
+ This plugin is available on **Android**, **iOS** and **Web**. No additional permissions or configuration are required.
55
+
56
+ ## Configuration
57
+
58
+ No configuration required for this plugin.
59
+
60
+ ## Usage
61
+
62
+ ```typescript
63
+ import { KeepAwake } from '@capawesome/capacitor-keep-awake';
64
+
65
+ const keepAwake = async () => {
66
+ await KeepAwake.keepAwake();
67
+ };
68
+
69
+ const allowSleep = async () => {
70
+ await KeepAwake.allowSleep();
71
+ };
72
+
73
+ const isKeptAwake = async () => {
74
+ const { keptAwake } = await KeepAwake.isKeptAwake();
75
+ return keptAwake;
76
+ };
77
+
78
+ const isAvailable = async () => {
79
+ const { available } = await KeepAwake.isAvailable();
80
+ return available;
81
+ };
82
+ ```
83
+
84
+ ## API
85
+
86
+ <docgen-index>
87
+
88
+ * [`allowSleep()`](#allowsleep)
89
+ * [`isAvailable()`](#isavailable)
90
+ * [`isKeptAwake()`](#iskeptawake)
91
+ * [`keepAwake()`](#keepawake)
92
+ * [Interfaces](#interfaces)
93
+
94
+ </docgen-index>
95
+
96
+ <docgen-api>
97
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
98
+
99
+ ### allowSleep()
100
+
101
+ ```typescript
102
+ allowSleep() => Promise<void>
103
+ ```
104
+
105
+ Allow the screen to dim or turn off again.
106
+
107
+ This reverses the effect of `keepAwake(...)`.
108
+
109
+ Only available on Android, iOS and Web.
110
+
111
+ **Since:** 0.1.0
112
+
113
+ --------------------
114
+
115
+
116
+ ### isAvailable()
117
+
118
+ ```typescript
119
+ isAvailable() => Promise<IsAvailableResult>
120
+ ```
121
+
122
+ Check if keeping the screen awake is available on this device.
123
+
124
+ On Web, this depends on whether the browser supports the
125
+ [Screen Wake Lock API](https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API).
126
+ On Android and iOS, this always returns `true`.
127
+
128
+ Only available on Android, iOS and Web.
129
+
130
+ **Returns:** <code>Promise&lt;<a href="#isavailableresult">IsAvailableResult</a>&gt;</code>
131
+
132
+ **Since:** 0.1.0
133
+
134
+ --------------------
135
+
136
+
137
+ ### isKeptAwake()
138
+
139
+ ```typescript
140
+ isKeptAwake() => Promise<IsKeptAwakeResult>
141
+ ```
142
+
143
+ Check if the screen is currently kept awake.
144
+
145
+ Only available on Android, iOS and Web.
146
+
147
+ **Returns:** <code>Promise&lt;<a href="#iskeptawakeresult">IsKeptAwakeResult</a>&gt;</code>
148
+
149
+ **Since:** 0.1.0
150
+
151
+ --------------------
152
+
153
+
154
+ ### keepAwake()
155
+
156
+ ```typescript
157
+ keepAwake() => Promise<void>
158
+ ```
159
+
160
+ Keep the screen awake by preventing it from dimming or turning off.
161
+
162
+ The screen is kept awake until `allowSleep(...)` is called or the app is
163
+ restarted. This setting only affects your app and is not system-wide.
164
+
165
+ Only available on Android, iOS and Web.
166
+
167
+ **Since:** 0.1.0
168
+
169
+ --------------------
170
+
171
+
172
+ ### Interfaces
173
+
174
+
175
+ #### IsAvailableResult
176
+
177
+ | Prop | Type | Description | Since |
178
+ | --------------- | -------------------- | -------------------------------------------------------------------- | ----- |
179
+ | **`available`** | <code>boolean</code> | Whether keeping the screen awake is available on this device or not. | 0.1.0 |
180
+
181
+
182
+ #### IsKeptAwakeResult
183
+
184
+ | Prop | Type | Description | Since |
185
+ | --------------- | -------------------- | -------------------------------------------------- | ----- |
186
+ | **`keptAwake`** | <code>boolean</code> | Whether the screen is currently kept awake or not. | 0.1.0 |
187
+
188
+ </docgen-api>
189
+
190
+ ## Behavior
191
+
192
+ Keep the following in mind when using this plugin:
193
+
194
+ - **App scope**: Keeping the screen awake only affects your app and is not a system-wide setting.
195
+ - **State reset**: The screen is only kept awake until `allowSleep(...)` is called or the app is restarted.
196
+ - **Web auto-release**: On the Web, the underlying [Screen Wake Lock](https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API) is automatically released by the browser whenever the tab becomes hidden (for example, when the user switches tabs or minimizes the window). The plugin automatically re-acquires the wake lock once the tab becomes visible again, as long as `allowSleep(...)` has not been called in the meantime.
197
+
198
+ ## Changelog
199
+
200
+ See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/keep-awake/CHANGELOG.md).
201
+
202
+ ## License
203
+
204
+ See [LICENSE](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/keep-awake/LICENSE).
@@ -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.7.1'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
6
+ }
7
+
8
+ buildscript {
9
+ repositories {
10
+ google()
11
+ mavenCentral()
12
+ }
13
+ dependencies {
14
+ classpath 'com.android.tools.build:gradle:8.13.0'
15
+ }
16
+ }
17
+
18
+ apply plugin: 'com.android.library'
19
+
20
+ android {
21
+ namespace = "io.capawesome.capacitorjs.plugins.keepawake"
22
+ compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
23
+ defaultConfig {
24
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
25
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
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_21
41
+ targetCompatibility JavaVersion.VERSION_21
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,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,40 @@
1
+ package io.capawesome.capacitorjs.plugins.keepawake;
2
+
3
+ import android.view.WindowManager;
4
+ import androidx.annotation.NonNull;
5
+ import io.capawesome.capacitorjs.plugins.keepawake.classes.results.IsAvailableResult;
6
+ import io.capawesome.capacitorjs.plugins.keepawake.classes.results.IsKeptAwakeResult;
7
+
8
+ public class KeepAwake {
9
+
10
+ @NonNull
11
+ private final KeepAwakePlugin plugin;
12
+
13
+ private boolean keptAwake = false;
14
+
15
+ public KeepAwake(@NonNull KeepAwakePlugin plugin) {
16
+ this.plugin = plugin;
17
+ }
18
+
19
+ public void allowSleep() {
20
+ keptAwake = false;
21
+ plugin
22
+ .getActivity()
23
+ .runOnUiThread(() -> plugin.getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON));
24
+ }
25
+
26
+ @NonNull
27
+ public IsAvailableResult isAvailable() {
28
+ return new IsAvailableResult(true);
29
+ }
30
+
31
+ @NonNull
32
+ public IsKeptAwakeResult isKeptAwake() {
33
+ return new IsKeptAwakeResult(keptAwake);
34
+ }
35
+
36
+ public void keepAwake() {
37
+ keptAwake = true;
38
+ plugin.getActivity().runOnUiThread(() -> plugin.getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON));
39
+ }
40
+ }
@@ -0,0 +1,86 @@
1
+ package io.capawesome.capacitorjs.plugins.keepawake;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+ import com.getcapacitor.Logger;
6
+ import com.getcapacitor.Plugin;
7
+ import com.getcapacitor.PluginCall;
8
+ import com.getcapacitor.PluginMethod;
9
+ import com.getcapacitor.annotation.CapacitorPlugin;
10
+ import io.capawesome.capacitorjs.plugins.keepawake.classes.results.IsAvailableResult;
11
+ import io.capawesome.capacitorjs.plugins.keepawake.classes.results.IsKeptAwakeResult;
12
+ import io.capawesome.capacitorjs.plugins.keepawake.interfaces.Result;
13
+
14
+ @CapacitorPlugin(name = "KeepAwake")
15
+ public class KeepAwakePlugin extends Plugin {
16
+
17
+ public static final String TAG = "KeepAwake";
18
+
19
+ private static final String ERROR_UNKNOWN_ERROR = "An unknown error occurred.";
20
+
21
+ private KeepAwake implementation;
22
+
23
+ @Override
24
+ public void load() {
25
+ implementation = new KeepAwake(this);
26
+ }
27
+
28
+ @PluginMethod
29
+ public void allowSleep(PluginCall call) {
30
+ try {
31
+ implementation.allowSleep();
32
+ resolveCall(call);
33
+ } catch (Exception exception) {
34
+ rejectCall(call, exception);
35
+ }
36
+ }
37
+
38
+ @PluginMethod
39
+ public void isAvailable(PluginCall call) {
40
+ try {
41
+ IsAvailableResult result = implementation.isAvailable();
42
+ resolveCall(call, result);
43
+ } catch (Exception exception) {
44
+ rejectCall(call, exception);
45
+ }
46
+ }
47
+
48
+ @PluginMethod
49
+ public void isKeptAwake(PluginCall call) {
50
+ try {
51
+ IsKeptAwakeResult result = implementation.isKeptAwake();
52
+ resolveCall(call, result);
53
+ } catch (Exception exception) {
54
+ rejectCall(call, exception);
55
+ }
56
+ }
57
+
58
+ @PluginMethod
59
+ public void keepAwake(PluginCall call) {
60
+ try {
61
+ implementation.keepAwake();
62
+ resolveCall(call);
63
+ } catch (Exception exception) {
64
+ rejectCall(call, exception);
65
+ }
66
+ }
67
+
68
+ private void rejectCall(@NonNull PluginCall call, @NonNull Exception exception) {
69
+ String message = exception.getMessage();
70
+ message = (message != null) ? message : ERROR_UNKNOWN_ERROR;
71
+ Logger.error(TAG, message, exception);
72
+ call.reject(message);
73
+ }
74
+
75
+ private void resolveCall(@NonNull PluginCall call) {
76
+ call.resolve();
77
+ }
78
+
79
+ private void resolveCall(@NonNull PluginCall call, @Nullable Result result) {
80
+ if (result == null) {
81
+ call.resolve();
82
+ } else {
83
+ call.resolve(result.toJSObject());
84
+ }
85
+ }
86
+ }
@@ -0,0 +1,22 @@
1
+ package io.capawesome.capacitorjs.plugins.keepawake.classes.results;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.JSObject;
5
+ import io.capawesome.capacitorjs.plugins.keepawake.interfaces.Result;
6
+
7
+ public class IsAvailableResult implements Result {
8
+
9
+ private final boolean available;
10
+
11
+ public IsAvailableResult(boolean available) {
12
+ this.available = available;
13
+ }
14
+
15
+ @Override
16
+ @NonNull
17
+ public JSObject toJSObject() {
18
+ JSObject result = new JSObject();
19
+ result.put("available", available);
20
+ return result;
21
+ }
22
+ }
@@ -0,0 +1,22 @@
1
+ package io.capawesome.capacitorjs.plugins.keepawake.classes.results;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.JSObject;
5
+ import io.capawesome.capacitorjs.plugins.keepawake.interfaces.Result;
6
+
7
+ public class IsKeptAwakeResult implements Result {
8
+
9
+ private final boolean keptAwake;
10
+
11
+ public IsKeptAwakeResult(boolean keptAwake) {
12
+ this.keptAwake = keptAwake;
13
+ }
14
+
15
+ @Override
16
+ @NonNull
17
+ public JSObject toJSObject() {
18
+ JSObject result = new JSObject();
19
+ result.put("keptAwake", keptAwake);
20
+ return result;
21
+ }
22
+ }
@@ -0,0 +1,7 @@
1
+ package io.capawesome.capacitorjs.plugins.keepawake.interfaces;
2
+
3
+ import com.getcapacitor.JSObject;
4
+
5
+ public interface Result {
6
+ JSObject toJSObject();
7
+ }
File without changes
package/dist/docs.json ADDED
@@ -0,0 +1,132 @@
1
+ {
2
+ "api": {
3
+ "name": "KeepAwakePlugin",
4
+ "slug": "keepawakeplugin",
5
+ "docs": "",
6
+ "tags": [],
7
+ "methods": [
8
+ {
9
+ "name": "allowSleep",
10
+ "signature": "() => Promise<void>",
11
+ "parameters": [],
12
+ "returns": "Promise<void>",
13
+ "tags": [
14
+ {
15
+ "name": "since",
16
+ "text": "0.1.0"
17
+ }
18
+ ],
19
+ "docs": "Allow the screen to dim or turn off again.\n\nThis reverses the effect of `keepAwake(...)`.\n\nOnly available on Android, iOS and Web.",
20
+ "complexTypes": [],
21
+ "slug": "allowsleep"
22
+ },
23
+ {
24
+ "name": "isAvailable",
25
+ "signature": "() => Promise<IsAvailableResult>",
26
+ "parameters": [],
27
+ "returns": "Promise<IsAvailableResult>",
28
+ "tags": [
29
+ {
30
+ "name": "since",
31
+ "text": "0.1.0"
32
+ }
33
+ ],
34
+ "docs": "Check if keeping the screen awake is available on this device.\n\nOn Web, this depends on whether the browser supports the\n[Screen Wake Lock API](https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API).\nOn Android and iOS, this always returns `true`.\n\nOnly available on Android, iOS and Web.",
35
+ "complexTypes": [
36
+ "IsAvailableResult"
37
+ ],
38
+ "slug": "isavailable"
39
+ },
40
+ {
41
+ "name": "isKeptAwake",
42
+ "signature": "() => Promise<IsKeptAwakeResult>",
43
+ "parameters": [],
44
+ "returns": "Promise<IsKeptAwakeResult>",
45
+ "tags": [
46
+ {
47
+ "name": "since",
48
+ "text": "0.1.0"
49
+ }
50
+ ],
51
+ "docs": "Check if the screen is currently kept awake.\n\nOnly available on Android, iOS and Web.",
52
+ "complexTypes": [
53
+ "IsKeptAwakeResult"
54
+ ],
55
+ "slug": "iskeptawake"
56
+ },
57
+ {
58
+ "name": "keepAwake",
59
+ "signature": "() => Promise<void>",
60
+ "parameters": [],
61
+ "returns": "Promise<void>",
62
+ "tags": [
63
+ {
64
+ "name": "since",
65
+ "text": "0.1.0"
66
+ }
67
+ ],
68
+ "docs": "Keep the screen awake by preventing it from dimming or turning off.\n\nThe screen is kept awake until `allowSleep(...)` is called or the app is\nrestarted. This setting only affects your app and is not system-wide.\n\nOnly available on Android, iOS and Web.",
69
+ "complexTypes": [],
70
+ "slug": "keepawake"
71
+ }
72
+ ],
73
+ "properties": []
74
+ },
75
+ "interfaces": [
76
+ {
77
+ "name": "IsAvailableResult",
78
+ "slug": "isavailableresult",
79
+ "docs": "",
80
+ "tags": [
81
+ {
82
+ "text": "0.1.0",
83
+ "name": "since"
84
+ }
85
+ ],
86
+ "methods": [],
87
+ "properties": [
88
+ {
89
+ "name": "available",
90
+ "tags": [
91
+ {
92
+ "text": "0.1.0",
93
+ "name": "since"
94
+ }
95
+ ],
96
+ "docs": "Whether keeping the screen awake is available on this device or not.",
97
+ "complexTypes": [],
98
+ "type": "boolean"
99
+ }
100
+ ]
101
+ },
102
+ {
103
+ "name": "IsKeptAwakeResult",
104
+ "slug": "iskeptawakeresult",
105
+ "docs": "",
106
+ "tags": [
107
+ {
108
+ "text": "0.1.0",
109
+ "name": "since"
110
+ }
111
+ ],
112
+ "methods": [],
113
+ "properties": [
114
+ {
115
+ "name": "keptAwake",
116
+ "tags": [
117
+ {
118
+ "text": "0.1.0",
119
+ "name": "since"
120
+ }
121
+ ],
122
+ "docs": "Whether the screen is currently kept awake or not.",
123
+ "complexTypes": [],
124
+ "type": "boolean"
125
+ }
126
+ ]
127
+ }
128
+ ],
129
+ "enums": [],
130
+ "typeAliases": [],
131
+ "pluginConfigs": []
132
+ }
@@ -0,0 +1,65 @@
1
+ export interface KeepAwakePlugin {
2
+ /**
3
+ * Allow the screen to dim or turn off again.
4
+ *
5
+ * This reverses the effect of `keepAwake(...)`.
6
+ *
7
+ * Only available on Android, iOS and Web.
8
+ *
9
+ * @since 0.1.0
10
+ */
11
+ allowSleep(): Promise<void>;
12
+ /**
13
+ * Check if keeping the screen awake is available on this device.
14
+ *
15
+ * On Web, this depends on whether the browser supports the
16
+ * [Screen Wake Lock API](https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API).
17
+ * On Android and iOS, this always returns `true`.
18
+ *
19
+ * Only available on Android, iOS and Web.
20
+ *
21
+ * @since 0.1.0
22
+ */
23
+ isAvailable(): Promise<IsAvailableResult>;
24
+ /**
25
+ * Check if the screen is currently kept awake.
26
+ *
27
+ * Only available on Android, iOS and Web.
28
+ *
29
+ * @since 0.1.0
30
+ */
31
+ isKeptAwake(): Promise<IsKeptAwakeResult>;
32
+ /**
33
+ * Keep the screen awake by preventing it from dimming or turning off.
34
+ *
35
+ * The screen is kept awake until `allowSleep(...)` is called or the app is
36
+ * restarted. This setting only affects your app and is not system-wide.
37
+ *
38
+ * Only available on Android, iOS and Web.
39
+ *
40
+ * @since 0.1.0
41
+ */
42
+ keepAwake(): Promise<void>;
43
+ }
44
+ /**
45
+ * @since 0.1.0
46
+ */
47
+ export interface IsKeptAwakeResult {
48
+ /**
49
+ * Whether the screen is currently kept awake or not.
50
+ *
51
+ * @since 0.1.0
52
+ */
53
+ keptAwake: boolean;
54
+ }
55
+ /**
56
+ * @since 0.1.0
57
+ */
58
+ export interface IsAvailableResult {
59
+ /**
60
+ * Whether keeping the screen awake is available on this device or not.
61
+ *
62
+ * @since 0.1.0
63
+ */
64
+ available: boolean;
65
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface KeepAwakePlugin {\n /**\n * Allow the screen to dim or turn off again.\n *\n * This reverses the effect of `keepAwake(...)`.\n *\n * Only available on Android, iOS and Web.\n *\n * @since 0.1.0\n */\n allowSleep(): Promise<void>;\n /**\n * Check if keeping the screen awake is available on this device.\n *\n * On Web, this depends on whether the browser supports the\n * [Screen Wake Lock API](https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API).\n * On Android and iOS, this always returns `true`.\n *\n * Only available on Android, iOS and Web.\n *\n * @since 0.1.0\n */\n isAvailable(): Promise<IsAvailableResult>;\n /**\n * Check if the screen is currently kept awake.\n *\n * Only available on Android, iOS and Web.\n *\n * @since 0.1.0\n */\n isKeptAwake(): Promise<IsKeptAwakeResult>;\n /**\n * Keep the screen awake by preventing it from dimming or turning off.\n *\n * The screen is kept awake until `allowSleep(...)` is called or the app is\n * restarted. This setting only affects your app and is not system-wide.\n *\n * Only available on Android, iOS and Web.\n *\n * @since 0.1.0\n */\n keepAwake(): Promise<void>;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface IsKeptAwakeResult {\n /**\n * Whether the screen is currently kept awake or not.\n *\n * @since 0.1.0\n */\n keptAwake: boolean;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface IsAvailableResult {\n /**\n * Whether keeping the screen awake is available on this device or not.\n *\n * @since 0.1.0\n */\n available: boolean;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { KeepAwakePlugin } from './definitions';
2
+ declare const KeepAwake: KeepAwakePlugin;
3
+ export * from './definitions';
4
+ export { KeepAwake };
@@ -0,0 +1,7 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const KeepAwake = registerPlugin('KeepAwake', {
3
+ web: () => import('./web').then(m => new m.KeepAwakeWeb()),
4
+ });
5
+ export * from './definitions';
6
+ export { KeepAwake };
7
+ //# sourceMappingURL=index.js.map
@@ -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,16 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { IsAvailableResult, IsKeptAwakeResult, KeepAwakePlugin } from './definitions';
3
+ export declare class KeepAwakeWeb extends WebPlugin implements KeepAwakePlugin {
4
+ private keepAwakeRequested;
5
+ private wakeLockSentinel;
6
+ constructor();
7
+ allowSleep(): Promise<void>;
8
+ isAvailable(): Promise<IsAvailableResult>;
9
+ isKeptAwake(): Promise<IsKeptAwakeResult>;
10
+ keepAwake(): Promise<void>;
11
+ private createUnavailableException;
12
+ private handleVisibilityChange;
13
+ private isSupported;
14
+ private releaseWakeLock;
15
+ private requestWakeLock;
16
+ }
@@ -0,0 +1,53 @@
1
+ import { CapacitorException, ExceptionCode, WebPlugin } from '@capacitor/core';
2
+ export class KeepAwakeWeb extends WebPlugin {
3
+ constructor() {
4
+ super();
5
+ this.keepAwakeRequested = false;
6
+ this.wakeLockSentinel = null;
7
+ document.addEventListener('visibilitychange', this.handleVisibilityChange.bind(this));
8
+ }
9
+ async allowSleep() {
10
+ if (!this.isSupported()) {
11
+ throw this.createUnavailableException();
12
+ }
13
+ this.keepAwakeRequested = false;
14
+ await this.releaseWakeLock();
15
+ }
16
+ async isAvailable() {
17
+ return { available: this.isSupported() };
18
+ }
19
+ async isKeptAwake() {
20
+ return { keptAwake: this.keepAwakeRequested };
21
+ }
22
+ async keepAwake() {
23
+ if (!this.isSupported()) {
24
+ throw this.createUnavailableException();
25
+ }
26
+ this.keepAwakeRequested = true;
27
+ await this.requestWakeLock();
28
+ }
29
+ createUnavailableException() {
30
+ return new CapacitorException('This plugin method is not available on this platform.', ExceptionCode.Unavailable);
31
+ }
32
+ async handleVisibilityChange() {
33
+ if (this.keepAwakeRequested && document.visibilityState === 'visible') {
34
+ await this.requestWakeLock();
35
+ }
36
+ }
37
+ isSupported() {
38
+ return 'wakeLock' in navigator;
39
+ }
40
+ async releaseWakeLock() {
41
+ if (this.wakeLockSentinel) {
42
+ await this.wakeLockSentinel.release();
43
+ this.wakeLockSentinel = null;
44
+ }
45
+ }
46
+ async requestWakeLock() {
47
+ if (this.wakeLockSentinel && !this.wakeLockSentinel.released) {
48
+ return;
49
+ }
50
+ this.wakeLockSentinel = await navigator.wakeLock.request('screen');
51
+ }
52
+ }
53
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQ/E,MAAM,OAAO,YAAa,SAAQ,SAAS;IAIzC;QACE,KAAK,EAAE,CAAC;QAJF,uBAAkB,GAAG,KAAK,CAAC;QAC3B,qBAAgB,GAA4B,IAAI,CAAC;QAIvD,QAAQ,CAAC,gBAAgB,CACv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I,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC/B,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,eAAe;QAC3B,IAAI,IAAI,CAAC,gBAAgB,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC;YAC7D,OAAO;QACT,CAAC;QACD,IAAI,CAAC,gBAAgB,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACrE,CAAC;CACF","sourcesContent":["import { CapacitorException, ExceptionCode, WebPlugin } from '@capacitor/core';\n\nimport type {\n IsAvailableResult,\n IsKeptAwakeResult,\n KeepAwakePlugin,\n} from './definitions';\n\nexport class KeepAwakeWeb extends WebPlugin implements KeepAwakePlugin {\n private keepAwakeRequested = false;\n private wakeLockSentinel: WakeLockSentinel | null = null;\n\n constructor() {\n super();\n document.addEventListener(\n 'visibilitychange',\n this.handleVisibilityChange.bind(this),\n );\n }\n\n async allowSleep(): Promise<void> {\n if (!this.isSupported()) {\n throw this.createUnavailableException();\n }\n this.keepAwakeRequested = false;\n await this.releaseWakeLock();\n }\n\n async isAvailable(): Promise<IsAvailableResult> {\n return { available: this.isSupported() };\n }\n\n async isKeptAwake(): Promise<IsKeptAwakeResult> {\n return { keptAwake: this.keepAwakeRequested };\n }\n\n async keepAwake(): Promise<void> {\n if (!this.isSupported()) {\n throw this.createUnavailableException();\n }\n this.keepAwakeRequested = true;\n await this.requestWakeLock();\n }\n\n private createUnavailableException(): CapacitorException {\n return new CapacitorException(\n 'This plugin method is not available on this platform.',\n ExceptionCode.Unavailable,\n );\n }\n\n private async handleVisibilityChange(): Promise<void> {\n if (this.keepAwakeRequested && document.visibilityState === 'visible') {\n await this.requestWakeLock();\n }\n }\n\n private isSupported(): boolean {\n return 'wakeLock' in navigator;\n }\n\n private async releaseWakeLock(): Promise<void> {\n if (this.wakeLockSentinel) {\n await this.wakeLockSentinel.release();\n this.wakeLockSentinel = null;\n }\n }\n\n private async requestWakeLock(): Promise<void> {\n if (this.wakeLockSentinel && !this.wakeLockSentinel.released) {\n return;\n }\n this.wakeLockSentinel = await navigator.wakeLock.request('screen');\n }\n}\n"]}
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ const KeepAwake = core.registerPlugin('KeepAwake', {
6
+ web: () => Promise.resolve().then(function () { return web; }).then(m => new m.KeepAwakeWeb()),
7
+ });
8
+
9
+ class KeepAwakeWeb extends core.WebPlugin {
10
+ constructor() {
11
+ super();
12
+ this.keepAwakeRequested = false;
13
+ this.wakeLockSentinel = null;
14
+ document.addEventListener('visibilitychange', this.handleVisibilityChange.bind(this));
15
+ }
16
+ async allowSleep() {
17
+ if (!this.isSupported()) {
18
+ throw this.createUnavailableException();
19
+ }
20
+ this.keepAwakeRequested = false;
21
+ await this.releaseWakeLock();
22
+ }
23
+ async isAvailable() {
24
+ return { available: this.isSupported() };
25
+ }
26
+ async isKeptAwake() {
27
+ return { keptAwake: this.keepAwakeRequested };
28
+ }
29
+ async keepAwake() {
30
+ if (!this.isSupported()) {
31
+ throw this.createUnavailableException();
32
+ }
33
+ this.keepAwakeRequested = true;
34
+ await this.requestWakeLock();
35
+ }
36
+ createUnavailableException() {
37
+ return new core.CapacitorException('This plugin method is not available on this platform.', core.ExceptionCode.Unavailable);
38
+ }
39
+ async handleVisibilityChange() {
40
+ if (this.keepAwakeRequested && document.visibilityState === 'visible') {
41
+ await this.requestWakeLock();
42
+ }
43
+ }
44
+ isSupported() {
45
+ return 'wakeLock' in navigator;
46
+ }
47
+ async releaseWakeLock() {
48
+ if (this.wakeLockSentinel) {
49
+ await this.wakeLockSentinel.release();
50
+ this.wakeLockSentinel = null;
51
+ }
52
+ }
53
+ async requestWakeLock() {
54
+ if (this.wakeLockSentinel && !this.wakeLockSentinel.released) {
55
+ return;
56
+ }
57
+ this.wakeLockSentinel = await navigator.wakeLock.request('screen');
58
+ }
59
+ }
60
+
61
+ var web = /*#__PURE__*/Object.freeze({
62
+ __proto__: null,
63
+ KeepAwakeWeb: KeepAwakeWeb
64
+ });
65
+
66
+ exports.KeepAwake = KeepAwake;
67
+ //# 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 { CapacitorException, ExceptionCode, WebPlugin } from '@capacitor/core';\nexport class KeepAwakeWeb extends WebPlugin {\n constructor() {\n super();\n this.keepAwakeRequested = false;\n this.wakeLockSentinel = null;\n document.addEventListener('visibilitychange', this.handleVisibilityChange.bind(this));\n }\n async allowSleep() {\n if (!this.isSupported()) {\n throw this.createUnavailableException();\n }\n this.keepAwakeRequested = false;\n await this.releaseWakeLock();\n }\n async isAvailable() {\n return { available: this.isSupported() };\n }\n async isKeptAwake() {\n return { keptAwake: this.keepAwakeRequested };\n }\n async keepAwake() {\n if (!this.isSupported()) {\n throw this.createUnavailableException();\n }\n this.keepAwakeRequested = true;\n await this.requestWakeLock();\n }\n createUnavailableException() {\n return new CapacitorException('This plugin method is not available on this platform.', ExceptionCode.Unavailable);\n }\n async handleVisibilityChange() {\n if (this.keepAwakeRequested && document.visibilityState === 'visible') {\n await this.requestWakeLock();\n }\n }\n isSupported() {\n return 'wakeLock' in navigator;\n }\n async releaseWakeLock() {\n if (this.wakeLockSentinel) {\n await this.wakeLockSentinel.release();\n this.wakeLockSentinel = null;\n }\n }\n async requestWakeLock() {\n if (this.wakeLockSentinel && !this.wakeLockSentinel.released) {\n return;\n }\n this.wakeLockSentinel = await navigator.wakeLock.request('screen');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","CapacitorException","ExceptionCode"],"mappings":";;;;AACK,MAAC,SAAS,GAAGA,m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AAa,CAAC,WAAW,CAAC;AACzH,IAAI;AACJ,IAAI,MAAM,sBAAsB,GAAG;AACnC,QAAQ,IAAI,IAAI,CAAC,kBAAkB,IAAI,QAAQ,CAAC,eAAe,KAAK,SAAS,EAAE;AAC/E,YAAY,MAAM,IAAI,CAAC,eAAe,EAAE;AACxC,QAAQ;AACR,IAAI;AACJ,IAAI,WAAW,GAAG;AAClB,QAAQ,OAAO,UAAU,IAAI,SAAS;AACtC,IAAI;AACJ,IAAI,MAAM,eAAe,GAAG;AAC5B,QAAQ,IAAI,IAAI,CAAC,gBAAgB,EAAE;AACnC,YAAY,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE;AACjD,YAAY,IAAI,CAAC,gBAAgB,GAAG,IAAI;AACxC,QAAQ;AACR,IAAI;AACJ,IAAI,MAAM,eAAe,GAAG;AAC5B,QAAQ,IAAI,IAAI,CAAC,gBAAgB,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE;AACtE,YAAY;AACZ,QAAQ;AACR,QAAQ,IAAI,CAAC,gBAAgB,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC;AAC1E,IAAI;AACJ;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,70 @@
1
+ var capacitorAppTrackingTransparency = (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
+ constructor() {
10
+ super();
11
+ this.keepAwakeRequested = false;
12
+ this.wakeLockSentinel = null;
13
+ document.addEventListener('visibilitychange', this.handleVisibilityChange.bind(this));
14
+ }
15
+ async allowSleep() {
16
+ if (!this.isSupported()) {
17
+ throw this.createUnavailableException();
18
+ }
19
+ this.keepAwakeRequested = false;
20
+ await this.releaseWakeLock();
21
+ }
22
+ async isAvailable() {
23
+ return { available: this.isSupported() };
24
+ }
25
+ async isKeptAwake() {
26
+ return { keptAwake: this.keepAwakeRequested };
27
+ }
28
+ async keepAwake() {
29
+ if (!this.isSupported()) {
30
+ throw this.createUnavailableException();
31
+ }
32
+ this.keepAwakeRequested = true;
33
+ await this.requestWakeLock();
34
+ }
35
+ createUnavailableException() {
36
+ return new core.CapacitorException('This plugin method is not available on this platform.', core.ExceptionCode.Unavailable);
37
+ }
38
+ async handleVisibilityChange() {
39
+ if (this.keepAwakeRequested && document.visibilityState === 'visible') {
40
+ await this.requestWakeLock();
41
+ }
42
+ }
43
+ isSupported() {
44
+ return 'wakeLock' in navigator;
45
+ }
46
+ async releaseWakeLock() {
47
+ if (this.wakeLockSentinel) {
48
+ await this.wakeLockSentinel.release();
49
+ this.wakeLockSentinel = null;
50
+ }
51
+ }
52
+ async requestWakeLock() {
53
+ if (this.wakeLockSentinel && !this.wakeLockSentinel.released) {
54
+ return;
55
+ }
56
+ this.wakeLockSentinel = await navigator.wakeLock.request('screen');
57
+ }
58
+ }
59
+
60
+ var web = /*#__PURE__*/Object.freeze({
61
+ __proto__: null,
62
+ KeepAwakeWeb: KeepAwakeWeb
63
+ });
64
+
65
+ exports.KeepAwake = KeepAwake;
66
+
67
+ return exports;
68
+
69
+ })({}, capacitorExports);
70
+ //# 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 { CapacitorException, ExceptionCode, WebPlugin } from '@capacitor/core';\nexport class KeepAwakeWeb extends WebPlugin {\n constructor() {\n super();\n this.keepAwakeRequested = false;\n this.wakeLockSentinel = null;\n document.addEventListener('visibilitychange', this.handleVisibilityChange.bind(this));\n }\n async allowSleep() {\n if (!this.isSupported()) {\n throw this.createUnavailableException();\n }\n this.keepAwakeRequested = false;\n await this.releaseWakeLock();\n }\n async isAvailable() {\n return { available: this.isSupported() };\n }\n async isKeptAwake() {\n return { keptAwake: this.keepAwakeRequested };\n }\n async keepAwake() {\n if (!this.isSupported()) {\n throw this.createUnavailableException();\n }\n this.keepAwakeRequested = true;\n await this.requestWakeLock();\n }\n createUnavailableException() {\n return new CapacitorException('This plugin method is not available on this platform.', ExceptionCode.Unavailable);\n }\n async handleVisibilityChange() {\n if (this.keepAwakeRequested && document.visibilityState === 'visible') {\n await this.requestWakeLock();\n }\n }\n isSupported() {\n return 'wakeLock' in navigator;\n }\n async releaseWakeLock() {\n if (this.wakeLockSentinel) {\n await this.wakeLockSentinel.release();\n this.wakeLockSentinel = null;\n }\n }\n async requestWakeLock() {\n if (this.wakeLockSentinel && !this.wakeLockSentinel.released) {\n return;\n }\n this.wakeLockSentinel = await navigator.wakeLock.request('screen');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","CapacitorException","ExceptionCode"],"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,WAAW,GAAG;IAClB,QAAQ,KAAK,EAAE;IACf,QAAQ,IAAI,CAAC,kBAAkB,GAAG,KAAK;IACvC,QAAQ,IAAI,CAAC,gBAAgB,GAAG,IAAI;IACpC,QAAQ,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7F,IAAI;IACJ,IAAI,MAAM,UAAU,GAAG;IACvB,QAAQ,IAAI,CAAC,IAAI,CAAC,WAAW,E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AG;IAC5B,QAAQ,IAAI,IAAI,CAAC,gBAAgB,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE;IACtE,YAAY;IACZ,QAAQ;IACR,QAAQ,IAAI,CAAC,gBAAgB,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC1E,IAAI;IACJ;;;;;;;;;;;;;;;"}
@@ -0,0 +1,16 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ @objc public class IsAvailableResult: NSObject, Result {
5
+ let available: Bool
6
+
7
+ init(available: Bool) {
8
+ self.available = available
9
+ }
10
+
11
+ @objc public func toJSObject() -> AnyObject {
12
+ var result = JSObject()
13
+ result["available"] = available
14
+ return result as AnyObject
15
+ }
16
+ }
@@ -0,0 +1,16 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ @objc public class IsKeptAwakeResult: NSObject, Result {
5
+ let keptAwake: Bool
6
+
7
+ init(keptAwake: Bool) {
8
+ self.keptAwake = keptAwake
9
+ }
10
+
11
+ @objc public func toJSObject() -> AnyObject {
12
+ var result = JSObject()
13
+ result["keptAwake"] = keptAwake
14
+ return result as AnyObject
15
+ }
16
+ }
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>$(DEVELOPMENT_LANGUAGE)</string>
7
+ <key>CFBundleExecutable</key>
8
+ <string>$(EXECUTABLE_NAME)</string>
9
+ <key>CFBundleIdentifier</key>
10
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11
+ <key>CFBundleInfoDictionaryVersion</key>
12
+ <string>6.0</string>
13
+ <key>CFBundleName</key>
14
+ <string>$(PRODUCT_NAME)</string>
15
+ <key>CFBundlePackageType</key>
16
+ <string>FMWK</string>
17
+ <key>CFBundleShortVersionString</key>
18
+ <string>1.0</string>
19
+ <key>CFBundleVersion</key>
20
+ <string>$(CURRENT_PROJECT_VERSION)</string>
21
+ <key>NSPrincipalClass</key>
22
+ <string></string>
23
+ </dict>
24
+ </plist>
@@ -0,0 +1,35 @@
1
+ import Foundation
2
+ import UIKit
3
+
4
+ @objc public class KeepAwake: NSObject {
5
+ private let plugin: KeepAwakePlugin
6
+
7
+ init(plugin: KeepAwakePlugin) {
8
+ self.plugin = plugin
9
+ }
10
+
11
+ @objc public func allowSleep(completion: @escaping () -> Void) {
12
+ DispatchQueue.main.async {
13
+ UIApplication.shared.isIdleTimerDisabled = false
14
+ completion()
15
+ }
16
+ }
17
+
18
+ @objc public func isAvailable() -> IsAvailableResult {
19
+ return IsAvailableResult(available: true)
20
+ }
21
+
22
+ @objc public func isKeptAwake(completion: @escaping (IsKeptAwakeResult) -> Void) {
23
+ DispatchQueue.main.async {
24
+ let keptAwake = UIApplication.shared.isIdleTimerDisabled
25
+ completion(IsKeptAwakeResult(keptAwake: keptAwake))
26
+ }
27
+ }
28
+
29
+ @objc public func keepAwake(completion: @escaping () -> Void) {
30
+ DispatchQueue.main.async {
31
+ UIApplication.shared.isIdleTimerDisabled = true
32
+ completion()
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,57 @@
1
+ import Foundation
2
+ import Capacitor
3
+
4
+ @objc(KeepAwakePlugin)
5
+ public class KeepAwakePlugin: CAPPlugin, CAPBridgedPlugin {
6
+ public let identifier = "KeepAwakePlugin"
7
+ public let jsName = "KeepAwake"
8
+ public let pluginMethods: [CAPPluginMethod] = [
9
+ CAPPluginMethod(name: "allowSleep", returnType: CAPPluginReturnPromise),
10
+ CAPPluginMethod(name: "isAvailable", returnType: CAPPluginReturnPromise),
11
+ CAPPluginMethod(name: "isKeptAwake", returnType: CAPPluginReturnPromise),
12
+ CAPPluginMethod(name: "keepAwake", returnType: CAPPluginReturnPromise)
13
+ ]
14
+
15
+ public static let tag = "KeepAwakePlugin"
16
+
17
+ private var implementation: KeepAwake?
18
+
19
+ override public func load() {
20
+ self.implementation = KeepAwake(plugin: self)
21
+ }
22
+
23
+ @objc func allowSleep(_ call: CAPPluginCall) {
24
+ implementation?.allowSleep {
25
+ self.resolveCall(call)
26
+ }
27
+ }
28
+
29
+ @objc func isAvailable(_ call: CAPPluginCall) {
30
+ let result = implementation?.isAvailable()
31
+ resolveCall(call, result)
32
+ }
33
+
34
+ @objc func isKeptAwake(_ call: CAPPluginCall) {
35
+ implementation?.isKeptAwake { result in
36
+ self.resolveCall(call, result)
37
+ }
38
+ }
39
+
40
+ @objc func keepAwake(_ call: CAPPluginCall) {
41
+ implementation?.keepAwake {
42
+ self.resolveCall(call)
43
+ }
44
+ }
45
+
46
+ private func resolveCall(_ call: CAPPluginCall) {
47
+ call.resolve()
48
+ }
49
+
50
+ private func resolveCall(_ call: CAPPluginCall, _ result: Result?) {
51
+ if let result = result?.toJSObject() as? JSObject {
52
+ call.resolve(result)
53
+ } else {
54
+ call.resolve()
55
+ }
56
+ }
57
+ }
@@ -0,0 +1,5 @@
1
+ import Capacitor
2
+
3
+ @objc public protocol Result {
4
+ @objc func toJSObject() -> AnyObject
5
+ }
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "@capawesome/capacitor-keep-awake",
3
+ "version": "0.0.1",
4
+ "description": "Capacitor plugin to keep the screen awake.",
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/Plugin/",
14
+ "CapawesomeCapacitorKeepAwake.podspec",
15
+ "Package.swift"
16
+ ],
17
+ "author": "Robin Genz <mail@robingenz.dev>",
18
+ "license": "MIT",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/capawesome-team/capacitor-plugins.git"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/capawesome-team/capacitor-plugins/issues"
25
+ },
26
+ "funding": [
27
+ {
28
+ "type": "github",
29
+ "url": "https://github.com/sponsors/capawesome-team/"
30
+ },
31
+ {
32
+ "type": "opencollective",
33
+ "url": "https://opencollective.com/capawesome"
34
+ }
35
+ ],
36
+ "homepage": "https://capawesome.io/docs/plugins/keep-awake/",
37
+ "keywords": [
38
+ "capacitor",
39
+ "plugin",
40
+ "native"
41
+ ],
42
+ "scripts": {
43
+ "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
44
+ "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
45
+ "verify:android": "cd android && ./gradlew clean build test && cd ..",
46
+ "verify:web": "npm run build",
47
+ "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
48
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
49
+ "eslint": "eslint . --ext ts",
50
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
51
+ "swiftlint": "node-swiftlint",
52
+ "docgen": "docgen --api KeepAwakePlugin --output-readme README.md --output-json dist/docs.json",
53
+ "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
54
+ "clean": "rimraf ./dist",
55
+ "watch": "tsc --watch",
56
+ "ios:pod:install": "cd ios && pod install --repo-update && cd ..",
57
+ "ios:spm:install": "cd ios && swift package resolve && cd ..",
58
+ "prepublishOnly": "npm run build"
59
+ },
60
+ "devDependencies": {
61
+ "@capacitor/android": "8.0.0",
62
+ "@capacitor/cli": "8.0.0",
63
+ "@capacitor/core": "8.0.0",
64
+ "@capacitor/docgen": "0.3.1",
65
+ "@capacitor/ios": "8.0.0",
66
+ "@ionic/eslint-config": "0.4.0",
67
+ "eslint": "8.57.0",
68
+ "prettier-plugin-java": "2.6.7",
69
+ "rimraf": "6.1.2",
70
+ "rollup": "4.53.3",
71
+ "swiftlint": "2.0.0",
72
+ "typescript": "5.9.3"
73
+ },
74
+ "peerDependencies": {
75
+ "@capacitor/core": ">=8.0.0"
76
+ },
77
+ "eslintConfig": {
78
+ "extends": "@ionic/eslint-config/recommended"
79
+ },
80
+ "capacitor": {
81
+ "ios": {
82
+ "src": "ios"
83
+ },
84
+ "android": {
85
+ "src": "android"
86
+ }
87
+ },
88
+ "publishConfig": {
89
+ "access": "public"
90
+ }
91
+ }