Fix windows crash when no bluetooth adapter available (#20)
This commit is contained in:
@@ -500,11 +500,19 @@ namespace universal_ble
|
|||||||
|
|
||||||
winrt::fire_and_forget UniversalBlePlugin::InitializeAsync()
|
winrt::fire_and_forget UniversalBlePlugin::InitializeAsync()
|
||||||
{
|
{
|
||||||
auto bluetoothAdapter = co_await BluetoothAdapter::GetDefaultAsync();
|
auto radios = co_await Radio::GetRadiosAsync();
|
||||||
bluetoothRadio = co_await bluetoothAdapter.GetRadioAsync();
|
for (auto &&radio : radios)
|
||||||
if (bluetoothRadio)
|
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user