Fix windows crash when no bluetooth adapter available (#20)

This commit is contained in:
Rohit Sangwan
2024-03-13 17:33:42 +05:30
committed by GitHub
parent 1f7ba287ef
commit e22a3ddf99
+12 -4
View File
@@ -500,11 +500,19 @@ namespace universal_ble
winrt::fire_and_forget UniversalBlePlugin::InitializeAsync()
{
auto bluetoothAdapter = co_await BluetoothAdapter::GetDefaultAsync();
bluetoothRadio = co_await bluetoothAdapter.GetRadioAsync();
if (bluetoothRadio)
auto radios = co_await Radio::GetRadiosAsync();
for (auto &&radio : radios)
{
radioStateChangedRevoker = bluetoothRadio.StateChanged(winrt::auto_revoke, {this, &UniversalBlePlugin::Radio_StateChanged});
if (radio.Kind() == RadioKind::Bluetooth)
{
bluetoothRadio = radio;
radioStateChangedRevoker = bluetoothRadio.StateChanged(winrt::auto_revoke, {this, &UniversalBlePlugin::Radio_StateChanged});
break;
}
}
if (!bluetoothRadio)
{
std::cout << "Bluetooth is not available" << std::endl;
}
}