diff --git a/net-view/operation/private/netmanagerthreadprivate.cpp b/net-view/operation/private/netmanagerthreadprivate.cpp index f9aa83cb..4a7ea590 100644 --- a/net-view/operation/private/netmanagerthreadprivate.cpp +++ b/net-view/operation/private/netmanagerthreadprivate.cpp @@ -3042,6 +3042,40 @@ NetType::NetConnectionStatus NetManagerThreadPrivate::toNetConnectionStatus(Conn return NetType::NetConnectionStatus::CS_UnConnected; } +bool NetManagerThreadPrivate::isWirelessApMode(NetworkDeviceBase *device) +{ + if (device->deviceType() != dde::network::DeviceType::Wireless) { + return false; + } + + // 查找 NetworkManager 的接口对象 + auto dev = NetworkManager::findNetworkInterface(device->path()); + if (!dev) { + return false; + } + + // 获取当前活动连接 + auto activeConn = dev->activeConnection(); + if (!activeConn || !activeConn->connection()) { + return false; + } + + // 获取连接设置 + auto settings = activeConn->connection()->settings(); + if (!settings) { + return false; + } + + // 检查无线设置的模式是否为 AP + // 使用 staticCast 因为前面已经确认了设备类型,性能优于 dynamicCast + auto wSettings = settings->setting(Setting::Wireless).staticCast(); + if (wSettings && wSettings->mode() == NetworkManager::WirelessSetting::Ap) { + return true; + } + + return false; +} + NetType::NetDeviceStatus NetManagerThreadPrivate::deviceStatus(NetworkDeviceBase *device) { // 如果当前网卡是有线网卡,且没有插入网线,那么就返回未插入网线 @@ -3080,7 +3114,9 @@ NetType::NetDeviceStatus NetManagerThreadPrivate::deviceStatus(NetworkDeviceBase return NetType::NetDeviceStatus::DS_Disconnected; case DeviceStatus::Prepare: case DeviceStatus::Config: - return NetType::NetDeviceStatus::DS_Connecting; + // 当设备处于 AP 模式时,虽然底层状态可能是 Prepare 或 Config, + // 但为了避免 UI 显示"正在连接"(用户并未连接外部网络),返回 Disconnected 状态。 + return isWirelessApMode(device) ? NetType::NetDeviceStatus::DS_Disconnected : NetType::NetDeviceStatus::DS_Connecting; case DeviceStatus::Needauth: return NetType::NetDeviceStatus::DS_Authenticating; case DeviceStatus::IpConfig: diff --git a/net-view/operation/private/netmanagerthreadprivate.h b/net-view/operation/private/netmanagerthreadprivate.h index 2bd803e4..0bc461fa 100644 --- a/net-view/operation/private/netmanagerthreadprivate.h +++ b/net-view/operation/private/netmanagerthreadprivate.h @@ -262,6 +262,7 @@ protected Q_SLOTS: static NetType::NetDeviceStatus toNetDeviceStatus(ConnectionStatus status); static NetType::NetConnectionStatus toNetConnectionStatus(ConnectionStatus status); + static bool isWirelessApMode(NetworkDeviceBase *device); static NetType::NetDeviceStatus deviceStatus(NetworkDeviceBase *device); private: