@@ -461,12 +461,14 @@ pub enum CoreBluetoothEvent {
461461 } ,
462462 DeviceDiscovered {
463463 uuid : Uuid ,
464- name : Option < String > ,
464+ local_name : Option < String > ,
465+ advertisement_name : Option < String > ,
465466 event_receiver : Receiver < PeripheralEventInternal > ,
466467 } ,
467468 DeviceUpdated {
468469 uuid : Uuid ,
469- name : String ,
470+ local_name : Option < String > ,
471+ advertisement_name : Option < String > ,
470472 } ,
471473 DeviceDisconnected {
472474 uuid : Uuid ,
@@ -569,26 +571,20 @@ impl CoreBluetoothInternal {
569571 async fn on_discovered_peripheral (
570572 & mut self ,
571573 peripheral : Retained < CBPeripheral > ,
572- local_name : Option < String > ,
574+ advertisement_name : Option < String > ,
573575 ) {
574576 let uuid = nsuuid_to_uuid ( unsafe { & peripheral. identifier ( ) } ) ;
575577 let peripheral_name = unsafe { peripheral. name ( ) } ;
576-
577- let name = match ( peripheral_name. map ( |n| n. to_string ( ) ) , local_name) {
578- ( Some ( p_name) , Some ( l_name) ) if p_name != l_name => {
579- Some ( format ! ( "{p_name} [{l_name}]" ) )
580- }
581- ( Some ( p_name) , Some ( _) ) => Some ( p_name) ,
582- ( Some ( p_name) , None ) => Some ( p_name) ,
583- ( None , Some ( l_name) ) => Some ( l_name) ,
584- ( None , None ) => None ,
585- } ;
578+ let local_name = peripheral_name
579+ . map ( |n| n. to_string ( ) )
580+ . or ( advertisement_name. clone ( ) ) ;
586581
587582 if self . peripherals . contains_key ( & uuid) {
588- if let Some ( name ) = name {
583+ if local_name . is_some ( ) {
589584 self . dispatch_event ( CoreBluetoothEvent :: DeviceUpdated {
590585 uuid,
591- name : name. to_string ( ) ,
586+ local_name,
587+ advertisement_name,
592588 } )
593589 . await ;
594590 }
@@ -599,7 +595,8 @@ impl CoreBluetoothInternal {
599595 . insert ( uuid, PeripheralInternal :: new ( peripheral, event_sender) ) ;
600596 self . dispatch_event ( CoreBluetoothEvent :: DeviceDiscovered {
601597 uuid,
602- name : name. map ( |name| name. to_string ( ) ) ,
598+ local_name,
599+ advertisement_name,
603600 event_receiver,
604601 } )
605602 . await ;
@@ -1096,8 +1093,8 @@ impl CoreBluetoothInternal {
10961093 CentralDelegateEvent :: DidUpdateState { state} => {
10971094 self . dispatch_event( CoreBluetoothEvent :: DidUpdateState { state} ) . await
10981095 }
1099- CentralDelegateEvent :: DiscoveredPeripheral { cbperipheral, local_name } => {
1100- self . on_discovered_peripheral( cbperipheral, local_name ) . await
1096+ CentralDelegateEvent :: DiscoveredPeripheral { cbperipheral, advertisement_name } => {
1097+ self . on_discovered_peripheral( cbperipheral, advertisement_name ) . await
11011098 }
11021099 CentralDelegateEvent :: DiscoveredServices { peripheral_uuid, services} => {
11031100 self . on_discovered_services( peripheral_uuid, services)
0 commit comments