diff --git a/selfdrive/ui/qt/offroad/networking.cc b/selfdrive/ui/qt/offroad/networking.cc index 49e6fef48f..0a8f00b5b6 100644 --- a/selfdrive/ui/qt/offroad/networking.cc +++ b/selfdrive/ui/qt/offroad/networking.cc @@ -77,7 +77,7 @@ void Networking::refresh() { an->refresh(); } -void Networking::connectToNetwork(const Network &n) { +void Networking::connectToNetwork(const Network n) { if (wifi->isKnownConnection(n.ssid)) { wifi->activateWifiConnection(n.ssid); } else if (n.security_type == SecurityType::OPEN) { diff --git a/selfdrive/ui/qt/offroad/networking.h b/selfdrive/ui/qt/offroad/networking.h index 7078bf9693..959a5f9a62 100644 --- a/selfdrive/ui/qt/offroad/networking.h +++ b/selfdrive/ui/qt/offroad/networking.h @@ -91,6 +91,6 @@ public slots: void refresh(); private slots: - void connectToNetwork(const Network &n); + void connectToNetwork(const Network n); void wrongPassword(const QString &ssid); }; diff --git a/selfdrive/ui/qt/offroad/wifiManager.cc b/selfdrive/ui/qt/offroad/wifiManager.cc index 55edb01e33..3aec03a6dc 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.cc +++ b/selfdrive/ui/qt/offroad/wifiManager.cc @@ -8,8 +8,8 @@ #include "selfdrive/ui/qt/util.h" bool compare_by_strength(const Network &a, const Network &b) { - return std::tuple(a.connected, strengthLevel(a.strength), b.ssid) > - std::tuple(b.connected, strengthLevel(b.strength), a.ssid); + return std::tuple(a.connected == ConnectedType::CONNECTED, strengthLevel(a.strength), b.ssid) > + std::tuple(b.connected == ConnectedType::CONNECTED, strengthLevel(b.strength), a.ssid); } template @@ -155,8 +155,7 @@ SecurityType WifiManager::getSecurityType(const QVariantMap &properties) { } void WifiManager::connect(const Network &n, const QString &password, const QString &username) { - connecting_to_network = n.ssid; - seenNetworks[n.ssid].connected = ConnectedType::CONNECTING; + setCurrentConnecting(n.ssid); forgetConnection(n.ssid); // Clear all connections that may already exist to the network we are connecting Connection connection; connection["connection"]["type"] = "802-11-wireless"; @@ -177,7 +176,6 @@ void WifiManager::connect(const Network &n, const QString &password, const QStri connection["ipv4"]["dns-priority"] = 600; connection["ipv6"]["method"] = "ignore"; - emit refreshSignal(); call(NM_DBUS_PATH_SETTINGS, NM_DBUS_INTERFACE_SETTINGS, "AddConnection", QVariant::fromValue(connection)); } @@ -257,6 +255,14 @@ void WifiManager::stateChange(unsigned int new_state, unsigned int previous_stat } } +void WifiManager::setCurrentConnecting(const QString &ssid) { + connecting_to_network = ssid; + for (auto &network : seenNetworks) { + network.connected = (network.ssid == ssid) ? ConnectedType::CONNECTING : ConnectedType::DISCONNECTED; + } + emit refreshSignal(); +} + // https://developer.gnome.org/NetworkManager/stable/gdbus-org.freedesktop.NetworkManager.Device.Wireless.html void WifiManager::propertyChange(const QString &interface, const QVariantMap &props, const QStringList &invalidated_props) { if (interface == NM_DBUS_INTERFACE_DEVICE_WIRELESS && props.contains("LastScan")) { @@ -310,9 +316,7 @@ void WifiManager::initConnections() { std::optional WifiManager::activateWifiConnection(const QString &ssid) { const QDBusObjectPath &path = getConnectionPath(ssid); if (!path.path().isEmpty()) { - connecting_to_network = ssid; - seenNetworks[ssid].connected = ConnectedType::CONNECTING; - emit refreshSignal(); + setCurrentConnecting(ssid); return asyncCall(NM_DBUS_PATH, NM_DBUS_INTERFACE, "ActivateConnection", QVariant::fromValue(path), QVariant::fromValue(QDBusObjectPath(adapter)), QVariant::fromValue(QDBusObjectPath("/"))); } return std::nullopt; diff --git a/selfdrive/ui/qt/offroad/wifiManager.h b/selfdrive/ui/qt/offroad/wifiManager.h index 244a3cec4a..c444b2abc1 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.h +++ b/selfdrive/ui/qt/offroad/wifiManager.h @@ -85,6 +85,7 @@ private: void refreshNetworks(); void activateModemConnection(const QDBusObjectPath &path); void addTetheringConnection(); + void setCurrentConnecting(const QString &ssid); signals: void wrongPassword(const QString &ssid);