@@ -5,7 +5,7 @@ use futures::StreamExt;
55use std:: time:: Duration ;
66use uuid:: Uuid ;
77
8- use bluest:: { Adapter , ConnectionEvent , DeviceId } ;
8+ use bluest:: { Adapter , ConnectionEvent , Device , DeviceId , Error } ;
99
1010use 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]
105119pub 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