Skip to content

Commit

Permalink
fix: Only force connect to devices on macos.
Browse files Browse the repository at this point in the history
  • Loading branch information
petejohanson committed Sep 3, 2024
1 parent adf1d01 commit c199d58
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src-tauri/src/transport/gatt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use futures::StreamExt;
use std::time::Duration;
use uuid::Uuid;

use bluest::{Adapter, ConnectionEvent, DeviceId};
use bluest::{Adapter, ConnectionEvent, Device, DeviceId, Error};

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

Expand Down Expand Up @@ -101,6 +101,20 @@ pub async fn gatt_connect(
}
}

#[cfg(target_os = "macos")]
async fn check_connected(adapter: &Adapter, dev: &Device) -> bool {
if let Some(()) = adapter.connect_device(&device).await {
true
} else {
false
}
}

#[cfg(not(target_os = "macos"))]
async fn check_connected(adapter: &Adapter, device: &Device) -> bool{
device.is_connected().await
}

#[command]
pub async fn gatt_list_devices() -> Result<Vec<super::commands::AvailableDevice>, ()> {
let adapter = Adapter::default().await.ok_or(())?;
Expand All @@ -118,7 +132,7 @@ pub async fn gatt_list_devices() -> Result<Vec<super::commands::AvailableDevice>

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

Expand Down

0 comments on commit c199d58

Please sign in to comment.