mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
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:
@@ -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());
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user