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"; 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 // Load backends
if (d->m_testMode) if (d->m_testMode)
d->m_linkProviders.insert(new LoopbackLinkProvider()); d->m_linkProviders.insert(new LoopbackLinkProvider());
@ -75,10 +85,7 @@ void Daemon::init()
#endif #endif
} }
// Register on DBus qCDebug(KDECONNECT_CORE) << "Backends loaded";
qDBusRegisterMetaType<QMap<QString, QString>>();
QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.kdeconnect"));
QDBusConnection::sessionBus().registerObject(QStringLiteral("/modules/kdeconnect"), this, QDBusConnection::ExportScriptableContents);
// Read remembered paired devices // Read remembered paired devices
const QStringList &list = KdeConnectConfig::instance().trustedDevices(); const QStringList &list = KdeConnectConfig::instance().trustedDevices();
@ -86,12 +93,16 @@ void Daemon::init()
addDevice(new Device(this, id)); addDevice(new Device(this, id));
} }
qCDebug(KDECONNECT_CORE) << "Paired devices added";
// Listen to new devices // Listen to new devices
for (LinkProvider *a : std::as_const(d->m_linkProviders)) { for (LinkProvider *a : std::as_const(d->m_linkProviders)) {
connect(a, &LinkProvider::onConnectionReceived, this, &Daemon::onNewDeviceLink); connect(a, &LinkProvider::onConnectionReceived, this, &Daemon::onNewDeviceLink);
a->onStart(); a->onStart();
} }
qCDebug(KDECONNECT_CORE) << "Link providers started";
NotificationServerInfo::instance().init(); NotificationServerInfo::instance().init();
qCDebug(KDECONNECT_CORE) << "Daemon started"; qCDebug(KDECONNECT_CORE) << "Daemon started";