bt/net: avoid showing state toasts on startup (bt on, wifi on), acquire a baseline silently to avoid the noise

This commit is contained in:
Lemmy
2026-05-09 23:48:54 -04:00
parent cd673dd1c9
commit b113e3b60d
5 changed files with 14 additions and 3 deletions
+6 -2
View File
@@ -533,7 +533,6 @@ void Application::initServices() {
try {
m_networkService = std::make_unique<NetworkService>(*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<BluetoothService>(*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<BluetoothDeviceInfo>& /*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());
+1
View File
@@ -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();
});
+2
View File
@@ -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<BluetoothDeviceInfo>& devices() const noexcept { return m_devices; }
void setPowered(bool enabled);
@@ -108,6 +109,7 @@ private:
BluetoothState m_state;
std::vector<BluetoothDeviceInfo> m_devices;
std::optional<bool> m_pendingLocalPowered;
bool m_hasStateSnapshot = false;
StateCallback m_stateCallback;
DevicesCallback m_devicesCallback;
};
+3 -1
View File
@@ -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.
+2
View File
@@ -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<AccessPointInfo>& accessPoints() const noexcept { return m_accessPoints; }
[[nodiscard]] const std::vector<VpnConnectionInfo>& 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<bool> m_pendingLocalWirelessEnabled;
bool m_hasStateSnapshot = false;
ChangeCallback m_changeCallback;
};