diff --git a/src/dbus/network/network_service.cpp b/src/dbus/network/network_service.cpp index e081cd7ae..d0610fac0 100644 --- a/src/dbus/network/network_service.cpp +++ b/src/dbus/network/network_service.cpp @@ -76,14 +76,6 @@ namespace { int pending = 0; }; - void finalizeSavedConnections(std::shared_ptr savedState, std::vector& savedSsids, - std::function onComplete) { - std::ranges::sort(savedState->ssids); - savedState->ssids.erase(std::unique(savedState->ssids.begin(), savedState->ssids.end()), savedState->ssids.end()); - savedSsids = std::move(savedState->ssids); - onComplete(); - } - struct VpnRefreshState { std::vector vpns; std::set vpnPaths; @@ -670,12 +662,12 @@ void NetworkService::refreshSavedConnections(std::function onComplete) { } } if (--savedState->pending == 0) { - finalizeSavedConnections(savedState, m_savedSsids, onComplete); + finishSavedConnections(savedState->ssids, onComplete); } }); } catch (const sdbus::Error&) { if (--savedState->pending == 0) { - finalizeSavedConnections(savedState, m_savedSsids, onComplete); + finishSavedConnections(savedState->ssids, onComplete); } } } @@ -824,7 +816,7 @@ void NetworkService::refreshVpnConnections(std::function onComplete) { std::shared_ptr(sdbus::createProxy(m_bus.connection(), k_nmBusName, connectionPath)); connection->callMethodAsync("GetSettings") .onInterface(k_nmSettingsConnectionInterface) - .uponReplyInvoke([this, lifetimeToken, connection, vpnState, connectionPath, markActiveAndFinalize, + .uponReplyInvoke([lifetimeToken, connection, vpnState, connectionPath, markActiveAndFinalize, onComplete](std::optional getErr, std::map> cfg) { if (lifetimeToken.expired()) { @@ -1089,6 +1081,13 @@ void NetworkService::refreshAccessPoints(std::function onComplete) { } } +void NetworkService::finishSavedConnections(std::vector& ssids, std::function onComplete) { + std::ranges::sort(ssids); + ssids.erase(std::unique(ssids.begin(), ssids.end()), ssids.end()); + m_savedSsids = std::move(ssids); + onComplete(); +} + void NetworkService::finishRefreshAccessPoints(std::vector& aps, std::function onComplete) { // Deduplicate by SSID, keeping the strongest (and marking active if any entry is active). std::vector deduped; @@ -1273,7 +1272,7 @@ void NetworkService::readStateAsync(std::function onComplete const std::string activeDevicePath = m_activeDevicePath; const std::string activeApPath = m_activeApPath; - auto finish = [this, lifetimeToken, next, vpnFromList, onComplete]() { + auto finish = [lifetimeToken, next, vpnFromList, onComplete]() { if (lifetimeToken.expired()) { return; } @@ -1296,8 +1295,8 @@ void NetworkService::readStateAsync(std::function onComplete apProxy->callMethodAsync("GetAll") .onInterface(k_propertiesInterface) .withArguments(k_nmAccessPointInterface) - .uponReplyInvoke([this, lifetimeToken, next, finish, apProxy]( - std::optional apErr, std::map apProperties) { + .uponReplyInvoke([lifetimeToken, next, finish, apProxy](std::optional apErr, + std::map apProperties) { if (lifetimeToken.expired()) { return; } @@ -1371,7 +1370,7 @@ void NetworkService::readStateAsync(std::function onComplete next->kind = NetworkConnectivity::Wired; } - auto finishAfterIp4 = [this, lifetimeToken, next, finish, readActiveAccessPoint, deviceType]() { + auto finishAfterIp4 = [lifetimeToken, finish, readActiveAccessPoint, deviceType]() { if (lifetimeToken.expired()) { return; } @@ -1393,7 +1392,7 @@ void NetworkService::readStateAsync(std::function onComplete ip4Proxy->callMethodAsync("GetAll") .onInterface(k_propertiesInterface) .withArguments(k_nmIp4ConfigInterface) - .uponReplyInvoke([this, lifetimeToken, next, finishAfterIp4, + .uponReplyInvoke([lifetimeToken, next, finishAfterIp4, ip4Proxy](std::optional ip4Err, std::map ip4Properties) { if (lifetimeToken.expired()) { @@ -1463,7 +1462,7 @@ void NetworkService::readStateAsync(std::function onComplete connectionProxy->callMethodAsync("GetAll") .onInterface(k_propertiesInterface) .withArguments(k_nmActiveConnectionInterface) - .uponReplyInvoke([this, lifetimeToken, next, finish, readDeviceState, + .uponReplyInvoke([lifetimeToken, next, readDeviceState, connectionProxy](std::optional connErr, std::map connectionProperties) { if (lifetimeToken.expired()) { @@ -1501,7 +1500,7 @@ void NetworkService::readStateAsync(std::function onComplete m_nm->callMethodAsync("GetAll") .onInterface(k_propertiesInterface) .withArguments(k_nmInterface) - .uponReplyInvoke([this, lifetimeToken, next, readActiveConnectionState]( + .uponReplyInvoke([lifetimeToken, next, readActiveConnectionState]( std::optional nmErr, std::map nmProperties) { if (lifetimeToken.expired()) { return; diff --git a/src/dbus/network/network_service.h b/src/dbus/network/network_service.h index 3c50b93a5..333b81a53 100644 --- a/src/dbus/network/network_service.h +++ b/src/dbus/network/network_service.h @@ -109,6 +109,7 @@ private: void refreshAccessPoints(std::function onComplete); void refreshSavedConnections(std::function onComplete); void refreshVpnConnections(std::function onComplete); + void finishSavedConnections(std::vector& ssids, std::function onComplete); void finishRefreshAccessPoints(std::vector& aps, std::function onComplete); void rebindActiveConnection(); void rebindActiveDevice(const std::string& devicePath);