@symbiote-native/battery 0.0.1 → 0.2.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.
Files changed (88) hide show
  1. package/README.md +172 -27
  2. package/build/angular/index.d.ts +4 -0
  3. package/build/angular/index.js +8 -0
  4. package/build/angular/services/battery-level.service/index.d.ts +5 -0
  5. package/build/angular/services/battery-level.service/index.js +74 -0
  6. package/build/angular/services/battery-state.service/index.d.ts +6 -0
  7. package/build/angular/services/battery-state.service/index.js +69 -0
  8. package/build/angular/services/low-power-mode.service/index.d.ts +5 -0
  9. package/build/angular/services/low-power-mode.service/index.js +69 -0
  10. package/build/core/battery.d.ts +44 -0
  11. package/build/core/battery.js +79 -0
  12. package/build/core/index.d.ts +3 -0
  13. package/build/core/index.js +2 -0
  14. package/build/core/native-module.d.ts +13 -0
  15. package/build/core/native-module.js +3 -0
  16. package/build/core/types.d.ts +40 -0
  17. package/build/core/types.js +23 -0
  18. package/build/react/hooks/use-battery-level/index.d.ts +1 -0
  19. package/build/react/hooks/use-battery-level/index.js +16 -0
  20. package/build/react/hooks/use-battery-state/index.d.ts +2 -0
  21. package/build/react/hooks/use-battery-state/index.js +14 -0
  22. package/build/react/hooks/use-low-power-mode/index.d.ts +1 -0
  23. package/build/react/hooks/use-low-power-mode/index.js +15 -0
  24. package/build/react/index.d.ts +4 -0
  25. package/build/react/index.js +9 -0
  26. package/build/svelte/index.d.ts +4 -0
  27. package/build/svelte/index.js +9 -0
  28. package/build/svelte/runes/use-battery-level.svelte.d.ts +3 -0
  29. package/build/svelte/runes/use-battery-level.svelte.js +37 -0
  30. package/build/svelte/runes/use-battery-state.svelte.d.ts +4 -0
  31. package/build/svelte/runes/use-battery-state.svelte.js +22 -0
  32. package/build/svelte/runes/use-low-power-mode.svelte.d.ts +3 -0
  33. package/build/svelte/runes/use-low-power-mode.svelte.js +22 -0
  34. package/build/vue/composables/use-battery-level/index.d.ts +2 -0
  35. package/build/vue/composables/use-battery-level/index.js +23 -0
  36. package/build/vue/composables/use-battery-state/index.d.ts +3 -0
  37. package/build/vue/composables/use-battery-state/index.js +21 -0
  38. package/build/vue/composables/use-low-power-mode/index.d.ts +2 -0
  39. package/build/vue/composables/use-low-power-mode/index.js +22 -0
  40. package/build/vue/index.d.ts +4 -0
  41. package/build/vue/index.js +9 -0
  42. package/build-ngc/angular/index.d.ts +4 -0
  43. package/build-ngc/angular/index.js +9 -0
  44. package/build-ngc/angular/index.js.map +1 -0
  45. package/build-ngc/angular/services/battery-level.service/index.d.ts +8 -0
  46. package/build-ngc/angular/services/battery-level.service/index.js +33 -0
  47. package/build-ngc/angular/services/battery-level.service/index.js.map +1 -0
  48. package/build-ngc/angular/services/battery-state.service/index.d.ts +9 -0
  49. package/build-ngc/angular/services/battery-state.service/index.js +28 -0
  50. package/build-ngc/angular/services/battery-state.service/index.js.map +1 -0
  51. package/build-ngc/angular/services/low-power-mode.service/index.d.ts +8 -0
  52. package/build-ngc/angular/services/low-power-mode.service/index.js +28 -0
  53. package/build-ngc/angular/services/low-power-mode.service/index.js.map +1 -0
  54. package/build-ngc/core/battery.d.ts +44 -0
  55. package/build-ngc/core/battery.js +80 -0
  56. package/build-ngc/core/battery.js.map +1 -0
  57. package/build-ngc/core/index.d.ts +3 -0
  58. package/build-ngc/core/index.js +3 -0
  59. package/build-ngc/core/index.js.map +1 -0
  60. package/build-ngc/core/native-module.d.ts +13 -0
  61. package/build-ngc/core/native-module.js +4 -0
  62. package/build-ngc/core/native-module.js.map +1 -0
  63. package/build-ngc/core/types.d.ts +40 -0
  64. package/build-ngc/core/types.js +24 -0
  65. package/build-ngc/core/types.js.map +1 -0
  66. package/native-link.json +12 -0
  67. package/package.json +106 -1
  68. package/src/angular/index.ts +8 -0
  69. package/src/angular/services/battery-level.service/index.ts +32 -0
  70. package/src/angular/services/battery-state.service/index.ts +27 -0
  71. package/src/angular/services/low-power-mode.service/index.ts +27 -0
  72. package/src/core/battery.ts +105 -0
  73. package/src/core/index.ts +19 -0
  74. package/src/core/native-module.ts +31 -0
  75. package/src/core/types.ts +47 -0
  76. package/src/react/hooks/use-battery-level/index.ts +19 -0
  77. package/src/react/hooks/use-battery-state/index.ts +17 -0
  78. package/src/react/hooks/use-low-power-mode/index.ts +18 -0
  79. package/src/react/index.ts +10 -0
  80. package/src/svelte/index.ts +10 -0
  81. package/src/svelte/runes/use-battery-level.svelte.ts +41 -0
  82. package/src/svelte/runes/use-battery-state.svelte.ts +30 -0
  83. package/src/svelte/runes/use-low-power-mode.svelte.ts +29 -0
  84. package/src/svelte/svelte-ambient.d.ts +6 -0
  85. package/src/vue/composables/use-battery-level/index.ts +32 -0
  86. package/src/vue/composables/use-battery-state/index.ts +31 -0
  87. package/src/vue/composables/use-low-power-mode/index.ts +31 -0
  88. package/src/vue/index.ts +10 -0
