Skip to content

Commit c199d58

Browse files
committed
fix: Only force connect to devices on macos.
1 parent adf1d01 commit c199d58

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src-tauri/src/transport/gatt.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use futures::StreamExt;
55
use std::time::Duration;
66
use uuid::Uuid;
77

8-
use bluest::{Adapter, ConnectionEvent, DeviceId};
8+
use bluest::{Adapter, ConnectionEvent, Device, DeviceId, Error};
99

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

@@ -101,6 +101,20 @@ pub async fn gatt_connect(
101101
}
102102
}
103103

104+
#[cfg(target_os = "macos")]
105+
async fn check_connected(adapter: &Adapter, dev: &Device) -> bool {
106+
if let Some(()) = adapter.connect_device(&device).await {
107+
true
108+
} else {
109+
false
110+
}
111+
}
112+
113+
#[cfg(not(target_os = "macos"))]
114+
async fn check_connected(adapter: &Adapter, device: &Device) -> bool{
115+
device.is_connected().await
116+
}
117+
104118
#[command]
105119
pub async fn gatt_list_devices() -> Result<Vec<super::commands::AvailableDevice>, ()> {
106120
let adapter = Adapter::default().await.ok_or(())?;
@@ -118,7 +132,7 @@ pub async fn gatt_list_devices() -> Result<Vec<super::commands::AvailableDevice>
118132

119133
let mut ret = vec![];
120134
while let Some(device) = devices.next().await {
121-
if let Ok(()) = adapter.connect_device(&device).await {
135+
if check_connected(&adapter, &device).await {
122136
let label = device.name_async().await.unwrap_or("Unknown".to_string());
123137
let id = serde_json::to_string(&device.id()).unwrap();
124138

0 commit comments

Comments
 (0)