Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion net-view/operation/private/netmanagerthreadprivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<NetworkManager::WirelessSetting>();
if (wSettings && wSettings->mode() == NetworkManager::WirelessSetting::Ap) {
return true;
}

return false;
}

NetType::NetDeviceStatus NetManagerThreadPrivate::deviceStatus(NetworkDeviceBase *device)
{
// 如果当前网卡是有线网卡,且没有插入网线,那么就返回未插入网线
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions net-view/operation/private/netmanagerthreadprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down