diff --git a/src-tauri/src/cmd/mod.rs b/src-tauri/src/cmd/mod.rs index 15b4bb2..6012e1c 100644 --- a/src-tauri/src/cmd/mod.rs +++ b/src-tauri/src/cmd/mod.rs @@ -1,6 +1,9 @@ use std::sync::Arc; -use btleplug::api::{Central as _, Peripheral as _}; +use btleplug::{ + api::{Central as _, Peripheral as _}, + platform::PeripheralId, +}; pub use state::{CentralState, ChannelState, PeripheralItem}; use tauri::{async_runtime::RwLock, AppHandle, Emitter, State}; @@ -79,6 +82,24 @@ pub async fn connected_peripheral_state( } } +#[tauri::command] +pub async fn specific_peripheral_state( + app_state: State<'_, Arc>>, + id: PeripheralId, +) -> Result { + let state = app_state.read().await; + let central = state + .get_central_adapter() + .await + .ok_or(errors::AppError::BluetoothAdapterNotFound)?; + let peripheral = central + .peripheral(&id) + .await + .map_err(|_| errors::AppError::UnableToRetrievePeripheralState)?; + let properties = peripheral.properties().await.unwrap_or(None); + Ok(PeripheralItem::new(&peripheral, properties.as_ref()).await) +} + #[tauri::command] pub async fn channel_a_state( _app_state: State<'_, Arc>>, diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index a8e5bcd..852759a 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -55,6 +55,7 @@ pub fn run() { .invoke_handler(generate_handler![ cmd::central_device_state, cmd::connected_peripheral_state, + cmd::specific_peripheral_state, cmd::channel_a_state, cmd::channel_b_state, cmd::activate_central_adapter,