File tree Expand file tree Collapse file tree
Buttplug.Server.Managers.UWPBluetoothManager Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
33using System . Linq ;
4+ using System . Threading . Tasks ;
45using Buttplug . Core ;
56using Buttplug . Server . Bluetooth ;
67using JetBrains . Annotations ;
@@ -53,12 +54,28 @@ public UWPBluetoothManager(IButtplugLogManager aLogManager)
5354 // classes whenever we receive a device.
5455 _bleWatcher . Received += OnAdvertisementReceived ;
5556 _bleWatcher . Stopped += OnWatcherStopped ;
57+ var adapterTask = Task . Run ( ( ) => BluetoothAdapter . GetDefaultAsync ( ) . AsTask ( ) ) ;
58+ adapterTask . Wait ( ) ;
59+ var adapter = adapterTask . Result ;
60+ if ( adapter == null )
61+ {
62+ BpLogger . Warn ( "No bluetooth adapter available for UWP Bluetooth Manager Connection" ) ;
63+ return ;
64+ }
65+
66+ if ( ! adapter . IsLowEnergySupported )
67+ {
68+ BpLogger . Warn ( "Bluetooth adapter available but does not support Bluetooth Low Energy." ) ;
69+ return ;
70+ }
71+
72+ BpLogger . Debug ( "UWP Manager found working Bluetooth LE Adapter" ) ;
5673 }
5774
5875 private async void OnAdvertisementReceived ( BluetoothLEAdvertisementWatcher aObj ,
5976 BluetoothLEAdvertisementReceivedEventArgs aEvent )
6077 {
61- if ( aEvent == null || aEvent . Advertisement == null )
78+ if ( aEvent ? . Advertisement == null )
6279 {
6380 BpLogger . Debug ( "Null BLE advertisement recieved: skipping" ) ;
6481 return ;
You can’t perform that action at this time.
0 commit comments