diff --git a/src/app/application.cpp b/src/app/application.cpp index 845ae8841..c13a60508 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -533,7 +533,6 @@ void Application::initServices() { try { m_networkService = std::make_unique(*m_systemBus); - m_prevWirelessEnabledForEvents = m_networkService->state().wirelessEnabled; m_networkService->setChangeCallback( [this, shouldRefreshControlCenter](const NetworkState& state, NetworkChangeOrigin origin) { onNetworkStateChangedForEvents(state, origin); @@ -542,6 +541,9 @@ void Application::initServices() { m_panelManager.refresh(); } }); + if (m_networkService->hasStateSnapshot()) { + m_prevWirelessEnabledForEvents = m_networkService->state().wirelessEnabled; + } kLog.info("network service active"); } catch (const std::exception& e) { kLog.warn("network service disabled: {}", e.what()); @@ -559,7 +561,6 @@ void Application::initServices() { try { m_bluetoothService = std::make_unique(*m_systemBus); - m_prevBluetoothPoweredForEvents = m_bluetoothService->state().powered; auto refreshBluetoothUi = [this, shouldRefreshControlCenter]() { m_bar.refresh(); if (shouldRefreshControlCenter()) { @@ -573,6 +574,9 @@ void Application::initServices() { }); m_bluetoothService->setDevicesCallback( [refreshBluetoothUi](const std::vector& /*devices*/) { refreshBluetoothUi(); }); + if (m_bluetoothService->hasStateSnapshot()) { + m_prevBluetoothPoweredForEvents = m_bluetoothService->state().powered; + } kLog.info("bluetooth service active"); } catch (const std::exception& e) { kLog.warn("bluetooth service disabled: {}", e.what()); diff --git a/src/dbus/bluetooth/bluetooth_service.cpp b/src/dbus/bluetooth/bluetooth_service.cpp index f4ab36fc8..945413cf1 100644 --- a/src/dbus/bluetooth/bluetooth_service.cpp +++ b/src/dbus/bluetooth/bluetooth_service.cpp @@ -458,6 +458,7 @@ void BluetoothService::refresh() { const BluetoothStateChangeOrigin origin = previous.powered != m_state.powered ? consumePoweredChangeOrigin(m_state.powered) : BluetoothStateChangeOrigin::External; + m_hasStateSnapshot = true; emitState(origin); emitDevices(); }); diff --git a/src/dbus/bluetooth/bluetooth_service.h b/src/dbus/bluetooth/bluetooth_service.h index bf295c621..17178a62f 100644 --- a/src/dbus/bluetooth/bluetooth_service.h +++ b/src/dbus/bluetooth/bluetooth_service.h @@ -79,6 +79,7 @@ public: void refresh(); [[nodiscard]] const BluetoothState& state() const noexcept { return m_state; } + [[nodiscard]] bool hasStateSnapshot() const noexcept { return m_hasStateSnapshot; } [[nodiscard]] const std::vector& devices() const noexcept { return m_devices; } void setPowered(bool enabled); @@ -108,6 +109,7 @@ private: BluetoothState m_state; std::vector m_devices; std::optional m_pendingLocalPowered; + bool m_hasStateSnapshot = false; StateCallback m_stateCallback; DevicesCallback m_devicesCallback; }; diff --git a/src/dbus/network/network_service.cpp b/src/dbus/network/network_service.cpp index d0610fac0..9d600c099 100644 --- a/src/dbus/network/network_service.cpp +++ b/src/dbus/network/network_service.cpp @@ -227,12 +227,14 @@ void NetworkService::refresh() { const bool vpnsChanged = pending->capturedVpns != m_vpnConnections; const bool savedChanged = pending->capturedSaved != m_savedSsids; const bool stateChanged = next != m_state; + const bool firstSnapshot = !m_hasStateSnapshot; const bool wirelessEnabledChanged = next.wirelessEnabled != m_state.wirelessEnabled; const NetworkChangeOrigin origin = wirelessEnabledChanged ? consumeWirelessEnabledChangeOrigin(next.wirelessEnabled) : NetworkChangeOrigin::External; m_state = std::move(next); - if ((stateChanged || apsChanged || vpnsChanged || savedChanged) && m_changeCallback) { + m_hasStateSnapshot = true; + if ((firstSnapshot || stateChanged || apsChanged || vpnsChanged || savedChanged) && m_changeCallback) { m_changeCallback(m_state, origin); } // Break the self-reference cycle: pending->onAllComplete captures pending. diff --git a/src/dbus/network/network_service.h b/src/dbus/network/network_service.h index 333b81a53..e58893a9a 100644 --- a/src/dbus/network/network_service.h +++ b/src/dbus/network/network_service.h @@ -73,6 +73,7 @@ public: void refresh(); [[nodiscard]] const NetworkState& state() const noexcept { return m_state; } + [[nodiscard]] bool hasStateSnapshot() const noexcept { return m_hasStateSnapshot; } [[nodiscard]] const std::vector& accessPoints() const noexcept { return m_accessPoints; } [[nodiscard]] const std::vector& vpnConnections() const noexcept { return m_vpnConnections; } [[nodiscard]] static const char* glyphForState(const NetworkState& state) noexcept; @@ -138,5 +139,6 @@ private: bool m_scanning = false; std::int64_t m_scanBaselineLastScan = 0; std::optional m_pendingLocalWirelessEnabled; + bool m_hasStateSnapshot = false; ChangeCallback m_changeCallback; };