diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2018-09-25 20:06:05 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-12 08:22:44 -0700 |
commit | 497c1248d4672524fc17e012f0fd3d4cb5137c8e (patch) | |
tree | 67d748476632995678074533f14bf92c5e092662 /core/btdiscovery.cpp | |
parent | 9491c96103d7be26e3a98245a345adcb9230c035 (diff) | |
download | subsurface-497c1248d4672524fc17e012f0fd3d4cb5137c8e.tar.gz |
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 <dirk@hohndel.org>
Diffstat (limited to 'core/btdiscovery.cpp')
-rw-r--r-- | core/btdiscovery.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
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 <QDebug> #include <QLoggingCategory> #include <QRegularExpression> +#include <QElapsedTimer> +#include <QCoreApplication> extern QMap<QString, dc_descriptor_t *> 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 |