From 980066436067d203d5d6479fd17410c809411043 Mon Sep 17 00:00:00 2001 From: Rob Emery Date: Mon, 7 Oct 2024 21:26:49 +0100 Subject: [PATCH] These all need to be near-idempotent --- .../bluetooth/bluetoothlinkprovider.cpp | 16 +++++++----- core/backends/lan/lanlinkprovider.cpp | 25 ++++++++++++++++--- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/core/backends/bluetooth/bluetoothlinkprovider.cpp b/core/backends/bluetooth/bluetoothlinkprovider.cpp index 6e061f18a..c5206c0a8 100644 --- a/core/backends/bluetooth/bluetoothlinkprovider.cpp +++ b/core/backends/bluetooth/bluetoothlinkprovider.cpp @@ -75,17 +75,21 @@ void BluetoothLinkProvider::onStop() void BluetoothLinkProvider::enable() { - enabled = true; - tryToInitialise(); + if (enabled == false) { + enabled = true; + tryToInitialise(); + } } void BluetoothLinkProvider::disable() { - enabled = false; - this->onStop(); + if (enabled == true) { + enabled = false; + this->onStop(); - mBluetoothServer = nullptr; - mServiceDiscoveryAgent = nullptr; + mBluetoothServer = nullptr; + mServiceDiscoveryAgent = nullptr; + } } void BluetoothLinkProvider::onNetworkChange() diff --git a/core/backends/lan/lanlinkprovider.cpp b/core/backends/lan/lanlinkprovider.cpp index ecaad0286..019f8477f 100644 --- a/core/backends/lan/lanlinkprovider.cpp +++ b/core/backends/lan/lanlinkprovider.cpp @@ -86,17 +86,25 @@ LanLinkProvider::~LanLinkProvider() void LanLinkProvider::enable() { - disabled = false; - this->onStart(); + if (disabled == true) { + disabled = false; + this->onStart(); + } } void LanLinkProvider::disable() { - this->onStop(); - disabled = true; + if (disabled == false) { + this->onStop(); + disabled = true; + } } void LanLinkProvider::onStart() { + if (disabled) { + return; + } + const QHostAddress bindAddress = m_testMode ? QHostAddress::LocalHost : QHostAddress::Any; bool success = m_udpSocket.bind(bindAddress, UDP_PORT, QUdpSocket::ShareAddress); @@ -129,6 +137,9 @@ void LanLinkProvider::onStart() void LanLinkProvider::onStop() { + if (disabled) { + return; + } #ifdef KDECONNECT_MDNS m_mdnsDiscovery.onStop(); #endif @@ -139,6 +150,9 @@ void LanLinkProvider::onStop() void LanLinkProvider::onNetworkChange() { + if (disabled) { + return; + } if (m_combineNetworkChangeTimer.isActive()) { qCDebug(KDECONNECT_CORE) << "Device discovery triggered too fast, ignoring"; return; @@ -149,6 +163,9 @@ void LanLinkProvider::onNetworkChange() // I'm in a new network, let's be polite and introduce myself void LanLinkProvider::combinedOnNetworkChange() { + if (disabled) { + return; + } if (!m_server->isListening()) { qWarning() << "TCP server not listening, not broadcasting"; return;