mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
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>
This commit is contained in:
parent
9491c96103
commit
497c1248d4
1 changed files with 16 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue