unify peripheral state struct.

This commit is contained in:
Vixalie
2025-02-28 13:50:53 +08:00
parent c6043b612f
commit 26165f5d5c
3 changed files with 10 additions and 31 deletions

View File

@@ -19,18 +19,11 @@ type PeripheralItem = {
id: string;
address: string;
represent: string | null;
isUnknown: boolean;
isConnected: boolean;
rssi: number | null;
battery: number | null;
};
type DeviceState = {
id: string | null;
address: string | null;
represent: string | null;
isConnected: boolean | null;
rssi: number | null;
battery: number | null;
};
type BluetoothState = {
ready: boolean | null;
searching: boolean | null;
@@ -54,28 +47,14 @@ export const BleState = atomWithRefresh<BluetoothState>(async (get) => {
connected: null,
};
});
export const DeviceState = atomWithRefresh<DeviceState>(async (get) => {
export const DeviceState = atomWithRefresh<PeripheralItem | null>(async (get) => {
try {
const state = await invoke('connected_peripheral_state');
return {
id: state?.id,
address: state?.address,
represent: state?.represent,
isConnected: state?.isConnected,
rssi: state?.rssi,
battery: state?.battery,
};
return state;
} catch (e) {
console.error('[refresh connected]', e);
}
return {
id: null,
address: null,
represent: null,
isConnected: null,
rssi: null,
battery: null,
};
return null;
});
export const FoundPeripherals = atom(
[] as PeripheralItem[],