unify peripheral state struct.
This commit is contained in:
		| @@ -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[], | ||||
|   | ||||
| @@ -9,8 +9,8 @@ const DeviceStates: FC = () => { | ||||
|  | ||||
|   return ( | ||||
|     <> | ||||
|       <IconRssi height={16} level={deviceState.rssi} /> | ||||
|       <IconBattery height={16} level={deviceState.battery} /> | ||||
|       <IconRssi height={16} level={deviceState?.rssi} /> | ||||
|       <IconBattery height={16} level={deviceState?.battery} /> | ||||
|     </> | ||||
|   ); | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user