@@ -0,0 +1,40 @@
1
+ export type PowerState = {
2
+ /** A number between `0` and `1`, inclusive, or `-1` if the battery level is unknown. */
3
+ batteryLevel: number;
4
+ /** An enum value representing the battery state. */
5
+ batteryState: BatteryState;
6
+ /** `true` if lowPowerMode is on, `false` if lowPowerMode is off. */
7
+ lowPowerMode: boolean;
8
+ };
9
+ export declare enum BatteryState {
10
+ /** If the battery state is unknown or inaccessible. */
11
+ UNKNOWN = 0,
12
+ /**
13
+ * If the battery is discharging (typically not connected to power). On Android, this
14
+ * corresponds to `BATTERY_STATUS_DISCHARGING`.
15
+ */
16
+ UNPLUGGED = 1,
17
+ /** If battery is charging. */
18
+ CHARGING = 2,
19
+ /** If the battery level is full. */
20
+ FULL = 3,
21
+ /**
22
+ * The battery is not charging while power is connected (AC/USB/wireless), for example when
23
+ * battery protection limits charge to 80%, or optimized charging pauses. This differs from
24
+ * `UNPLUGGED` (discharging on battery).
25
+ * @platform android
26
+ */
27
+ NOT_CHARGING = 4
28
+ }
29
+ export type BatteryLevelEvent = {
30
+ /** A number between `0` and `1`, inclusive, or `-1` if the battery level is unknown. */
31
+ batteryLevel: number;
32
+ };
33
+ export type BatteryStateEvent = {
34
+ /** An enum value representing the battery state. */
35
+ batteryState: BatteryState;
36
+ };
37
+ export type PowerModeEvent = {
38
+ /** `true` if lowPowerMode is on, `false` if lowPowerMode is off. */
39
+ lowPowerMode: boolean;
40
+ };
@@ -0,0 +1,23 @@
1
+ // Hand-ported from .vendors/expo/packages/expo-battery/src/Battery.types.ts (sdk-57) — plain
2
+ // data shapes, no `expo` meta-package import to swap out (unlike local-auth's types.ts).
3
+ export var BatteryState;
4
+ (function (BatteryState) {
5
+ /** If the battery state is unknown or inaccessible. */
6
+ BatteryState[BatteryState["UNKNOWN"] = 0] = "UNKNOWN";
7
+ /**
8
+ * If the battery is discharging (typically not connected to power). On Android, this
9
+ * corresponds to `BATTERY_STATUS_DISCHARGING`.
10
+ */
11
+ BatteryState[BatteryState["UNPLUGGED"] = 1] = "UNPLUGGED";
12
+ /** If battery is charging. */
13
+ BatteryState[BatteryState["CHARGING"] = 2] = "CHARGING";
14
+ /** If the battery level is full. */
15
+ BatteryState[BatteryState["FULL"] = 3] = "FULL";
16
+ /**
17
+ * The battery is not charging while power is connected (AC/USB/wireless), for example when
18
+ * battery protection limits charge to 80%, or optimized charging pauses. This differs from
19
+ * `UNPLUGGED` (discharging on battery).
20
+ * @platform android
21
+ */
22
+ BatteryState[BatteryState["NOT_CHARGING"] = 4] = "NOT_CHARGING";
23
+ })(BatteryState || (BatteryState = {}));
@@ -0,0 +1 @@
1
+ export declare function useBatteryLevel(): number;
@@ -0,0 +1,16 @@
1
+ // React lifecycle wiring over the framework-agnostic core (core/battery.ts) — mirrors the
2
+ // lifecycle-bucket naming convention of adapters/react/src/hooks and the shape of
3
+ // packages/sensors/src/react/hooks/use-accelerometer. Seeds the initial value with a one-shot
4
+ // getBatteryLevelAsync() call before the first native event fires, matching upstream's own
5
+ // useBatteryLevel (.vendors/expo/packages/expo-battery/src/Battery.ts).
6
+ import { useEffect, useState } from 'react';
7
+ import { addBatteryLevelListener, getBatteryLevelAsync } from '../../../core/index.js';
8
+ export function useBatteryLevel() {
9
+ const [batteryLevel, setBatteryLevel] = useState(-1);
10
+ useEffect(() => {
11
+ getBatteryLevelAsync().then(setBatteryLevel);
12
+ const subscription = addBatteryLevelListener(event => setBatteryLevel(event.batteryLevel));
13
+ return () => subscription.remove();
14
+ }, []);
15
+ return batteryLevel;
16
+ }
@@ -0,0 +1,2 @@
1
+ import { BatteryState } from '../../../core';
2
+ export declare function useBatteryState(): BatteryState;
@@ -0,0 +1,14 @@
1
+ // React lifecycle wiring over the framework-agnostic core (core/battery.ts) — mirrors
2
+ // use-battery-level's shape. Seeds the initial value with a one-shot getBatteryStateAsync()
3
+ // call before the first native event fires, matching upstream's own useBatteryState.
4
+ import { useEffect, useState } from 'react';
5
+ import { addBatteryStateListener, BatteryState, getBatteryStateAsync } from '../../../core/index.js';
6
+ export function useBatteryState() {
7
+ const [batteryState, setBatteryState] = useState(BatteryState.UNKNOWN);
8
+ useEffect(() => {
9
+ getBatteryStateAsync().then(setBatteryState);
10
+ const subscription = addBatteryStateListener(event => setBatteryState(event.batteryState));
11
+ return () => subscription.remove();
12
+ }, []);
13
+ return batteryState;
14
+ }
@@ -0,0 +1 @@
1
+ export declare function useLowPowerMode(): boolean;
@@ -0,0 +1,15 @@
1
+ // React lifecycle wiring over the framework-agnostic core (core/battery.ts) — mirrors
2
+ // use-battery-level's shape. Seeds the initial value with a one-shot
3
+ // isLowPowerModeEnabledAsync() call before the first native event fires, matching upstream's
4
+ // own useLowPowerMode.
5
+ import { useEffect, useState } from 'react';
6
+ import { addLowPowerModeListener, isLowPowerModeEnabledAsync } from '../../../core/index.js';
7
+ export function useLowPowerMode() {
8
+ const [lowPowerMode, setLowPowerMode] = useState(false);
9
+ useEffect(() => {
10
+ isLowPowerModeEnabledAsync().then(setLowPowerMode);
11
+ const subscription = addLowPowerModeListener(event => setLowPowerMode(event.lowPowerMode));
12
+ return () => subscription.remove();
13
+ }, []);
14
+ return lowPowerMode;
15
+ }
@@ -0,0 +1,4 @@
1
+ export { useBatteryLevel } from './hooks/use-battery-level';
2
+ export { useBatteryState } from './hooks/use-battery-state';
3
+ export { useLowPowerMode } from './hooks/use-low-power-mode';
4
+ export * from '../core';
@@ -0,0 +1,9 @@
1
+ // @symbiote-native/battery/react: the React entry over the framework-agnostic core. Battery's
2
+ // three subscription-backed values (level/state/low-power-mode) each get their own lifecycle
3
+ // hook, matching upstream's own useBatteryLevel/useBatteryState/useLowPowerMode being three
4
+ // separate hooks, not one combined hook — mirrors the lifecycle-bucket naming convention of
5
+ // adapters/react/src/hooks (never `composables`, that's Vue's term).
6
+ export { useBatteryLevel } from './hooks/use-battery-level/index.js';
7
+ export { useBatteryState } from './hooks/use-battery-state/index.js';
8
+ export { useLowPowerMode } from './hooks/use-low-power-mode/index.js';
9
+ export * from '../core/index.js';
@@ -0,0 +1,4 @@
1
+ export { useBatteryLevel } from './runes/use-battery-level.svelte';
2
+ export { useBatteryState } from './runes/use-battery-state.svelte';
3
+ export { useLowPowerMode } from './runes/use-low-power-mode.svelte';
4
+ export * from '../core';
@@ -0,0 +1,9 @@
1
+ // @symbiote-native/battery/svelte: the Svelte entry over the framework-agnostic core. Battery's
2
+ // three subscription-backed values (level/state/low-power-mode) each get their own lifecycle
3
+ // rune, matching upstream's own useBatteryLevel/useBatteryState/useLowPowerMode being three
4
+ // separate hooks, not one combined hook — mirrors the lifecycle-bucket naming convention of
5
+ // adapters/svelte/src/runes (never `hooks/`/`composables/`, those are React's and Vue's terms).
6
+ export { useBatteryLevel } from './runes/use-battery-level.svelte';
7
+ export { useBatteryState } from './runes/use-battery-state.svelte';
8
+ export { useLowPowerMode } from './runes/use-low-power-mode.svelte';
9
+ export * from '../core/index.js';
@@ -0,0 +1,3 @@
1
+ export declare function useBatteryLevel(): {
2
+ readonly current: number;
3
+ };
@@ -0,0 +1,37 @@
1
+ // Svelte lifecycle wiring over the framework-agnostic core (core/battery.ts) — the Svelte twin of
2
+ // vue/composables/use-battery-level and react/hooks/use-battery-level. Seeds the initial value
3
+ // with a one-shot getBatteryLevelAsync() call before the first native event fires, matching
4
+ // upstream's own useBatteryLevel.
5
+ //
6
+ // `.svelte.ts` (not `.ts`): runes ($state/$effect) are only usable in a file with this extension
7
+ // outside an actual `.svelte` component. `runes/` is Svelte's own term for the bucket React calls
8
+ // `hooks/` and Vue calls `composables/` — see adapters/svelte/src/runes.
9
+ //
10
+ // Vue's onMounted/onUnmounted pair collapses into ONE `$effect` whose returned function is the
11
+ // teardown. The effect only WRITES `batteryLevel`, never reads it, so its dependency set stays
12
+ // empty: it runs exactly once on mount and cleans up exactly once on unmount.
13
+ //
14
+ // Returns a boxed getter object, NOT a bare `$state`: Svelte 5 reactivity is lexically scoped to
15
+ // the declaring module, so a raw `let x = $state(...)` handed out of a plain function arrives
16
+ // dead at the caller. `{ get current() { … } }` is the sanctioned way across, read as `.current`
17
+ // exactly like Vue's `Ref` is unwrapped via `.value`.
18
+ import { addBatteryLevelListener, getBatteryLevelAsync } from '../../core/index.js';
19
+ // core/battery.ts's documented sentinel for "this device cannot report a battery level".
20
+ const UNKNOWN_BATTERY_LEVEL = -1;
21
+ export function useBatteryLevel() {
22
+ let batteryLevel = $state(UNKNOWN_BATTERY_LEVEL);
23
+ $effect(() => {
24
+ getBatteryLevelAsync().then(level => {
25
+ batteryLevel = level;
26
+ });
27
+ const subscription = addBatteryLevelListener(event => {
28
+ batteryLevel = event.batteryLevel;
29
+ });
30
+ return () => subscription.remove();
31
+ });
32
+ return {
33
+ get current() {
34
+ return batteryLevel;
35
+ },
36
+ };
37
+ }
@@ -0,0 +1,4 @@
1
+ import { BatteryState } from '../../core';
2
+ export declare function useBatteryState(): {
3
+ readonly current: BatteryState;
4
+ };
@@ -0,0 +1,22 @@
1
+ // Svelte lifecycle wiring over the framework-agnostic core (core/battery.ts) — mirrors
2
+ // use-battery-level.svelte.ts's shape; see its header for the `.svelte.ts`/`runes/`/boxed-getter
3
+ // reasoning. Seeds the initial value with a one-shot getBatteryStateAsync() call before the first
4
+ // native event fires, matching upstream's own useBatteryState.
5
+ import { addBatteryStateListener, BatteryState, getBatteryStateAsync, } from '../../core/index.js';
6
+ export function useBatteryState() {
7
+ let batteryState = $state(BatteryState.UNKNOWN);
8
+ $effect(() => {
9
+ getBatteryStateAsync().then(state => {
10
+ batteryState = state;
11
+ });
12
+ const subscription = addBatteryStateListener(event => {
13
+ batteryState = event.batteryState;
14
+ });
15
+ return () => subscription.remove();
16
+ });
17
+ return {
18
+ get current() {
19
+ return batteryState;
20
+ },
21
+ };
22
+ }
@@ -0,0 +1,3 @@
1
+ export declare function useLowPowerMode(): {
2
+ readonly current: boolean;
3
+ };
@@ -0,0 +1,22 @@
1
+ // Svelte lifecycle wiring over the framework-agnostic core (core/battery.ts) — mirrors
2
+ // use-battery-level.svelte.ts's shape; see its header for the `.svelte.ts`/`runes/`/boxed-getter
3
+ // reasoning. Seeds the initial value with a one-shot isLowPowerModeEnabledAsync() call before the
4
+ // first native event fires, matching upstream's own useLowPowerMode.
5
+ import { addLowPowerModeListener, isLowPowerModeEnabledAsync, } from '../../core/index.js';
6
+ export function useLowPowerMode() {
7
+ let lowPowerMode = $state(false);
8
+ $effect(() => {
9
+ isLowPowerModeEnabledAsync().then(enabled => {
10
+ lowPowerMode = enabled;
11
+ });
12
+ const subscription = addLowPowerModeListener(event => {
13
+ lowPowerMode = event.lowPowerMode;
14
+ });
15
+ return () => subscription.remove();
16
+ });
17
+ return {
18
+ get current() {
19
+ return lowPowerMode;
20
+ },
21
+ };
22
+ }
@@ -0,0 +1,2 @@
1
+ import { type Ref } from '@vue/runtime-core';
2
+ export declare function useBatteryLevel(): Ref<number>;
@@ -0,0 +1,23 @@
1
+ // Vue lifecycle wiring over the framework-agnostic core (core/battery.ts) — mirrors the
2
+ // lifecycle-bucket naming convention of adapters/vue/src/composables and the
3
+ // onMounted/onUnmounted shape of packages/sensors/src/vue/composables/use-accelerometer. Seeds
4
+ // the initial value with a one-shot getBatteryLevelAsync() call before the first native event
5
+ // fires, matching upstream's own useBatteryLevel.
6
+ import { onMounted, onUnmounted, ref } from '@vue/runtime-core';
7
+ import { addBatteryLevelListener, getBatteryLevelAsync, } from '../../../core/index.js';
8
+ export function useBatteryLevel() {
9
+ const batteryLevel = ref(-1);
10
+ let subscription;
11
+ onMounted(() => {
12
+ getBatteryLevelAsync().then(level => {
13
+ batteryLevel.value = level;
14
+ });
15
+ subscription = addBatteryLevelListener(event => {
16
+ batteryLevel.value = event.batteryLevel;
17
+ });
18
+ });
19
+ onUnmounted(() => {
20
+ subscription?.remove();
21
+ });
22
+ return batteryLevel;
23
+ }
@@ -0,0 +1,3 @@
1
+ import { type Ref } from '@vue/runtime-core';
2
+ import { BatteryState } from '../../../core';
3
+ export declare function useBatteryState(): Ref<BatteryState>;
@@ -0,0 +1,21 @@
1
+ // Vue lifecycle wiring over the framework-agnostic core (core/battery.ts) — mirrors
2
+ // use-battery-level's shape. Seeds the initial value with a one-shot getBatteryStateAsync()
3
+ // call before the first native event fires, matching upstream's own useBatteryState.
4
+ import { onMounted, onUnmounted, ref } from '@vue/runtime-core';
5
+ import { addBatteryStateListener, BatteryState, getBatteryStateAsync, } from '../../../core/index.js';
6
+ export function useBatteryState() {
7
+ const batteryState = ref(BatteryState.UNKNOWN);
8
+ let subscription;
9
+ onMounted(() => {
10
+ getBatteryStateAsync().then(state => {
11
+ batteryState.value = state;
12
+ });
13
+ subscription = addBatteryStateListener(event => {
14
+ batteryState.value = event.batteryState;
15
+ });
16
+ });
17
+ onUnmounted(() => {
18
+ subscription?.remove();
19
+ });
20
+ return batteryState;
21
+ }
@@ -0,0 +1,2 @@
1
+ import { type Ref } from '@vue/runtime-core';
2
+ export declare function useLowPowerMode(): Ref<boolean>;
@@ -0,0 +1,22 @@
1
+ // Vue lifecycle wiring over the framework-agnostic core (core/battery.ts) — mirrors
2
+ // use-battery-level's shape. Seeds the initial value with a one-shot
3
+ // isLowPowerModeEnabledAsync() call before the first native event fires, matching upstream's
4
+ // own useLowPowerMode.
5
+ import { onMounted, onUnmounted, ref } from '@vue/runtime-core';
6
+ import { addLowPowerModeListener, isLowPowerModeEnabledAsync, } from '../../../core/index.js';
7
+ export function useLowPowerMode() {
8
+ const lowPowerMode = ref(false);
9
+ let subscription;
10
+ onMounted(() => {
11
+ isLowPowerModeEnabledAsync().then(enabled => {
12
+ lowPowerMode.value = enabled;
13
+ });
14
+ subscription = addLowPowerModeListener(event => {
15
+ lowPowerMode.value = event.lowPowerMode;
16
+ });
17
+ });
18
+ onUnmounted(() => {
19
+ subscription?.remove();
20
+ });
21
+ return lowPowerMode;
22
+ }
@@ -0,0 +1,4 @@
1
+ export { useBatteryLevel } from './composables/use-battery-level';
2
+ export { useBatteryState } from './composables/use-battery-state';
3
+ export { useLowPowerMode } from './composables/use-low-power-mode';
4
+ export * from '../core';
@@ -0,0 +1,9 @@
1
+ // @symbiote-native/battery/vue: the Vue entry over the framework-agnostic core. Battery's three
2
+ // subscription-backed values (level/state/low-power-mode) each get their own lifecycle
3
+ // composable, matching upstream's own useBatteryLevel/useBatteryState/useLowPowerMode being
4
+ // three separate hooks, not one combined hook — mirrors the lifecycle-bucket naming convention
5
+ // of adapters/vue/src/composables (never `hooks/`, that's React's term).
6
+ export { useBatteryLevel } from './composables/use-battery-level/index.js';
7
+ export { useBatteryState } from './composables/use-battery-state/index.js';
8
+ export { useLowPowerMode } from './composables/use-low-power-mode/index.js';
9
+ export * from '../core/index.js';
@@ -0,0 +1,4 @@
1
+ export { BatteryLevelService } from './services/battery-level.service';
2
+ export { BatteryStateService } from './services/battery-state.service';
3
+ export { LowPowerModeService } from './services/low-power-mode.service';
4
+ export * from '../core';
@@ -0,0 +1,9 @@
1
+ // BatteryLevelService/BatteryStateService/LowPowerModeService are the Angular-only lifecycle
2
+ // half; the free functions and event subscription plumbing all live in core, shared with
3
+ // React/Vue. Three separate services (not one combined service), matching upstream's own
4
+ // useBatteryLevel/useBatteryState/useLowPowerMode being three separate hooks.
5
+ export { BatteryLevelService } from './services/battery-level.service';
6
+ export { BatteryStateService } from './services/battery-state.service';
7
+ export { LowPowerModeService } from './services/low-power-mode.service';
8
+ export * from '../core';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/angular/index.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,yFAAyF;AACzF,yFAAyF;AACzF,8EAA8E;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,cAAc,SAAS,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { type Signal } from '@angular/core';
2
+ import * as i0 from "@angular/core";
3
+ export declare class BatteryLevelService {
4
+ private readonly injector;
5
+ connect(): Signal<number>;
6
+ static ɵfac: i0.ɵɵFactoryDeclaration<BatteryLevelService, never>;
7
+ static ɵprov: i0.ɵɵInjectableDeclaration<BatteryLevelService>;
8
+ }
@@ -0,0 +1,33 @@
1
+ import { effect, inject, Injectable, Injector, signal } from '@angular/core';
2
+ import { addBatteryLevelListener, getBatteryLevelAsync } from '../../../core';
3
+ import * as i0 from "@angular/core";
4
+ // Angular twin of React's `useBatteryLevel` hook and Vue's `useBatteryLevel` composable.
5
+ // Angular has no per-instance hook — state and lifecycle live in DI instead, so `connect()`
6
+ // stands in for the hook's role: call it ONCE (typically from a component's field initializer,
7
+ // inside an injection context).
8
+ //
9
+ // readonly batteryLevel = inject(BatteryLevelService).connect();
10
+ // // template: {{ batteryLevel() }}
11
+ //
12
+ // Mirrors AccelerometerService.connect() — a single effect() that seeds the initial value with
13
+ // getBatteryLevelAsync(), subscribes once, and cleans up once.
14
+ export class BatteryLevelService {
15
+ injector = inject(Injector);
16
+ connect() {
17
+ const batteryLevel = signal(-1, /* @ts-ignore */
18
+ ...(ngDevMode ? [{ debugName: "batteryLevel" }] : /* istanbul ignore next */ []));
19
+ effect(onCleanup => {
20
+ getBatteryLevelAsync().then(level => batteryLevel.set(level));
21
+ const subscription = addBatteryLevelListener(event => batteryLevel.set(event.batteryLevel));
22
+ onCleanup(() => subscription.remove());
23
+ }, { injector: this.injector });
24
+ return batteryLevel.asReadonly();
25
+ }
26
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: BatteryLevelService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
27
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: BatteryLevelService, providedIn: 'root' });
28
+ }
29
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: BatteryLevelService, decorators: [{
30
+ type: Injectable,
31
+ args: [{ providedIn: 'root' }]
32
+ }] });
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/angular/services/battery-level.service/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAe,MAAM,eAAe,CAAC;AAC1F,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;;AAE9E,yFAAyF;AACzF,4FAA4F;AAC5F,+FAA+F;AAC/F,gCAAgC;AAChC,EAAE;AACF,mEAAmE;AACnE,sCAAsC;AACtC,EAAE;AACF,+FAA+F;AAC/F,+DAA+D;AAE/D,MAAM,OAAO,mBAAmB;IACb,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAE7C,OAAO;QACL,MAAM,YAAY,GAAG,MAAM,CAAC,CAAC,CAAC;yFAAC,CAAC;QAEhC,MAAM,CACJ,SAAS,CAAC,EAAE;YACV,oBAAoB,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;YAC9D,MAAM,YAAY,GAAG,uBAAuB,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;YAC5F,SAAS,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;QACzC,CAAC,EACD,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAC5B,CAAC;QAEF,OAAO,YAAY,CAAC,UAAU,EAAE,CAAC;IACnC,CAAC;uGAhBU,mBAAmB;2GAAnB,mBAAmB,cADN,MAAM;;2FACnB,mBAAmB;kBAD/B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE"}
@@ -0,0 +1,9 @@
1
+ import { type Signal } from '@angular/core';
2
+ import { BatteryState } from '../../../core';
3
+ import * as i0 from "@angular/core";
4
+ export declare class BatteryStateService {
5
+ private readonly injector;
6
+ connect(): Signal<BatteryState>;
7
+ static ɵfac: i0.ɵɵFactoryDeclaration<BatteryStateService, never>;
8
+ static ɵprov: i0.ɵɵInjectableDeclaration<BatteryStateService>;
9
+ }
@@ -0,0 +1,28 @@
1
+ import { effect, inject, Injectable, Injector, signal } from '@angular/core';
2
+ import { addBatteryStateListener, BatteryState, getBatteryStateAsync } from '../../../core';
3
+ import * as i0 from "@angular/core";
4
+ // Angular twin of React's `useBatteryState` hook and Vue's `useBatteryState` composable. See
5
+ // BatteryLevelService for the `connect()` pattern rationale.
6
+ //
7
+ // readonly batteryState = inject(BatteryStateService).connect();
8
+ // // template: {{ batteryState() }}
9
+ export class BatteryStateService {
10
+ injector = inject(Injector);
11
+ connect() {
12
+ const batteryState = signal(BatteryState.UNKNOWN, /* @ts-ignore */
13
+ ...(ngDevMode ? [{ debugName: "batteryState" }] : /* istanbul ignore next */ []));
14
+ effect(onCleanup => {
15
+ getBatteryStateAsync().then(state => batteryState.set(state));
16
+ const subscription = addBatteryStateListener(event => batteryState.set(event.batteryState));
17
+ onCleanup(() => subscription.remove());
18
+ }, { injector: this.injector });
19
+ return batteryState.asReadonly();
20
+ }
21
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: BatteryStateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
22
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: BatteryStateService, providedIn: 'root' });
23
+ }
24
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: BatteryStateService, decorators: [{
25
+ type: Injectable,
26
+ args: [{ providedIn: 'root' }]
27
+ }] });
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/angular/services/battery-state.service/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAe,MAAM,eAAe,CAAC;AAC1F,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;;AAE5F,6FAA6F;AAC7F,6DAA6D;AAC7D,EAAE;AACF,mEAAmE;AACnE,sCAAsC;AAEtC,MAAM,OAAO,mBAAmB;IACb,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAE7C,OAAO;QACL,MAAM,YAAY,GAAG,MAAM,CAAe,YAAY,CAAC,OAAO;yFAAC,CAAC;QAEhE,MAAM,CACJ,SAAS,CAAC,EAAE;YACV,oBAAoB,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;YAC9D,MAAM,YAAY,GAAG,uBAAuB,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;YAC5F,SAAS,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;QACzC,CAAC,EACD,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAC5B,CAAC;QAEF,OAAO,YAAY,CAAC,UAAU,EAAE,CAAC;IACnC,CAAC;uGAhBU,mBAAmB;2GAAnB,mBAAmB,cADN,MAAM;;2FACnB,mBAAmB;kBAD/B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE"}
@@ -0,0 +1,8 @@
1
+ import { type Signal } from '@angular/core';
2
+ import * as i0 from "@angular/core";
3
+ export declare class LowPowerModeService {
4
+ private readonly injector;
5
+ connect(): Signal<boolean>;
6
+ static ɵfac: i0.ɵɵFactoryDeclaration<LowPowerModeService, never>;
7
+ static ɵprov: i0.ɵɵInjectableDeclaration<LowPowerModeService>;
8
+ }
@@ -0,0 +1,28 @@
1
+ import { effect, inject, Injectable, Injector, signal } from '@angular/core';
2
+ import { addLowPowerModeListener, isLowPowerModeEnabledAsync } from '../../../core';
3
+ import * as i0 from "@angular/core";
4
+ // Angular twin of React's `useLowPowerMode` hook and Vue's `useLowPowerMode` composable. See
5
+ // BatteryLevelService for the `connect()` pattern rationale.
6
+ //
7
+ // readonly lowPowerMode = inject(LowPowerModeService).connect();
8
+ // // template: {{ lowPowerMode() }}
9
+ export class LowPowerModeService {
10
+ injector = inject(Injector);
11
+ connect() {
12
+ const lowPowerMode = signal(false, /* @ts-ignore */
13
+ ...(ngDevMode ? [{ debugName: "lowPowerMode" }] : /* istanbul ignore next */ []));
14
+ effect(onCleanup => {
15
+ isLowPowerModeEnabledAsync().then(enabled => lowPowerMode.set(enabled));
16
+ const subscription = addLowPowerModeListener(event => lowPowerMode.set(event.lowPowerMode));
17
+ onCleanup(() => subscription.remove());
18
+ }, { injector: this.injector });
19
+ return lowPowerMode.asReadonly();
20
+ }
21
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: LowPowerModeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
22
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: LowPowerModeService, providedIn: 'root' });
23
+ }
24
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.8", ngImport: i0, type: LowPowerModeService, decorators: [{
25
+ type: Injectable,
26
+ args: [{ providedIn: 'root' }]
27
+ }] });
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/angular/services/low-power-mode.service/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAe,MAAM,eAAe,CAAC;AAC1F,OAAO,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;;AAEpF,6FAA6F;AAC7F,6DAA6D;AAC7D,EAAE;AACF,mEAAmE;AACnE,sCAAsC;AAEtC,MAAM,OAAO,mBAAmB;IACb,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAE7C,OAAO;QACL,MAAM,YAAY,GAAG,MAAM,CAAC,KAAK;yFAAC,CAAC;QAEnC,MAAM,CACJ,SAAS,CAAC,EAAE;YACV,0BAA0B,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;YACxE,MAAM,YAAY,GAAG,uBAAuB,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;YAC5F,SAAS,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;QACzC,CAAC,EACD,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAC5B,CAAC;QAEF,OAAO,YAAY,CAAC,UAAU,EAAE,CAAC;IACnC,CAAC;uGAhBU,mBAAmB;2GAAnB,mBAAmB,cADN,MAAM;;2FACnB,mBAAmB;kBAD/B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE"}
@@ -0,0 +1,44 @@
1
+ import type { EventSubscription } from 'expo-modules-core';
2
+ import { BatteryState, type BatteryLevelEvent, type BatteryStateEvent, type PowerModeEvent, type PowerState } from './types';
3
+ /**
4
+ * Resolves with whether the battery API is available on the current device. `true` on Android
5
+ * and physical iOS devices, `false` on iOS simulators.
6
+ */
7
+ export declare function isAvailableAsync(): Promise<boolean>;
8
+ /**
9
+ * Gets the battery level of the device as a number between `0` and `1`, inclusive. If the
10
+ * device does not support retrieving the battery level, this method returns `-1`.
11
+ */
12
+ export declare function getBatteryLevelAsync(): Promise<number>;
13
+ /** Tells the battery's current state. */
14
+ export declare function getBatteryStateAsync(): Promise<BatteryState>;
15
+ /**
16
+ * Gets the current status of Power Saver mode on Android and Low Power mode on iOS. If a
17
+ * platform doesn't support low-power-mode reporting, this always resolves `false`, even if the
18
+ * device is actually in low-power mode.
19
+ */
20
+ export declare function isLowPowerModeEnabledAsync(): Promise<boolean>;
21
+ /**
22
+ * Checks whether battery optimization is enabled for this app. If enabled, background tasks
23
+ * might be affected when the app goes into doze mode state.
24
+ * @platform android
25
+ */
26
+ export declare function isBatteryOptimizationEnabledAsync(): Promise<boolean>;
27
+ /**
28
+ * Gets the power state of the device: battery level, whether it is plugged in, and whether the
29
+ * system is currently in Power Saver Mode (Android) / Low Power Mode (iOS).
30
+ */
31
+ export declare function getPowerStateAsync(): Promise<PowerState>;
32
+ /**
33
+ * Subscribe to battery level change updates. On Android this only fires on significant changes
34
+ * (crossing the low/okay battery thresholds); on iOS it fires per one-percent drop, at most once
35
+ * a minute.
36
+ */
37
+ export declare function addBatteryLevelListener(listener: (event: BatteryLevelEvent) => void): EventSubscription;
38
+ /** Subscribe to battery state (charging/full/unplugged/unknown) change updates. */
39
+ export declare function addBatteryStateListener(listener: (event: BatteryStateEvent) => void): EventSubscription;
40
+ /**
41
+ * Subscribe to Power Saver Mode (Android) / Low Power Mode (iOS) updates. Fires whenever the
42
+ * power mode is toggled.
43
+ */
44
+ export declare function addLowPowerModeListener(listener: (event: PowerModeEvent) => void): EventSubscription;