Skip to content

Commit 70f03ba

Browse files
committed
chore: Add basic adapter detection to UWP Bluetooth Manager Startup
Use UWP functions to see if we even have a viable adapter to use and write information to the log about it.
1 parent a53310c commit 70f03ba

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

Buttplug.Server.Managers.UWPBluetoothManager/UWPBluetoothManager.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Threading.Tasks;
45
using Buttplug.Core;
56
using Buttplug.Server.Bluetooth;
67
using 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;

0 commit comments

Comments
 (0)