Bluetooth provider workaround for BlueZ/DBus timeouts

Context: https://invent.kde.org/network/kdeconnect-kde/-/merge_requests/600#note_884500

When bluetooth doesn't exist on the machine at all, QTConnectivity
tries to communicate with Bluez via dbus and introduces a 30 odd second
pause. That's not necessarily a problem in concept, however this blocks
the main thread of KDEConnect, which also then blocks the main thread
of Plasma on logon and causes tremendous delays and very broken
behaviour.

For the life of me, I cannot find a way to do "is bluetooth ok" without
QTConnect kicking off the dbus call so I think the only option is to
thread off the startup of the providers so that pauses don't block
the whole process.

I've just tested this here and my logon with bluetooth missing went
from approx 35 seconds down to about 2.

Ready for input/feedback whenever people have time; in my testing at the moment it seems to completely break the behaviour of KDEConnect (i.e. things can't connect), I'm guessing this is something to do with the effect of wrapping everything in the QThread. I'll dig into that next and see if I can figure it out.

BUG: 481870


(cherry picked from commit bb146a76d0)

4beb8c65 Fixing hanging startup/logon when bluetooth is unavailable

Co-authored-by: Rob Emery <kde@mintsoft.net>
This commit is contained in:
Simon Redman 2024-07-31 21:25:49 +00:00
parent 3a23350329
commit 8eff1dcca7

View file

@ -62,6 +62,16 @@ void Daemon::init()
{
qCDebug(KDECONNECT_CORE) << "Daemon starting";
// Register on DBus
// This must happen as early as possible in the process startup to ensure
// the absolute minimum amount of blocking on logon/autostart
qDBusRegisterMetaType<QMap<QString, QString>>();
QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.kdeconnect"));
QDBusConnection::sessionBus().registerObject(QStringLiteral("/modules/kdeconnect"), this, QDBusConnection::ExportScriptableContents);
qCDebug(KDECONNECT_CORE) << "DBus registration complete";
// Load backends
if (d->m_testMode)
d->m_linkProviders.insert(new LoopbackLinkProvider());
@ -75,10 +85,7 @@ void Daemon::init()
#endif
}
// Register on DBus
qDBusRegisterMetaType<QMap<QString, QString>>();
QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.kdeconnect"));
QDBusConnection::sessionBus().registerObject(QStringLiteral("/modules/kdeconnect"), this, QDBusConnection::ExportScriptableContents);
qCDebug(KDECONNECT_CORE) << "Backends loaded";
// Read remembered paired devices
const QStringList &list = KdeConnectConfig::instance().trustedDevices();
@ -86,12 +93,16 @@ void Daemon::init()
addDevice(new Device(this, id));
}
qCDebug(KDECONNECT_CORE) << "Paired devices added";
// Listen to new devices
for (LinkProvider *a : std::as_const(d->m_linkProviders)) {
connect(a, &LinkProvider::onConnectionReceived, this, &Daemon::onNewDeviceLink);
a->onStart();
}
qCDebug(KDECONNECT_CORE) << "Link providers started";
NotificationServerInfo::instance().init();
qCDebug(KDECONNECT_CORE) << "Daemon started";