diff --git a/src-tauri/src/cmd/state.rs b/src-tauri/src/cmd/state.rs index 9718464..373bd19 100644 --- a/src-tauri/src/cmd/state.rs +++ b/src-tauri/src/cmd/state.rs @@ -19,7 +19,8 @@ pub struct CentralState { pub struct PeripheralItem { pub id: PeripheralId, pub address: String, - pub represent: String, + pub represent: Option, + pub is_unknown: bool, pub is_connected: bool, pub rssi: Option, pub battery: Option, @@ -42,9 +43,8 @@ impl PeripheralItem { Self { id: periperial.id(), address: periperial.address().to_string(), - represent: properties - .and_then(|p| p.local_name.clone()) - .unwrap_or(String::from("Unknown")), + represent: properties.and_then(|p| p.local_name.clone()), + is_unknown: properties.and_then(|p| p.local_name.clone()).is_none(), is_connected: periperial.is_connected().await.unwrap_or(false), rssi: properties.and_then(|p| p.rssi), battery: properties.and_then(|p| p.tx_power_level), diff --git a/src/context/EstimContext.tsx b/src/context/EstimContext.tsx index 55a0b84..044d5cc 100644 --- a/src/context/EstimContext.tsx +++ b/src/context/EstimContext.tsx @@ -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(async (get) => { connected: null, }; }); -export const DeviceState = atomWithRefresh(async (get) => { +export const DeviceState = atomWithRefresh(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[], diff --git a/src/page-components/state-bar/DeviceStates.tsx b/src/page-components/state-bar/DeviceStates.tsx index 741827a..9746de4 100644 --- a/src/page-components/state-bar/DeviceStates.tsx +++ b/src/page-components/state-bar/DeviceStates.tsx @@ -9,8 +9,8 @@ const DeviceStates: FC = () => { return ( <> - - + + ); };