Skip to content

Commit

Permalink
Fix windows crash when no bluetooth adapter available
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitsangwan01 committed Mar 13, 2024
1 parent 1f7ba28 commit 2ab3209
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions windows/src/universal_ble_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 2ab3209

Please sign in to comment.