diff --git a/core/backends/bluetooth/bluetoothlinkprovider.cpp b/core/backends/bluetooth/bluetoothlinkprovider.cpp index 4c587d505..c021ae2c5 100644 --- a/core/backends/bluetooth/bluetoothlinkprovider.cpp +++ b/core/backends/bluetooth/bluetoothlinkprovider.cpp @@ -30,6 +30,12 @@ BluetoothLinkProvider::BluetoothLinkProvider() } void BluetoothLinkProvider::onStart() +{ + qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onStart executed"; + tryToInitialise(); +} + +void BluetoothLinkProvider::tryToInitialise() { QBluetoothLocalDevice localDevice; if (!localDevice.isValid()) { @@ -37,18 +43,16 @@ void BluetoothLinkProvider::onStart() return; } - qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onStart executed"; + if (!mBluetoothServer) { + qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onNetworkChange re-setting up mBluetoothServer"; - mBluetoothServer = new QBluetoothServer(QBluetoothServiceInfo::RfcommProtocol, this); - mBluetoothServer->setSecurityFlags(QBluetooth::Security::Encryption | QBluetooth::Security::Secure); - connect(mBluetoothServer, &QBluetoothServer::newConnection, this, &BluetoothLinkProvider::serverNewConnection); + mBluetoothServer = new QBluetoothServer(QBluetoothServiceInfo::RfcommProtocol, this); + mBluetoothServer->setSecurityFlags(QBluetooth::Security::Encryption | QBluetooth::Security::Secure); + connect(mBluetoothServer, &QBluetoothServer::newConnection, this, &BluetoothLinkProvider::serverNewConnection); - qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::About to start server listen"; - mKdeconnectService = mBluetoothServer->listen(mServiceUuid, QStringLiteral("KDE Connect")); - - // Disabled for the moment as once the server is listening, the client will not be able to connect anyway - // mServiceDiscoveryAgent->start(); - // connectTimer->start(); + qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onNetworkChange About to start server listen"; + mKdeconnectService = mBluetoothServer->listen(mServiceUuid, QStringLiteral("KDE Connect")); + } } void BluetoothLinkProvider::onStop() @@ -65,9 +69,10 @@ void BluetoothLinkProvider::onStop() mBluetoothServer->deleteLater(); } -// I'm in a new network, let's be polite and introduce myself void BluetoothLinkProvider::onNetworkChange() { + qCDebug(KDECONNECT_CORE) << "BluetoothLinkProvider::onNetworkChange executed"; + tryToInitialise(); } void BluetoothLinkProvider::connectError() diff --git a/core/backends/bluetooth/bluetoothlinkprovider.h b/core/backends/bluetooth/bluetoothlinkprovider.h index b831c926b..cf35d0ae2 100644 --- a/core/backends/bluetooth/bluetoothlinkprovider.h +++ b/core/backends/bluetooth/bluetoothlinkprovider.h @@ -62,6 +62,7 @@ private Q_SLOTS: private: void addLink(BluetoothDeviceLink *deviceLink, const QString &deviceId); QList getPairedDevices(); + void tryToInitialise(); QBluetoothUuid mServiceUuid; QPointer mBluetoothServer; diff --git a/core/daemon.cpp b/core/daemon.cpp index ee76b507a..863216d4b 100644 --- a/core/daemon.cpp +++ b/core/daemon.cpp @@ -127,6 +127,7 @@ void Daemon::forceOnNetworkChange() { qCDebug(KDECONNECT_CORE) << "Sending onNetworkChange to" << d->m_linkProviders.size() << "LinkProviders"; for (LinkProvider *a : std::as_const(d->m_linkProviders)) { + qCDebug(KDECONNECT_CORE) << "Sending onNetworkChange to: " << a->name(); a->onNetworkChange(); } }