@symbiote-native/keep-awake 0.2.0 → 0.3.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/README.md +28 -19
- package/build/angular/services/keep-awake.service/index.js +1 -1
- package/build/core/index.d.ts +1 -1
- package/build/react/hooks/use-keep-awake/index.js +1 -1
- package/build/solid/index.d.ts +2 -0
- package/build/solid/index.js +6 -0
- package/build/solid/primitives/create-keep-awake.d.ts +2 -0
- package/build/solid/primitives/create-keep-awake.js +41 -0
- package/build/svelte/runes/use-keep-awake.svelte.js +1 -1
- package/build/vue/composables/use-keep-awake/index.js +1 -1
- package/build-ngc/angular/services/keep-awake.service/index.js +1 -1
- package/build-ngc/angular/services/keep-awake.service/index.js.map +1 -1
- package/build-ngc/core/index.d.ts +1 -1
- package/build-ngc/core/keep-awake.js.map +1 -1
- package/build-ngc/core/native-module.js.map +1 -1
- package/package.json +22 -8
- package/src/angular/services/keep-awake.service/index.ts +9 -2
- package/src/core/index.ts +5 -1
- package/src/core/keep-awake.ts +10 -4
- package/src/core/native-module.ts +4 -1
- package/src/react/hooks/use-keep-awake/index.ts +9 -2
- package/src/solid/index.ts +7 -0
- package/src/solid/primitives/create-keep-awake.ts +54 -0
- package/src/svelte/runes/use-keep-awake.svelte.ts +9 -2
- package/src/vue/composables/use-keep-awake/index.ts +9 -2
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Port of [`expo-keep-awake`](https://docs.expo.dev/versions/latest/sdk/keep-awake/) for
|
|
4
4
|
[SymbioteNative](../../README.md) — keeps the screen on for the lifetime of a mounted
|
|
5
|
-
component/composable/service, reachable from every adapter (React, Vue, Angular),
|
|
6
|
-
React.
|
|
5
|
+
component/composable/service, reachable from every adapter (React, Vue, Svelte, Solid, Angular),
|
|
6
|
+
not just React.
|
|
7
7
|
|
|
8
8
|
Built the same way as [`@symbiote-native/battery`](../battery) and
|
|
9
9
|
[`@symbiote-native/device`](../device), an `expo-modules-core`-based wrapper (see the
|
|
@@ -31,12 +31,12 @@ into the native host app **once**, covering this package and every other `expo-m
|
|
|
31
31
|
package (`@symbiote-native/battery`, `@symbiote-native/device`, `@symbiote-native/sensors`, …)
|
|
32
32
|
with zero further changes:
|
|
33
33
|
|
|
34
|
-
| Platform | Touches
|
|
35
|
-
|
|
36
|
-
| iOS
|
|
37
|
-
| iOS
|
|
38
|
-
| Android
|
|
39
|
-
| Android
|
|
34
|
+
| Platform | Touches |
|
|
35
|
+
| -------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
36
|
+
| iOS | `ios/Podfile` — add `use_expo_modules!` |
|
|
37
|
+
| iOS | `AppDelegate.swift` — Expo's runtime-bootstrap hook |
|
|
38
|
+
| Android | `settings.gradle` / `app/build.gradle` — resolve and include the Expo Gradle projects |
|
|
39
|
+
| Android | `MainApplication.kt` — Expo's bootstrap hook, plus a hand-written native-module name map (there's no `expo` meta-package here to auto-generate one) |
|
|
40
40
|
|
|
41
41
|
The recurring per-package half of the Android wiring (`app/build.gradle`'s
|
|
42
42
|
`implementation project(':expo-keep-awake')` line and `MainApplication.kt`'s module-name map
|
|
@@ -59,15 +59,18 @@ src/core/ keep-awake.ts — isAvailableAsync/activateKeepAwakeAsyn
|
|
|
59
59
|
KeepAwakeOptions, hand-ported from KeepAwake.types.ts.
|
|
60
60
|
src/react/hooks/ @symbiote-native/keep-awake/react — useKeepAwake
|
|
61
61
|
src/vue/composables/ @symbiote-native/keep-awake/vue — useKeepAwake
|
|
62
|
+
src/svelte/runes/ @symbiote-native/keep-awake/svelte — useKeepAwake
|
|
63
|
+
src/solid/primitives/ @symbiote-native/keep-awake/solid — createKeepAwake (Solid says
|
|
64
|
+
create*, not use*)
|
|
62
65
|
src/angular/services/ @symbiote-native/keep-awake/angular — KeepAwakeService (`.connect()`,
|
|
63
66
|
no return value — a pure side effect for the component's lifetime)
|
|
64
67
|
```
|
|
65
68
|
|
|
66
|
-
Each adapter's hook/composable/service activates a keep-awake lock on mount and
|
|
67
|
-
unmount, over the same `core` functions — the tag-generation and
|
|
68
|
-
written once and shared by
|
|
69
|
-
matching upstream; Vue and Angular have no
|
|
70
|
-
monotonically-incrementing module-local counter (`keep-awake-tag-1`, `keep-awake-tag-2`, …) when
|
|
69
|
+
Each adapter's hook/composable/rune/primitive/service activates a keep-awake lock on mount and
|
|
70
|
+
deactivates it on unmount, over the same `core` functions — the tag-generation and
|
|
71
|
+
activate/deactivate lifecycle is written once and shared by every adapter. React uses `useId()`
|
|
72
|
+
for its default per-instance tag, matching upstream; Vue, Svelte, Solid and Angular have no
|
|
73
|
+
`useId` equivalent, so they fall back to a small monotonically-incrementing module-local counter (`keep-awake-tag-1`, `keep-awake-tag-2`, …) when
|
|
71
74
|
no explicit tag is given.
|
|
72
75
|
|
|
73
76
|
## Use it
|
|
@@ -100,7 +103,7 @@ useKeepAwake();
|
|
|
100
103
|
import { Component, inject } from '@angular/core';
|
|
101
104
|
import { KeepAwakeService } from '@symbiote-native/keep-awake/angular';
|
|
102
105
|
|
|
103
|
-
@Component({
|
|
106
|
+
@Component({/* ... */})
|
|
104
107
|
export class KeepAwakeScreen {
|
|
105
108
|
constructor() {
|
|
106
109
|
inject(KeepAwakeService).connect();
|
|
@@ -123,25 +126,31 @@ as a minimal `unknown` placeholder: upstream's own shape there is web-specific a
|
|
|
123
126
|
analogue, and native listeners for it rarely fire.
|
|
124
127
|
|
|
125
128
|
```ts
|
|
126
|
-
import {
|
|
129
|
+
import {
|
|
130
|
+
activateKeepAwakeAsync,
|
|
131
|
+
deactivateKeepAwake,
|
|
132
|
+
} from '@symbiote-native/keep-awake';
|
|
127
133
|
|
|
128
134
|
// framework-scoped entry points re-export the same free functions, plus a lifecycle
|
|
129
135
|
// hook/composable/service:
|
|
130
136
|
import { useKeepAwake } from '@symbiote-native/keep-awake/react';
|
|
131
137
|
import { useKeepAwake } from '@symbiote-native/keep-awake/vue';
|
|
138
|
+
import { useKeepAwake } from '@symbiote-native/keep-awake/svelte';
|
|
139
|
+
import { createKeepAwake } from '@symbiote-native/keep-awake/solid';
|
|
132
140
|
import { KeepAwakeService } from '@symbiote-native/keep-awake/angular';
|
|
133
141
|
```
|
|
134
142
|
|
|
135
|
-
Each hook/composable/service activates a lock on mount (optionally registering
|
|
136
|
-
once activation resolves) and deactivates it on unmount — mirroring upstream's
|
|
137
|
-
`useKeepAwake(tag?, options?)`.
|
|
143
|
+
Each hook/composable/rune/primitive/service activates a lock on mount (optionally registering
|
|
144
|
+
`options.listener` once activation resolves) and deactivates it on unmount — mirroring upstream's
|
|
145
|
+
own `useKeepAwake(tag?, options?)`. Solid's `createKeepAwake(tag?, options?)` does it from the
|
|
146
|
+
primitive body, releasing through `onCleanup`.
|
|
138
147
|
|
|
139
148
|
## Test it
|
|
140
149
|
|
|
141
150
|
No Fabric/Descriptor angle at all — keep-awake is a pure async-function + `EventEmitter` listener
|
|
142
151
|
surface, never a view. Tests inject a fake native-module object in place of the real
|
|
143
152
|
`requireNativeModule` resolution (`src/core/keep-awake.test.ts`,
|
|
144
|
-
`src/{react,vue,angular}/**/*.test.{ts,tsx}`, `vitest`), the same pattern
|
|
153
|
+
`src/{react,vue,svelte,solid,angular}/**/*.test.{ts,tsx}`, `vitest`), the same pattern
|
|
145
154
|
`@symbiote-native/battery` and `@symbiote-native/device` use — no `installFabric()`-driven Fabric
|
|
146
155
|
assertions on the core level, only the adapter lifecycle tests mount through the fake Fabric slot
|
|
147
156
|
to prove activate-on-mount/deactivate-on-unmount. Native rendering itself is verified on-device —
|
|
@@ -33,7 +33,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
33
33
|
return useValue ? value : void 0;
|
|
34
34
|
};
|
|
35
35
|
import { effect, inject, Injectable, Injector } from '@angular/core';
|
|
36
|
-
import { activateKeepAwakeAsync, deactivateKeepAwake } from '../../../core/index.js';
|
|
36
|
+
import { activateKeepAwakeAsync, deactivateKeepAwake, } from '../../../core/index.js';
|
|
37
37
|
import { createKeepAwakeListenerAttachment } from '../../../core/listener-attachment.js';
|
|
38
38
|
// Angular twin of React's `useKeepAwake` hook and Vue's `useKeepAwake` composable. See
|
|
39
39
|
// LowPowerModeService (packages/battery) for the `connect()`/`effect()` pattern rationale — same
|
package/build/core/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { ExpoKeepAwakeTag, isAvailableAsync, activateKeepAwakeAsync, deactivateKeepAwake, addListener, } from './keep-awake';
|
|
2
|
-
export type { KeepAwakeEvent, KeepAwakeListener, KeepAwakeOptions } from './types';
|
|
2
|
+
export type { KeepAwakeEvent, KeepAwakeListener, KeepAwakeOptions, } from './types';
|
|
3
3
|
export type { EventSubscription } from 'expo-modules-core';
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// that's not reachable here (only core's public API is), so an UnavailabilityError from
|
|
8
8
|
// `addListener` is just swallowed by the trailing `.catch(() => {})` instead - same net effect.
|
|
9
9
|
import { useEffect, useId } from 'react';
|
|
10
|
-
import { activateKeepAwakeAsync, deactivateKeepAwake } from '../../../core/index.js';
|
|
10
|
+
import { activateKeepAwakeAsync, deactivateKeepAwake, } from '../../../core/index.js';
|
|
11
11
|
import { createKeepAwakeListenerAttachment } from '../../../core/listener-attachment.js';
|
|
12
12
|
export function useKeepAwake(tag, options) {
|
|
13
13
|
const defaultTag = useId();
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// @symbiote-native/keep-awake/solid: the Solid entry over the framework-agnostic core. The
|
|
2
|
+
// lifecycle bucket is `primitives/` and the name is `create*` (never `hooks/`/`use*`, that is
|
|
3
|
+
// React's term and Solid's word for consuming an existing thing) — see
|
|
4
|
+
// adapters/solid/src/primitives for the same convention.
|
|
5
|
+
export { createKeepAwake } from './primitives/create-keep-awake.js';
|
|
6
|
+
export * from '../core/index.js';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Solid lifecycle wiring over the framework-agnostic core (core/keep-awake.ts): activates a
|
|
2
|
+
// keep-awake lock in the primitive body, deactivates it when the owner is disposed — the Solid
|
|
3
|
+
// twin of React's hook, Vue's composable, Svelte's rune and Angular's KeepAwakeService.connect().
|
|
4
|
+
//
|
|
5
|
+
// `primitives/` and `create*`, not `hooks/`/`use*`: Solid's ecosystem calls a composable reactive
|
|
6
|
+
// function a PRIMITIVE and reserves `use*` for consuming something that already exists. Full
|
|
7
|
+
// rationale in adapters/solid/src/primitives/create-color-scheme.ts's header.
|
|
8
|
+
//
|
|
9
|
+
// Activation runs SYNCHRONOUSLY in the body with `onCleanup` for teardown, not from a mount hook
|
|
10
|
+
// (React's useEffect, Vue's onMounted, Svelte's $effect) — the lock is requested one tick earlier,
|
|
11
|
+
// and nothing can interleave between construction and the request.
|
|
12
|
+
//
|
|
13
|
+
// Nothing reactive is returned: keeping the screen awake is a pure side effect for the owner's
|
|
14
|
+
// lifetime, so there is no accessor and the once-per-owner contract matches Vue/Svelte/Angular
|
|
15
|
+
// rather than React's hook, which re-runs when the tag changes.
|
|
16
|
+
//
|
|
17
|
+
// No `useId` in Solid, so the default tag comes from a module-local counter, as in Vue and Svelte.
|
|
18
|
+
//
|
|
19
|
+
// Outside a component / createRoot there is no owner for `onCleanup`, so the lock is never
|
|
20
|
+
// released — see create-color-scheme's header for the same documented caveat.
|
|
21
|
+
import { onCleanup } from 'solid-js';
|
|
22
|
+
import { activateKeepAwakeAsync, deactivateKeepAwake, } from '../../core/index.js';
|
|
23
|
+
import { createKeepAwakeListenerAttachment } from '../../core/listener-attachment.js';
|
|
24
|
+
let tagCounter = 0;
|
|
25
|
+
export function createKeepAwake(tag, options) {
|
|
26
|
+
const tagOrDefault = tag ?? `keep-awake-tag-${++tagCounter}`;
|
|
27
|
+
// One attachment per owner: the body runs once, so it spans the single activate/onCleanup pair.
|
|
28
|
+
const attachment = createKeepAwakeListenerAttachment(tagOrDefault, options?.listener);
|
|
29
|
+
activateKeepAwakeAsync(tagOrDefault)
|
|
30
|
+
.then(() => attachment.attach())
|
|
31
|
+
.catch(() => { });
|
|
32
|
+
onCleanup(() => {
|
|
33
|
+
attachment.release();
|
|
34
|
+
if (options?.suppressDeactivateWarnings) {
|
|
35
|
+
deactivateKeepAwake(tagOrDefault).catch(() => { });
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
deactivateKeepAwake(tagOrDefault);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
//
|
|
14
14
|
// No `useId` in Svelte, so the default tag comes from a module-local counter, as in Vue's
|
|
15
15
|
// composable.
|
|
16
|
-
import { activateKeepAwakeAsync, deactivateKeepAwake } from '../../core/index.js';
|
|
16
|
+
import { activateKeepAwakeAsync, deactivateKeepAwake, } from '../../core/index.js';
|
|
17
17
|
import { createKeepAwakeListenerAttachment } from '../../core/listener-attachment.js';
|
|
18
18
|
let tagCounter = 0;
|
|
19
19
|
export function useKeepAwake(tag, options) {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// counter instead — simplest robust way to give each composable instance its own tag when the
|
|
5
5
|
// caller doesn't supply one.
|
|
6
6
|
import { onMounted, onUnmounted } from '@vue/runtime-core';
|
|
7
|
-
import { activateKeepAwakeAsync, deactivateKeepAwake } from '../../../core/index.js';
|
|
7
|
+
import { activateKeepAwakeAsync, deactivateKeepAwake, } from '../../../core/index.js';
|
|
8
8
|
import { createKeepAwakeListenerAttachment } from '../../../core/listener-attachment.js';
|
|
9
9
|
let tagCounter = 0;
|
|
10
10
|
export function useKeepAwake(tag, options) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { effect, inject, Injectable, Injector } from '@angular/core';
|
|
2
|
-
import { activateKeepAwakeAsync, deactivateKeepAwake } from '../../../core';
|
|
2
|
+
import { activateKeepAwakeAsync, deactivateKeepAwake, } from '../../../core';
|
|
3
3
|
import { createKeepAwakeListenerAttachment } from '../../../core/listener-attachment';
|
|
4
4
|
import * as i0 from "@angular/core";
|
|
5
5
|
// Angular twin of React's `useKeepAwake` hook and Vue's `useKeepAwake` composable. See
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/angular/services/keep-awake.service/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/angular/services/keep-awake.service/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EACL,sBAAsB,EACtB,mBAAmB,GAEpB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iCAAiC,EAAE,MAAM,mCAAmC,CAAC;;AAEtF,uFAAuF;AACvF,iGAAiG;AACjG,+FAA+F;AAC/F,6FAA6F;AAC7F,yFAAyF;AACzF,EAAE;AACF,0DAA0D;AAC1D,IAAI,UAAU,GAAG,CAAC,CAAC;AAGnB,MAAM,OAAO,gBAAgB;IACV,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAE7C,OAAO,CAAC,GAAY,EAAE,OAA0B;QAC9C,MAAM,YAAY,GAAG,GAAG,IAAI,kBAAkB,EAAE,UAAU,EAAE,CAAC;QAE7D,MAAM,CACJ,SAAS,CAAC,EAAE;YACV,sFAAsF;YACtF,2DAA2D;YAC3D,MAAM,UAAU,GAAG,iCAAiC,CAClD,YAAY,EACZ,OAAO,EAAE,QAAQ,CAClB,CAAC;YAEF,sBAAsB,CAAC,YAAY,CAAC;iBACjC,IAAI,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;iBAC/B,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YAEnB,SAAS,CAAC,GAAG,EAAE;gBACb,UAAU,CAAC,OAAO,EAAE,CAAC;gBACrB,IAAI,OAAO,EAAE,0BAA0B,EAAE,CAAC;oBACxC,mBAAmB,CAAC,YAAY,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;gBACpD,CAAC;qBAAM,CAAC;oBACN,mBAAmB,CAAC,YAAY,CAAC,CAAC;gBACpC,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,EACD,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAC5B,CAAC;IACJ,CAAC;uGA9BU,gBAAgB;2GAAhB,gBAAgB,cADH,MAAM;;2FACnB,gBAAgB;kBAD5B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { ExpoKeepAwakeTag, isAvailableAsync, activateKeepAwakeAsync, deactivateKeepAwake, addListener, } from './keep-awake';
|
|
2
|
-
export type { KeepAwakeEvent, KeepAwakeListener, KeepAwakeOptions } from './types';
|
|
2
|
+
export type { KeepAwakeEvent, KeepAwakeListener, KeepAwakeOptions, } from './types';
|
|
3
3
|
export type { EventSubscription } from 'expo-modules-core';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keep-awake.js","sourceRoot":"","sources":["../../src/core/keep-awake.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,oFAAoF;AACpF,2FAA2F;AAC3F,6EAA6E;AAC7E,qFAAqF;AACrF,OAAO,EAAE,mBAAmB,EAA0B,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,MAAM,CAAC,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AAE1D,4EAA4E;AAC5E,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,IAAI,aAAa,CAAC,gBAAgB,EAAE,CAAC;QACnC,OAAO,MAAM,aAAa,CAAC,gBAAgB,EAAE,CAAC;IAChD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,
|
|
1
|
+
{"version":3,"file":"keep-awake.js","sourceRoot":"","sources":["../../src/core/keep-awake.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,oFAAoF;AACpF,2FAA2F;AAC3F,6EAA6E;AAC7E,qFAAqF;AACrF,OAAO,EAAE,mBAAmB,EAA0B,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,MAAM,CAAC,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AAE1D,4EAA4E;AAC5E,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,IAAI,aAAa,CAAC,gBAAgB,EAAE,CAAC;QACnC,OAAO,MAAM,aAAa,CAAC,gBAAgB,EAAE,CAAC;IAChD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,MAAc,gBAAgB;IAE9B,MAAM,aAAa,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC;AAED,iGAAiG;AACjG,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAAc,gBAAgB;IAE9B,MAAM,aAAa,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC;AACxC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CACzB,aAAyC,EACzC,QAA4B;IAE5B,IAAI,CAAC,aAAa,CAAC,iBAAiB,EAAE,CAAC;QACrC,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,mBAAmB,CAAC,CAAC;IACtE,CAAC;IACD,MAAM,GAAG,GACP,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,gBAAgB,CAAC;IACvE,MAAM,gBAAgB,GACpB,OAAO,aAAa,KAAK,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC;IACjE,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,SAAS,CAAC,0CAA0C,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,aAAa,CAAC,iBAAiB,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-module.js","sourceRoot":"","sources":["../../src/core/native-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAIxD,MAAM,2BAA2B,GAAG,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"native-module.js","sourceRoot":"","sources":["../../src/core/native-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAIxD,MAAM,2BAA2B,GAAG,eAAe,CAAC;AAgBpD,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,CAC9C,2BAA2B,CAC5B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbiote-native/keep-awake",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "expo-keep-awake wrapped for SymbioteNative — one framework-agnostic core, built once and reachable from the React, Vue, and Angular adapters. Keeps the screen awake for the lifetime of a mounted component/composable/service, with an optional listener for keep-awake state changes.",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "expo-keep-awake wrapped for SymbioteNative — one framework-agnostic core, built once and reachable from the React, Vue, Svelte, Solid, and Angular adapters. Keeps the screen awake for the lifetime of a mounted component/composable/service, with an optional listener for keep-awake state changes.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -34,6 +34,10 @@
|
|
|
34
34
|
"types": "./build/svelte/index.d.ts",
|
|
35
35
|
"default": "./build/svelte/index.js"
|
|
36
36
|
},
|
|
37
|
+
"./solid": {
|
|
38
|
+
"types": "./build/solid/index.d.ts",
|
|
39
|
+
"default": "./build/solid/index.js"
|
|
40
|
+
},
|
|
37
41
|
"./angular": {
|
|
38
42
|
"types": "./build-ngc/angular/index.d.ts",
|
|
39
43
|
"react-native": "./build-ngc/angular/index.js",
|
|
@@ -60,12 +64,14 @@
|
|
|
60
64
|
"@symbiote-native/angular": ">=0.6.2",
|
|
61
65
|
"@symbiote-native/engine": ">=0.1.7",
|
|
62
66
|
"@symbiote-native/react": ">=0.2.8",
|
|
67
|
+
"@symbiote-native/solid": ">=0.0.1",
|
|
63
68
|
"@symbiote-native/svelte": ">=0.1.0",
|
|
64
69
|
"@symbiote-native/vue": ">=0.3.8",
|
|
65
70
|
"@angular/core": ">=20",
|
|
66
71
|
"@vue/runtime-core": "^3.5.13",
|
|
67
72
|
"react": ">=19.0.0",
|
|
68
73
|
"react-native": ">=0.86",
|
|
74
|
+
"solid-js": ">=1.9.0",
|
|
69
75
|
"svelte": ">=5.56.0",
|
|
70
76
|
"vue": ">=3.5.0"
|
|
71
77
|
},
|
|
@@ -76,6 +82,9 @@
|
|
|
76
82
|
"@symbiote-native/react": {
|
|
77
83
|
"optional": true
|
|
78
84
|
},
|
|
85
|
+
"@symbiote-native/solid": {
|
|
86
|
+
"optional": true
|
|
87
|
+
},
|
|
79
88
|
"@symbiote-native/svelte": {
|
|
80
89
|
"optional": true
|
|
81
90
|
},
|
|
@@ -91,6 +100,9 @@
|
|
|
91
100
|
"react": {
|
|
92
101
|
"optional": true
|
|
93
102
|
},
|
|
103
|
+
"solid-js": {
|
|
104
|
+
"optional": true
|
|
105
|
+
},
|
|
94
106
|
"svelte": {
|
|
95
107
|
"optional": true
|
|
96
108
|
},
|
|
@@ -106,14 +118,16 @@
|
|
|
106
118
|
"@types/react": "^19.2.0",
|
|
107
119
|
"@vue/runtime-core": "^3.5.13",
|
|
108
120
|
"react": "19.2.3",
|
|
121
|
+
"solid-js": "^1.9.14",
|
|
109
122
|
"svelte": "^5.56.0",
|
|
110
123
|
"typescript": "~6.0.0",
|
|
111
|
-
"@symbiote-native/angular": "0.
|
|
112
|
-
"@symbiote-native/engine": "0.
|
|
113
|
-
"@symbiote-native/react": "0.
|
|
114
|
-
"@symbiote-native/
|
|
115
|
-
"@symbiote-native/
|
|
116
|
-
"@symbiote-native/
|
|
124
|
+
"@symbiote-native/angular": "0.8.0",
|
|
125
|
+
"@symbiote-native/engine": "0.3.0",
|
|
126
|
+
"@symbiote-native/react": "0.4.0",
|
|
127
|
+
"@symbiote-native/solid": "0.1.0",
|
|
128
|
+
"@symbiote-native/svelte": "0.3.0",
|
|
129
|
+
"@symbiote-native/test-utils": "0.2.0",
|
|
130
|
+
"@symbiote-native/vue": "0.5.0"
|
|
117
131
|
},
|
|
118
132
|
"scripts": {
|
|
119
133
|
"typecheck": "tsc --build",
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { effect, inject, Injectable, Injector } from '@angular/core';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
activateKeepAwakeAsync,
|
|
4
|
+
deactivateKeepAwake,
|
|
5
|
+
type KeepAwakeOptions,
|
|
6
|
+
} from '../../../core';
|
|
3
7
|
import { createKeepAwakeListenerAttachment } from '../../../core/listener-attachment';
|
|
4
8
|
|
|
5
9
|
// Angular twin of React's `useKeepAwake` hook and Vue's `useKeepAwake` composable. See
|
|
@@ -22,7 +26,10 @@ export class KeepAwakeService {
|
|
|
22
26
|
onCleanup => {
|
|
23
27
|
// Per effect run: onCleanup releases this exact attachment, so a re-run always starts
|
|
24
28
|
// from a fresh one rather than reviving a released attach.
|
|
25
|
-
const attachment = createKeepAwakeListenerAttachment(
|
|
29
|
+
const attachment = createKeepAwakeListenerAttachment(
|
|
30
|
+
tagOrDefault,
|
|
31
|
+
options?.listener,
|
|
32
|
+
);
|
|
26
33
|
|
|
27
34
|
activateKeepAwakeAsync(tagOrDefault)
|
|
28
35
|
.then(() => attachment.attach())
|
package/src/core/index.ts
CHANGED
|
@@ -5,5 +5,9 @@ export {
|
|
|
5
5
|
deactivateKeepAwake,
|
|
6
6
|
addListener,
|
|
7
7
|
} from './keep-awake';
|
|
8
|
-
export type {
|
|
8
|
+
export type {
|
|
9
|
+
KeepAwakeEvent,
|
|
10
|
+
KeepAwakeListener,
|
|
11
|
+
KeepAwakeOptions,
|
|
12
|
+
} from './types';
|
|
9
13
|
export type { EventSubscription } from 'expo-modules-core';
|
package/src/core/keep-awake.ts
CHANGED
|
@@ -21,12 +21,16 @@ export async function isAvailableAsync(): Promise<boolean> {
|
|
|
21
21
|
* Activates a keep-awake lock under `tag` (the shared default tag when none is given) — the
|
|
22
22
|
* screen stays on for as long as any tag holds an active lock.
|
|
23
23
|
*/
|
|
24
|
-
export async function activateKeepAwakeAsync(
|
|
24
|
+
export async function activateKeepAwakeAsync(
|
|
25
|
+
tag: string = ExpoKeepAwakeTag,
|
|
26
|
+
): Promise<void> {
|
|
25
27
|
await expoKeepAwake.activate?.(tag);
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
/** Releases the keep-awake lock held under `tag` (the shared default tag when none is given). */
|
|
29
|
-
export async function deactivateKeepAwake(
|
|
31
|
+
export async function deactivateKeepAwake(
|
|
32
|
+
tag: string = ExpoKeepAwakeTag,
|
|
33
|
+
): Promise<void> {
|
|
30
34
|
await expoKeepAwake.deactivate?.(tag);
|
|
31
35
|
}
|
|
32
36
|
|
|
@@ -41,8 +45,10 @@ export function addListener(
|
|
|
41
45
|
if (!expoKeepAwake.addListenerForTag) {
|
|
42
46
|
throw new UnavailabilityError('ExpoKeepAwake', 'addListenerForTag');
|
|
43
47
|
}
|
|
44
|
-
const tag =
|
|
45
|
-
|
|
48
|
+
const tag =
|
|
49
|
+
typeof tagOrListener === 'string' ? tagOrListener : ExpoKeepAwakeTag;
|
|
50
|
+
const resolvedListener =
|
|
51
|
+
typeof tagOrListener === 'function' ? tagOrListener : listener;
|
|
46
52
|
if (!resolvedListener) {
|
|
47
53
|
throw new TypeError('addListener requires a listener function');
|
|
48
54
|
}
|
|
@@ -12,7 +12,10 @@ export type INativeKeepAwakeModule = {
|
|
|
12
12
|
isAvailableAsync?(): Promise<boolean>;
|
|
13
13
|
activate?(tag: string): Promise<void>;
|
|
14
14
|
deactivate?(tag: string): Promise<void>;
|
|
15
|
-
addListenerForTag?(
|
|
15
|
+
addListenerForTag?(
|
|
16
|
+
tag: string,
|
|
17
|
+
listener: KeepAwakeListener,
|
|
18
|
+
): EventSubscription;
|
|
16
19
|
};
|
|
17
20
|
|
|
18
21
|
export const expoKeepAwake = requireNativeModule<INativeKeepAwakeModule>(
|
|
@@ -7,7 +7,11 @@
|
|
|
7
7
|
// that's not reachable here (only core's public API is), so an UnavailabilityError from
|
|
8
8
|
// `addListener` is just swallowed by the trailing `.catch(() => {})` instead - same net effect.
|
|
9
9
|
import { useEffect, useId } from 'react';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
activateKeepAwakeAsync,
|
|
12
|
+
deactivateKeepAwake,
|
|
13
|
+
type KeepAwakeOptions,
|
|
14
|
+
} from '../../../core';
|
|
11
15
|
import { createKeepAwakeListenerAttachment } from '../../../core/listener-attachment';
|
|
12
16
|
|
|
13
17
|
export function useKeepAwake(tag?: string, options?: KeepAwakeOptions): void {
|
|
@@ -17,7 +21,10 @@ export function useKeepAwake(tag?: string, options?: KeepAwakeOptions): void {
|
|
|
17
21
|
useEffect(() => {
|
|
18
22
|
// Per effect run, not per hook call - a changed tag tears the old attachment down with the
|
|
19
23
|
// rest of the cleanup and starts a fresh one.
|
|
20
|
-
const attachment = createKeepAwakeListenerAttachment(
|
|
24
|
+
const attachment = createKeepAwakeListenerAttachment(
|
|
25
|
+
tagOrDefault,
|
|
26
|
+
options?.listener,
|
|
27
|
+
);
|
|
21
28
|
|
|
22
29
|
activateKeepAwakeAsync(tagOrDefault)
|
|
23
30
|
.then(() => attachment.attach())
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// @symbiote-native/keep-awake/solid: the Solid entry over the framework-agnostic core. The
|
|
2
|
+
// lifecycle bucket is `primitives/` and the name is `create*` (never `hooks/`/`use*`, that is
|
|
3
|
+
// React's term and Solid's word for consuming an existing thing) — see
|
|
4
|
+
// adapters/solid/src/primitives for the same convention.
|
|
5
|
+
|
|
6
|
+
export { createKeepAwake } from './primitives/create-keep-awake';
|
|
7
|
+
export * from '../core';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Solid lifecycle wiring over the framework-agnostic core (core/keep-awake.ts): activates a
|
|
2
|
+
// keep-awake lock in the primitive body, deactivates it when the owner is disposed — the Solid
|
|
3
|
+
// twin of React's hook, Vue's composable, Svelte's rune and Angular's KeepAwakeService.connect().
|
|
4
|
+
//
|
|
5
|
+
// `primitives/` and `create*`, not `hooks/`/`use*`: Solid's ecosystem calls a composable reactive
|
|
6
|
+
// function a PRIMITIVE and reserves `use*` for consuming something that already exists. Full
|
|
7
|
+
// rationale in adapters/solid/src/primitives/create-color-scheme.ts's header.
|
|
8
|
+
//
|
|
9
|
+
// Activation runs SYNCHRONOUSLY in the body with `onCleanup` for teardown, not from a mount hook
|
|
10
|
+
// (React's useEffect, Vue's onMounted, Svelte's $effect) — the lock is requested one tick earlier,
|
|
11
|
+
// and nothing can interleave between construction and the request.
|
|
12
|
+
//
|
|
13
|
+
// Nothing reactive is returned: keeping the screen awake is a pure side effect for the owner's
|
|
14
|
+
// lifetime, so there is no accessor and the once-per-owner contract matches Vue/Svelte/Angular
|
|
15
|
+
// rather than React's hook, which re-runs when the tag changes.
|
|
16
|
+
//
|
|
17
|
+
// No `useId` in Solid, so the default tag comes from a module-local counter, as in Vue and Svelte.
|
|
18
|
+
//
|
|
19
|
+
// Outside a component / createRoot there is no owner for `onCleanup`, so the lock is never
|
|
20
|
+
// released — see create-color-scheme's header for the same documented caveat.
|
|
21
|
+
import { onCleanup } from 'solid-js';
|
|
22
|
+
import {
|
|
23
|
+
activateKeepAwakeAsync,
|
|
24
|
+
deactivateKeepAwake,
|
|
25
|
+
type KeepAwakeOptions,
|
|
26
|
+
} from '../../core';
|
|
27
|
+
import { createKeepAwakeListenerAttachment } from '../../core/listener-attachment';
|
|
28
|
+
|
|
29
|
+
let tagCounter = 0;
|
|
30
|
+
|
|
31
|
+
export function createKeepAwake(
|
|
32
|
+
tag?: string,
|
|
33
|
+
options?: KeepAwakeOptions,
|
|
34
|
+
): void {
|
|
35
|
+
const tagOrDefault = tag ?? `keep-awake-tag-${++tagCounter}`;
|
|
36
|
+
// One attachment per owner: the body runs once, so it spans the single activate/onCleanup pair.
|
|
37
|
+
const attachment = createKeepAwakeListenerAttachment(
|
|
38
|
+
tagOrDefault,
|
|
39
|
+
options?.listener,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
activateKeepAwakeAsync(tagOrDefault)
|
|
43
|
+
.then(() => attachment.attach())
|
|
44
|
+
.catch(() => {});
|
|
45
|
+
|
|
46
|
+
onCleanup(() => {
|
|
47
|
+
attachment.release();
|
|
48
|
+
if (options?.suppressDeactivateWarnings) {
|
|
49
|
+
deactivateKeepAwake(tagOrDefault).catch(() => {});
|
|
50
|
+
} else {
|
|
51
|
+
deactivateKeepAwake(tagOrDefault);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -13,7 +13,11 @@
|
|
|
13
13
|
//
|
|
14
14
|
// No `useId` in Svelte, so the default tag comes from a module-local counter, as in Vue's
|
|
15
15
|
// composable.
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
activateKeepAwakeAsync,
|
|
18
|
+
deactivateKeepAwake,
|
|
19
|
+
type KeepAwakeOptions,
|
|
20
|
+
} from '../../core';
|
|
17
21
|
import { createKeepAwakeListenerAttachment } from '../../core/listener-attachment';
|
|
18
22
|
|
|
19
23
|
let tagCounter = 0;
|
|
@@ -23,7 +27,10 @@ export function useKeepAwake(tag?: string, options?: KeepAwakeOptions): void {
|
|
|
23
27
|
|
|
24
28
|
$effect(() => {
|
|
25
29
|
// Inside the effect, so the attachment shares the teardown returned below.
|
|
26
|
-
const attachment = createKeepAwakeListenerAttachment(
|
|
30
|
+
const attachment = createKeepAwakeListenerAttachment(
|
|
31
|
+
tagOrDefault,
|
|
32
|
+
options?.listener,
|
|
33
|
+
);
|
|
27
34
|
|
|
28
35
|
activateKeepAwakeAsync(tagOrDefault)
|
|
29
36
|
.then(() => attachment.attach())
|
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
// counter instead — simplest robust way to give each composable instance its own tag when the
|
|
5
5
|
// caller doesn't supply one.
|
|
6
6
|
import { onMounted, onUnmounted } from '@vue/runtime-core';
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
activateKeepAwakeAsync,
|
|
9
|
+
deactivateKeepAwake,
|
|
10
|
+
type KeepAwakeOptions,
|
|
11
|
+
} from '../../../core';
|
|
8
12
|
import { createKeepAwakeListenerAttachment } from '../../../core/listener-attachment';
|
|
9
13
|
|
|
10
14
|
let tagCounter = 0;
|
|
@@ -13,7 +17,10 @@ export function useKeepAwake(tag?: string, options?: KeepAwakeOptions): void {
|
|
|
13
17
|
const tagOrDefault = tag ?? `keep-awake-tag-${++tagCounter}`;
|
|
14
18
|
// Setup body scope: it runs once per instance, so one attachment spans the single
|
|
15
19
|
// onMounted/onUnmounted pair - no need to re-create it on the mount hook.
|
|
16
|
-
const attachment = createKeepAwakeListenerAttachment(
|
|
20
|
+
const attachment = createKeepAwakeListenerAttachment(
|
|
21
|
+
tagOrDefault,
|
|
22
|
+
options?.listener,
|
|
23
|
+
);
|
|
17
24
|
|
|
18
25
|
onMounted(() => {
|
|
19
26
|
activateKeepAwakeAsync(tagOrDefault)
|