From 497c1248d4672524fc17e012f0fd3d4cb5137c8e Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 25 Sep 2018 20:06:05 -0700 Subject: Bluetooth: wait until we actually have device info On macOS, we cannot connect to a BT/BLE device until we have scanned it. Right now this just sits quietly and waits, which given how long this can take is rather unsatisfying and might look like Subsurface is hung. Signed-off-by: Dirk Hohndel --- core/btdiscovery.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/core/btdiscovery.cpp b/core/btdiscovery.cpp index c3f6c9b36..0bacbadda 100644 --- a/core/btdiscovery.cpp +++ b/core/btdiscovery.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include extern QMap descriptorLookup; @@ -326,7 +328,20 @@ QBluetoothDeviceInfo getBtDeviceInfo(const QString &devaddr) { if (btDeviceInfo.contains(devaddr)) return btDeviceInfo[devaddr]; - qDebug() << "need to scan for" << devaddr; + if(!btDeviceInfo.keys().contains(devaddr)) { + qDebug() << "still looking scan is still running, we should just wait for a few moments"; + // wait for a maximum of 30 more seconds + // yes, that seems crazy, but on my Mac I see this take more than 20 seconds + QElapsedTimer timer; + timer.start(); + do { + if (btDeviceInfo.keys().contains(devaddr)) + return btDeviceInfo[devaddr]; + QCoreApplication::processEvents(QEventLoop::AllEvents, 100); + QThread::msleep(100); + } while (timer.elapsed() < 30000); + } + qDebug() << "notify user that we can't find" << devaddr; return QBluetoothDeviceInfo(); } #endif // BT_SUPPORT -- cgit v1.2.3-70-g09d2