Skip to content

Commit 34ac4f0

Browse files
committed
chore: Minor cleanup of UUID usage.
1 parent 0df090b commit 34ac4f0

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

src-tauri/Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ tauri-build = { version = "2.0.0-beta.15", features = [] }
1818
serde_json = "1.0"
1919
serde = { version = "1.0", features = ["derive"] }
2020
tauri = { version = "2.0.0-beta.19", features = [] }
21-
bluest = "0.6.6"
21+
bluest = { version = "0.6.6", features = ["serde"] }
2222
async-std = "1.12.0"
2323
uuid = "1.6.1"
2424
futures = "0.3.30"

src-tauri/src/transport/gatt.rs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ use bluest::{Adapter, DeviceId};
99

1010
use tauri::{command, AppHandle, State};
1111

12-
const SVC_UUID: &str = "00000000-0196-6107-c967-c5cfb1c2482a";
13-
const RPC_CHRC_UUID: &str = "00000001-0196-6107-c967-c5cfb1c2482a";
12+
const SVC_UUID: Uuid = Uuid::from_u128(0x00000000_0196_6107_c967_c5cfb1c2482a);
13+
const RPC_CHRC_UUID: Uuid = Uuid::from_u128(0x00000001_0196_6107_c967_c5cfb1c2482a);
1414

1515
#[command]
1616
pub async fn gatt_connect(
1717
id: String,
1818
app_handle: AppHandle,
1919
state: State<'_, super::commands::ActiveConnection<'_>>,
2020
) -> Result<bool, ()> {
21-
let uuid = Uuid::parse_str(SVC_UUID).expect("Valid UUID");
22-
2321
let adapter = Adapter::default().await.ok_or(())?;
2422

2523
adapter.wait_available().await.map_err(|_| ())?;
@@ -32,16 +30,15 @@ pub async fn gatt_connect(
3230
}
3331

3432
let service = d
35-
.discover_services_with_uuid(uuid)
33+
.discover_services_with_uuid(SVC_UUID)
3634
.await
3735
.map_err(|e| ())?
3836
.get(0)
3937
.cloned();
4038

4139
if let Some(s) = service {
42-
let char_uuid = Uuid::parse_str(RPC_CHRC_UUID).expect("Valid UUID");
4340
let char = s
44-
.discover_characteristics_with_uuid(char_uuid)
41+
.discover_characteristics_with_uuid(RPC_CHRC_UUID)
4542
.await
4643
.map_err(|_| ())?
4744
.get(0)
@@ -81,32 +78,24 @@ pub async fn gatt_connect(
8178

8279
#[command]
8380
pub async fn gatt_list_devices() -> Result<Vec<super::commands::AvailableDevice>, ()> {
84-
let uuid = Uuid::parse_str(SVC_UUID).expect("Valid UUID");
85-
8681
let adapter = Adapter::default().await.ok_or(())?;
8782

8883
adapter.wait_available().await.map_err(|_| ())?;
8984

9085
let devices = adapter
91-
.discover_devices(&[uuid])
86+
.discover_devices(&[SVC_UUID])
9287
.await
9388
.expect("GET DEVICES!")
9489
.take_until(async_std::task::sleep(Duration::from_secs(2)))
95-
.collect::<Vec<_>>()
96-
.await;
97-
98-
let candidates: Vec<super::commands::AvailableDevice> = devices
99-
.into_iter()
100-
.filter_map(|d| {
101-
d.map(|device| {
102-
let label = device.name().unwrap_or("Unknown".to_string());
90+
.filter_map(|d| ready(d.ok()))
91+
.then(move |device| async move {
92+
let label = device.name_async().await.unwrap_or("Unknown".to_string());
10393
let id = serde_json::to_string(&device.id()).unwrap();
10494

10595
super::commands::AvailableDevice { label, id }
106-
})
107-
.ok()
10896
})
109-
.collect();
97+
.collect::<Vec<_>>()
98+
.await;
11099

111-
Ok(candidates)
100+
Ok(devices)
112101
}

0 commit comments

Comments
 (0)