@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.
- package/README.md +172 -27
- package/build/angular/index.d.ts +4 -0
- package/build/angular/index.js +8 -0
- package/build/angular/services/battery-level.service/index.d.ts +5 -0
- package/build/angular/services/battery-level.service/index.js +74 -0
- package/build/angular/services/battery-state.service/index.d.ts +6 -0
- package/build/angular/services/battery-state.service/index.js +69 -0
- package/build/angular/services/low-power-mode.service/index.d.ts +5 -0
- package/build/angular/services/low-power-mode.service/index.js +69 -0
- package/build/core/battery.d.ts +44 -0
- package/build/core/battery.js +79 -0
- package/build/core/index.d.ts +3 -0
- package/build/core/index.js +2 -0
- package/build/core/native-module.d.ts +13 -0
- package/build/core/native-module.js +3 -0
- package/build/core/types.d.ts +40 -0
- package/build/core/types.js +23 -0
- package/build/react/hooks/use-battery-level/index.d.ts +1 -0
- package/build/react/hooks/use-battery-level/index.js +16 -0
- package/build/react/hooks/use-battery-state/index.d.ts +2 -0
- package/build/react/hooks/use-battery-state/index.js +14 -0
- package/build/react/hooks/use-low-power-mode/index.d.ts +1 -0
- package/build/react/hooks/use-low-power-mode/index.js +15 -0
- package/build/react/index.d.ts +4 -0
- package/build/react/index.js +9 -0
- package/build/svelte/index.d.ts +4 -0
- package/build/svelte/index.js +9 -0
- package/build/svelte/runes/use-battery-level.svelte.d.ts +3 -0
- package/build/svelte/runes/use-battery-level.svelte.js +37 -0
- package/build/svelte/runes/use-battery-state.svelte.d.ts +4 -0
- package/build/svelte/runes/use-battery-state.svelte.js +22 -0
- package/build/svelte/runes/use-low-power-mode.svelte.d.ts +3 -0
- package/build/svelte/runes/use-low-power-mode.svelte.js +22 -0
- package/build/vue/composables/use-battery-level/index.d.ts +2 -0
- package/build/vue/composables/use-battery-level/index.js +23 -0
- package/build/vue/composables/use-battery-state/index.d.ts +3 -0
- package/build/vue/composables/use-battery-state/index.js +21 -0
- package/build/vue/composables/use-low-power-mode/index.d.ts +2 -0
- package/build/vue/composables/use-low-power-mode/index.js +22 -0
- package/build/vue/index.d.ts +4 -0
- package/build/vue/index.js +9 -0
- package/build-ngc/angular/index.d.ts +4 -0
- package/build-ngc/angular/index.js +9 -0
- package/build-ngc/angular/index.js.map +1 -0
- package/build-ngc/angular/services/battery-level.service/index.d.ts +8 -0
- package/build-ngc/angular/services/battery-level.service/index.js +33 -0
- package/build-ngc/angular/services/battery-level.service/index.js.map +1 -0
- package/build-ngc/angular/services/battery-state.service/index.d.ts +9 -0
- package/build-ngc/angular/services/battery-state.service/index.js +28 -0
- package/build-ngc/angular/services/battery-state.service/index.js.map +1 -0
- package/build-ngc/angular/services/low-power-mode.service/index.d.ts +8 -0
- package/build-ngc/angular/services/low-power-mode.service/index.js +28 -0
- package/build-ngc/angular/services/low-power-mode.service/index.js.map +1 -0
- package/build-ngc/core/battery.d.ts +44 -0
- package/build-ngc/core/battery.js +80 -0
- package/build-ngc/core/battery.js.map +1 -0
- package/build-ngc/core/index.d.ts +3 -0
- package/build-ngc/core/index.js +3 -0
- package/build-ngc/core/index.js.map +1 -0
- package/build-ngc/core/native-module.d.ts +13 -0
- package/build-ngc/core/native-module.js +4 -0
- package/build-ngc/core/native-module.js.map +1 -0
- package/build-ngc/core/types.d.ts +40 -0
- package/build-ngc/core/types.js +24 -0
- package/build-ngc/core/types.js.map +1 -0
- package/native-link.json +12 -0
- package/package.json +106 -1
- package/src/angular/index.ts +8 -0
- package/src/angular/services/battery-level.service/index.ts +32 -0
- package/src/angular/services/battery-state.service/index.ts +27 -0
- package/src/angular/services/low-power-mode.service/index.ts +27 -0
- package/src/core/battery.ts +105 -0
- package/src/core/index.ts +19 -0
- package/src/core/native-module.ts +31 -0
- package/src/core/types.ts +47 -0
- package/src/react/hooks/use-battery-level/index.ts +19 -0
- package/src/react/hooks/use-battery-state/index.ts +17 -0
- package/src/react/hooks/use-low-power-mode/index.ts +18 -0
- package/src/react/index.ts +10 -0
- package/src/svelte/index.ts +10 -0
- package/src/svelte/runes/use-battery-level.svelte.ts +41 -0
- package/src/svelte/runes/use-battery-state.svelte.ts +30 -0
- package/src/svelte/runes/use-low-power-mode.svelte.ts +29 -0
- package/src/svelte/svelte-ambient.d.ts +6 -0
- package/src/vue/composables/use-battery-level/index.ts +32 -0
- package/src/vue/composables/use-battery-state/index.ts +31 -0
- package/src/vue/composables/use-low-power-mode/index.ts +31 -0
- package/src/vue/index.ts +10 -0
|
@@ -0,0 +1,17 @@
|
|
|
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';
|
|
6
|
+
|
|
7
|
+
export function useBatteryState(): BatteryState {
|
|
8
|
+
const [batteryState, setBatteryState] = useState<BatteryState>(BatteryState.UNKNOWN);
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
getBatteryStateAsync().then(setBatteryState);
|
|
12
|
+
const subscription = addBatteryStateListener(event => setBatteryState(event.batteryState));
|
|
13
|
+
return () => subscription.remove();
|
|
14
|
+
}, []);
|
|
15
|
+
|
|
16
|
+
return batteryState;
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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';
|
|
7
|
+
|
|
8
|
+
export function useLowPowerMode(): boolean {
|
|
9
|
+
const [lowPowerMode, setLowPowerMode] = useState(false);
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
isLowPowerModeEnabledAsync().then(setLowPowerMode);
|
|
13
|
+
const subscription = addLowPowerModeListener(event => setLowPowerMode(event.lowPowerMode));
|
|
14
|
+
return () => subscription.remove();
|
|
15
|
+
}, []);
|
|
16
|
+
|
|
17
|
+
return lowPowerMode;
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
|
|
7
|
+
export { useBatteryLevel } from './hooks/use-battery-level';
|
|
8
|
+
export { useBatteryState } from './hooks/use-battery-state';
|
|
9
|
+
export { useLowPowerMode } from './hooks/use-low-power-mode';
|
|
10
|
+
export * from '../core';
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
|
|
7
|
+
export { useBatteryLevel } from './runes/use-battery-level.svelte';
|
|
8
|
+
export { useBatteryState } from './runes/use-battery-state.svelte';
|
|
9
|
+
export { useLowPowerMode } from './runes/use-low-power-mode.svelte';
|
|
10
|
+
export * from '../core';
|
|
@@ -0,0 +1,41 @@
|
|
|
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, type EventSubscription } from '../../core';
|
|
19
|
+
|
|
20
|
+
// core/battery.ts's documented sentinel for "this device cannot report a battery level".
|
|
21
|
+
const UNKNOWN_BATTERY_LEVEL = -1;
|
|
22
|
+
|
|
23
|
+
export function useBatteryLevel(): { readonly current: number } {
|
|
24
|
+
let batteryLevel = $state(UNKNOWN_BATTERY_LEVEL);
|
|
25
|
+
|
|
26
|
+
$effect(() => {
|
|
27
|
+
getBatteryLevelAsync().then(level => {
|
|
28
|
+
batteryLevel = level;
|
|
29
|
+
});
|
|
30
|
+
const subscription: EventSubscription = addBatteryLevelListener(event => {
|
|
31
|
+
batteryLevel = event.batteryLevel;
|
|
32
|
+
});
|
|
33
|
+
return () => subscription.remove();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
get current(): number {
|
|
38
|
+
return batteryLevel;
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 {
|
|
6
|
+
addBatteryStateListener,
|
|
7
|
+
BatteryState,
|
|
8
|
+
getBatteryStateAsync,
|
|
9
|
+
type EventSubscription,
|
|
10
|
+
} from '../../core';
|
|
11
|
+
|
|
12
|
+
export function useBatteryState(): { readonly current: BatteryState } {
|
|
13
|
+
let batteryState = $state<BatteryState>(BatteryState.UNKNOWN);
|
|
14
|
+
|
|
15
|
+
$effect(() => {
|
|
16
|
+
getBatteryStateAsync().then(state => {
|
|
17
|
+
batteryState = state;
|
|
18
|
+
});
|
|
19
|
+
const subscription: EventSubscription = addBatteryStateListener(event => {
|
|
20
|
+
batteryState = event.batteryState;
|
|
21
|
+
});
|
|
22
|
+
return () => subscription.remove();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
get current(): BatteryState {
|
|
27
|
+
return batteryState;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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 {
|
|
6
|
+
addLowPowerModeListener,
|
|
7
|
+
isLowPowerModeEnabledAsync,
|
|
8
|
+
type EventSubscription,
|
|
9
|
+
} from '../../core';
|
|
10
|
+
|
|
11
|
+
export function useLowPowerMode(): { readonly current: boolean } {
|
|
12
|
+
let lowPowerMode = $state(false);
|
|
13
|
+
|
|
14
|
+
$effect(() => {
|
|
15
|
+
isLowPowerModeEnabledAsync().then(enabled => {
|
|
16
|
+
lowPowerMode = enabled;
|
|
17
|
+
});
|
|
18
|
+
const subscription: EventSubscription = addLowPowerModeListener(event => {
|
|
19
|
+
lowPowerMode = event.lowPowerMode;
|
|
20
|
+
});
|
|
21
|
+
return () => subscription.remove();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
get current(): boolean {
|
|
26
|
+
return lowPowerMode;
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Pulls in svelte's ambient global declarations ($state/$effect/...) for this package's tsc
|
|
2
|
+
// program. adapters/svelte gets these for free because render.ts does a real value import from
|
|
3
|
+
// 'svelte' (any file in a program importing a module loads its ambient globals for the whole
|
|
4
|
+
// program); this package has no such import, so a triple-slash reference does the same job
|
|
5
|
+
// explicitly rather than relying on an incidental side-effect.
|
|
6
|
+
/// <reference types="svelte" />
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
|
|
7
|
+
import { onMounted, onUnmounted, ref, type Ref } from '@vue/runtime-core';
|
|
8
|
+
import {
|
|
9
|
+
addBatteryLevelListener,
|
|
10
|
+
getBatteryLevelAsync,
|
|
11
|
+
type EventSubscription,
|
|
12
|
+
} from '../../../core';
|
|
13
|
+
|
|
14
|
+
export function useBatteryLevel(): Ref<number> {
|
|
15
|
+
const batteryLevel = ref(-1);
|
|
16
|
+
let subscription: EventSubscription | undefined;
|
|
17
|
+
|
|
18
|
+
onMounted(() => {
|
|
19
|
+
getBatteryLevelAsync().then(level => {
|
|
20
|
+
batteryLevel.value = level;
|
|
21
|
+
});
|
|
22
|
+
subscription = addBatteryLevelListener(event => {
|
|
23
|
+
batteryLevel.value = event.batteryLevel;
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
onUnmounted(() => {
|
|
28
|
+
subscription?.remove();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return batteryLevel;
|
|
32
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
|
|
5
|
+
import { onMounted, onUnmounted, ref, type Ref } from '@vue/runtime-core';
|
|
6
|
+
import {
|
|
7
|
+
addBatteryStateListener,
|
|
8
|
+
BatteryState,
|
|
9
|
+
getBatteryStateAsync,
|
|
10
|
+
type EventSubscription,
|
|
11
|
+
} from '../../../core';
|
|
12
|
+
|
|
13
|
+
export function useBatteryState(): Ref<BatteryState> {
|
|
14
|
+
const batteryState = ref<BatteryState>(BatteryState.UNKNOWN);
|
|
15
|
+
let subscription: EventSubscription | undefined;
|
|
16
|
+
|
|
17
|
+
onMounted(() => {
|
|
18
|
+
getBatteryStateAsync().then(state => {
|
|
19
|
+
batteryState.value = state;
|
|
20
|
+
});
|
|
21
|
+
subscription = addBatteryStateListener(event => {
|
|
22
|
+
batteryState.value = event.batteryState;
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
onUnmounted(() => {
|
|
27
|
+
subscription?.remove();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return batteryState;
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
|
|
6
|
+
import { onMounted, onUnmounted, ref, type Ref } from '@vue/runtime-core';
|
|
7
|
+
import {
|
|
8
|
+
addLowPowerModeListener,
|
|
9
|
+
isLowPowerModeEnabledAsync,
|
|
10
|
+
type EventSubscription,
|
|
11
|
+
} from '../../../core';
|
|
12
|
+
|
|
13
|
+
export function useLowPowerMode(): Ref<boolean> {
|
|
14
|
+
const lowPowerMode = ref(false);
|
|
15
|
+
let subscription: EventSubscription | undefined;
|
|
16
|
+
|
|
17
|
+
onMounted(() => {
|
|
18
|
+
isLowPowerModeEnabledAsync().then(enabled => {
|
|
19
|
+
lowPowerMode.value = enabled;
|
|
20
|
+
});
|
|
21
|
+
subscription = addLowPowerModeListener(event => {
|
|
22
|
+
lowPowerMode.value = event.lowPowerMode;
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
onUnmounted(() => {
|
|
27
|
+
subscription?.remove();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return lowPowerMode;
|
|
31
|
+
}
|
package/src/vue/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
|
|
7
|
+
export { useBatteryLevel } from './composables/use-battery-level';
|
|
8
|
+
export { useBatteryState } from './composables/use-battery-state';
|
|
9
|
+
export { useLowPowerMode } from './composables/use-low-power-mode';
|
|
10
|
+
export * from '../core';
|