@capawesome/capacitor-keep-awake 0.0.1 → 0.1.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.
- package/README.md +78 -3
- package/android/build.gradle +1 -1
- package/package.json +12 -4
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Capacitor Keep Awake Plugin
|
|
2
2
|
|
|
3
3
|
Capacitor plugin to keep the screen awake.
|
|
4
4
|
|
|
@@ -19,9 +19,14 @@ Capacitor plugin to keep the screen awake.
|
|
|
19
19
|
|
|
20
20
|
Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
|
|
21
21
|
|
|
22
|
-
##
|
|
22
|
+
## Use Cases
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
The Keep Awake plugin is typically used whenever the screen must stay visible without user interaction, for example:
|
|
25
|
+
|
|
26
|
+
- **Media playback**: Keep the screen on while users watch videos or follow along with content.
|
|
27
|
+
- **Navigation and tracking**: Prevent the display from turning off during turn-by-turn navigation or workout tracking.
|
|
28
|
+
- **Hands-free reading**: Keep recipes, sheet music, or step-by-step instructions visible while the user's hands are busy.
|
|
29
|
+
- **Dashboards and kiosks**: Display live data or presentations without the screen dimming or sleeping.
|
|
25
30
|
|
|
26
31
|
## Compatibility
|
|
27
32
|
|
|
@@ -59,21 +64,51 @@ No configuration required for this plugin.
|
|
|
59
64
|
|
|
60
65
|
## Usage
|
|
61
66
|
|
|
67
|
+
The following examples show how to keep the screen awake, allow it to sleep again, check whether it is currently kept awake, and check whether the feature is available.
|
|
68
|
+
|
|
69
|
+
### Keep the screen awake
|
|
70
|
+
|
|
71
|
+
Prevent the screen from dimming or turning off. The screen is kept awake until `allowSleep(...)` is called or the app is restarted. This only affects your app and is not a system-wide setting:
|
|
72
|
+
|
|
62
73
|
```typescript
|
|
63
74
|
import { KeepAwake } from '@capawesome/capacitor-keep-awake';
|
|
64
75
|
|
|
65
76
|
const keepAwake = async () => {
|
|
66
77
|
await KeepAwake.keepAwake();
|
|
67
78
|
};
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Allow the screen to sleep again
|
|
82
|
+
|
|
83
|
+
Restore the default screen sleep behavior at any time:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { KeepAwake } from '@capawesome/capacitor-keep-awake';
|
|
68
87
|
|
|
69
88
|
const allowSleep = async () => {
|
|
70
89
|
await KeepAwake.allowSleep();
|
|
71
90
|
};
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Check if the screen is kept awake
|
|
94
|
+
|
|
95
|
+
Read whether the screen is currently kept awake:
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { KeepAwake } from '@capawesome/capacitor-keep-awake';
|
|
72
99
|
|
|
73
100
|
const isKeptAwake = async () => {
|
|
74
101
|
const { keptAwake } = await KeepAwake.isKeptAwake();
|
|
75
102
|
return keptAwake;
|
|
76
103
|
};
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Check if the feature is available
|
|
107
|
+
|
|
108
|
+
On the Web, keeping the screen awake depends on whether the browser supports the [Screen Wake Lock API](https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API). On Android and iOS, this always returns `true`:
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import { KeepAwake } from '@capawesome/capacitor-keep-awake';
|
|
77
112
|
|
|
78
113
|
const isAvailable = async () => {
|
|
79
114
|
const { available } = await KeepAwake.isAvailable();
|
|
@@ -195,6 +230,46 @@ Keep the following in mind when using this plugin:
|
|
|
195
230
|
- **State reset**: The screen is only kept awake until `allowSleep(...)` is called or the app is restarted.
|
|
196
231
|
- **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
232
|
|
|
233
|
+
## FAQ
|
|
234
|
+
|
|
235
|
+
### How is this plugin different from other similar plugins?
|
|
236
|
+
|
|
237
|
+
It keeps the screen awake on Android, iOS, and the Web from one fully typed API, and lets you check both whether the feature is available and whether the screen is currently kept awake. On the Web it uses the Screen Wake Lock API and automatically re-acquires the lock when a hidden tab becomes visible again, so the behavior stays predictable across platforms. It needs no permissions or configuration and is actively maintained against the latest Capacitor version.
|
|
238
|
+
|
|
239
|
+
### Which platforms does this plugin support?
|
|
240
|
+
|
|
241
|
+
The plugin supports Android, iOS and Web. On the Web, it relies on the Screen Wake Lock API, so availability depends on the browser. You can check this at runtime with the `isAvailable()` method, which always returns `true` on Android and iOS.
|
|
242
|
+
|
|
243
|
+
### Does keeping the screen awake affect other apps?
|
|
244
|
+
|
|
245
|
+
No, keeping the screen awake only affects your app and is not a system-wide setting. As soon as the user leaves your app, the default screen sleep behavior of the device applies again.
|
|
246
|
+
|
|
247
|
+
### How long is the screen kept awake?
|
|
248
|
+
|
|
249
|
+
The screen is kept awake until `allowSleep(...)` is called or the app is restarted. The setting is not persisted across app restarts.
|
|
250
|
+
|
|
251
|
+
### Why does the screen sleep again on the Web after switching tabs?
|
|
252
|
+
|
|
253
|
+
On the Web, the browser automatically releases the underlying wake lock 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. See the [Behavior](#behavior) section for details.
|
|
254
|
+
|
|
255
|
+
### Do I need any permissions or configuration?
|
|
256
|
+
|
|
257
|
+
No, the plugin does not require any permissions or configuration on any platform. Simply install it and call `keepAwake()`.
|
|
258
|
+
|
|
259
|
+
### Can I use this plugin with Ionic, React, Vue or Angular?
|
|
260
|
+
|
|
261
|
+
Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.
|
|
262
|
+
|
|
263
|
+
## Related Plugins
|
|
264
|
+
|
|
265
|
+
- [Screen Brightness](https://capawesome.io/docs/sdks/capacitor/screen-brightness/): Read and control the screen brightness.
|
|
266
|
+
- [Screen Orientation](https://capawesome.io/docs/sdks/capacitor/screen-orientation/): Lock and unlock the screen orientation.
|
|
267
|
+
- [Battery](https://capawesome.io/docs/sdks/capacitor/battery/): Access battery information of the device.
|
|
268
|
+
|
|
269
|
+
## Newsletter
|
|
270
|
+
|
|
271
|
+
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/).
|
|
272
|
+
|
|
198
273
|
## Changelog
|
|
199
274
|
|
|
200
275
|
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/keep-awake/CHANGELOG.md).
|
package/android/build.gradle
CHANGED
|
@@ -30,7 +30,7 @@ android {
|
|
|
30
30
|
buildTypes {
|
|
31
31
|
release {
|
|
32
32
|
minifyEnabled false
|
|
33
|
-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
lintOptions {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capawesome/capacitor-keep-awake",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Capacitor plugin to keep the screen awake.",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Capacitor plugin to keep the screen awake on Android, iOS, and Web.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/esm/index.d.ts",
|
|
@@ -33,11 +33,19 @@
|
|
|
33
33
|
"url": "https://opencollective.com/capawesome"
|
|
34
34
|
}
|
|
35
35
|
],
|
|
36
|
-
"homepage": "https://capawesome.io/docs/
|
|
36
|
+
"homepage": "https://capawesome.io/docs/sdks/capacitor/keep-awake/",
|
|
37
37
|
"keywords": [
|
|
38
38
|
"capacitor",
|
|
39
39
|
"plugin",
|
|
40
|
-
"native"
|
|
40
|
+
"native",
|
|
41
|
+
"capacitor-plugin",
|
|
42
|
+
"keep awake",
|
|
43
|
+
"keep screen on",
|
|
44
|
+
"wake lock",
|
|
45
|
+
"screen wake lock",
|
|
46
|
+
"prevent sleep",
|
|
47
|
+
"screen timeout",
|
|
48
|
+
"display awake"
|
|
41
49
|
],
|
|
42
50
|
"scripts": {
|
|
43
51
|
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|