refactor to global static variables to store application states.

This commit is contained in:
Vixalie
2025-03-03 09:53:58 +08:00
parent 3f175a1958
commit b126a3105f
6 changed files with 236 additions and 135 deletions

View File

@@ -23,6 +23,7 @@ type PeripheralItem = {
isConnected: boolean;
rssi: number | null;
battery: number | null;
services: { uuid: string; characteristics: string[] }[];
};
type BluetoothState = {
ready: boolean | null;
@@ -84,7 +85,6 @@ export const AvailablePeripherals = atom((get) => {
});
export const UnknownPeripherals = atom((get) => {
const peripherals = get(Peripherals);
console.debug('[origin peripherals]', peripherals);
return peripherals.filter((i) => i.isUnknown);
});
const Channels: Record<Channels, PrimitiveAtom<ChannelState>> = {
@@ -158,7 +158,7 @@ const EstimWatchProvider: FC<{ children?: ReactNode }> = ({ children }) => {
try {
unlistenBle.current = await listen('central_state_updated', () => refreshBle());
unlistenDevice.current = await listen('peripheral_connected', () => refreshDevice());
unlistenPreipherals.current = await listen('peripheral_found', (event) => {
unlistenPreipherals.current = await listen('peripheral_updated', (event) => {
refreshPeripherals(event.payload);
});
unlistenChannelA.current = await listen('channel_a_updated', () => refreshChannelA());