-
Notifications
You must be signed in to change notification settings - Fork 49
fix: Update taskbar signal strength icon in real-time when network st… #483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideUpdates wireless access point strength handling so the taskbar/network UI reacts in real time to changes in the active access point’s signal strength, and ensures icon refresh when strength level changes. Sequence diagram for real-time taskbar signal strength updatessequenceDiagram
actor User
participant NetworkManagerWirelessDevice as NetworkManager_WirelessDevice
participant NetworkManagerAccessPoint as NetworkManager_AccessPoint
participant WirelessDeviceManagerRealize
participant AccessPointInfo
participant AccessPointProxyNM
participant NetStatus
participant TaskbarIcon
User->>NetworkManagerWirelessDevice: connectToNetwork
NetworkManagerWirelessDevice->>WirelessDeviceManagerRealize: activeAccessPointChanged
WirelessDeviceManagerRealize->>NetworkManagerWirelessDevice: activeAccessPoint()
NetworkManagerWirelessDevice-->>WirelessDeviceManagerRealize: activeAp
WirelessDeviceManagerRealize->>WirelessDeviceManagerRealize: changeActiveAp
WirelessDeviceManagerRealize->>WirelessDeviceManagerRealize: updateActiveApStrength(activeAp)
WirelessDeviceManagerRealize->>AccessPointInfo: findByUni(activeAp.uni())
AccessPointInfo-->>WirelessDeviceManagerRealize: apInfo
WirelessDeviceManagerRealize->>AccessPointProxyNM: updateStrengthFromActiveAp(activeAp.signalStrength())
AccessPointProxyNM-->>NetStatus: strengthChanged(m_strength)
NetStatus->>NetStatus: onStrengthLevelChanged
NetStatus->>NetStatus: updateStatus
NetStatus->>NetStatus: updateNetworkIcon
NetStatus-->>TaskbarIcon: setSignalStrengthIcon
loop While connected
NetworkManagerAccessPoint-->>WirelessDeviceManagerRealize: signalStrengthChanged
WirelessDeviceManagerRealize->>WirelessDeviceManagerRealize: updateActiveApStrength(activeAp)
WirelessDeviceManagerRealize->>AccessPointProxyNM: updateStrengthFromActiveAp(activeAp.signalStrength())
AccessPointProxyNM-->>NetStatus: strengthChanged(m_strength)
NetStatus->>NetStatus: onStrengthLevelChanged
NetStatus->>NetStatus: updateNetworkIcon
NetStatus-->>TaskbarIcon: setSignalStrengthIcon
end
Class diagram for updated network strength handlingclassDiagram
class WirelessDeviceManagerRealize {
- NetworkManager_WirelessDevice_Ptr m_device
- QList~AccessPointInfo_ptr~ m_accessPointInfos
- bool m_hotspotEnabled
- ProcesserInterface_ptr m_netProcesser
- bool m_available
- QMetaObject_Connection m_activeApStrengthConn
+ WirelessDeviceManagerRealize(NetworkManager_WirelessDevice_Ptr device)
+ ~WirelessDeviceManagerRealize()
+ void addNetwork(NetworkManager_WirelessNetwork_Ptr network)
}
class AccessPointInfo {
+ AccessPointProxyNM_ptr proxy()
+ QString accessPoint()
}
class AccessPointProxyNM {
- int m_strength
+ bool isWlan6() const
+ void updateStrengthFromActiveAp(int strength)
+ void strengthChanged(int strength)
}
class NetStatus {
+ void onStrengthLevelChanged()
+ void updateStatus()
+ void updateNetworkIcon()
}
class NetworkManager_WirelessDevice {
+ NetworkManager_AccessPoint_Ptr activeAccessPoint() const
+ void activeAccessPointChanged()
}
class NetworkManager_AccessPoint {
+ QString uni() const
+ int signalStrength() const
+ void signalStrengthChanged(int strength)
}
WirelessDeviceManagerRealize --> NetworkManager_WirelessDevice : uses
WirelessDeviceManagerRealize "1" --> "*" AccessPointInfo : manages
AccessPointInfo --> AccessPointProxyNM : has
WirelessDeviceManagerRealize ..> AccessPointProxyNM : calls updateStrengthFromActiveAp
NetworkManager_WirelessDevice --> NetworkManager_AccessPoint : activeAccessPoint
NetworkManager_AccessPoint ..> WirelessDeviceManagerRealize : signalStrengthChanged
AccessPointProxyNM ..> NetStatus : strengthChanged
NetStatus ..> NetStatus : updateNetworkIcon
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've left some high level feedback:
- The logic for syncing the active access point’s strength to
AccessPointProxyis duplicated in multiple places (constructor,addNetwork); consider extracting this into a small helper method to avoid divergence and make future changes less error-prone. - In
addNetwork, the new active-AP strength update paths assumeapInfo->proxy()is non-null; for consistency with the constructor loop where you checkapInfo && apInfo->proxy(), it may be safer to add the same null-checks here.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The logic for syncing the active access point’s strength to `AccessPointProxy` is duplicated in multiple places (constructor, `addNetwork`); consider extracting this into a small helper method to avoid divergence and make future changes less error-prone.
- In `addNetwork`, the new active-AP strength update paths assume `apInfo->proxy()` is non-null; for consistency with the constructor loop where you check `apInfo && apInfo->proxy()`, it may be safer to add the same null-checks here.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…rength changes When the network signal strength changes, the taskbar icon should be updated accordingly. Log: Fix the issue where the taskbar signal strength icon does not update in real-time Influence: Taskbar signal strength display PMS: BUG-331547
deepin pr auto review这段代码主要解决了无线网络信号强度更新不及时的问题,通过监听 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
5. 具体改进代码示例针对代码重复问题,建议修改 // 辅助函数
void WirelessDeviceManagerRealize::syncActiveApStrength(AccessPointInfo *apInfo)
{
if (!apInfo) return;
NetworkManager::AccessPoint::Ptr activeAp = m_device->activeAccessPoint();
if (!activeAp.isNull() && apInfo->proxy()->contains(activeAp->uni())) {
apInfo->proxy()->updateStrengthFromActiveAp(activeAp->signalStrength());
}
}
// 在 addNetwork 中使用
void WirelessDeviceManagerRealize::addNetwork(const NetworkManager::WirelessNetwork::Ptr &network)
{
// ... 前面的代码 ...
if (itApInfo == m_accessPointInfos.end()) {
AccessPointInfo *apInfo = new AccessPointInfo(m_device, network);
m_accessPointInfos << apInfo;
// 使用辅助函数
syncActiveApStrength(apInfo);
Q_EMIT networkAdded({ apInfo->accessPoint() });
} else {
AccessPointInfo *apInfo = *itApInfo;
apInfo->proxy()->updateNetwork(network);
// 使用辅助函数
syncActiveApStrength(apInfo);
}
}针对 Lambda 连接的建议修改: // 在构造函数中
auto changeActiveAp = [this] {
if (m_activeApStrengthConn) {
disconnect(m_activeApStrengthConn);
m_activeApStrengthConn = QMetaObject::Connection(); // 重置连接对象
}
NetworkManager::AccessPoint::Ptr activeAp = m_device->activeAccessPoint();
if (activeAp.isNull())
return;
// 更新初始强度
auto updateFunc = [this](const NetworkManager::AccessPoint::Ptr &ap) {
if (ap.isNull()) return;
for (AccessPointInfo *apInfo : m_accessPointInfos) {
if (apInfo && apInfo->proxy() && apInfo->proxy()->contains(ap->uni())) {
apInfo->proxy()->updateStrengthFromActiveAp(ap->signalStrength());
break;
}
}
};
updateFunc(activeAp);
// 建立新连接,移除 Qt::UniqueConnection,因为逻辑上已经唯一
m_activeApStrengthConn = connect(activeAp.data(), &NetworkManager::AccessPoint::signalStrengthChanged,
this, [updateFunc, activeAp] {
updateFunc(activeAp);
});
};总结这段代码整体质量不错,逻辑清晰,有效地解决了信号强度同步问题。主要改进点在于消除代码重复(提取辅助函数)和微调 Lambda 连接管理的写法以提高可读性。安全性方面做得较好,有必要的空指针检查。性能方面对于常规场景(AP 数量不多)没有问题。 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: caixr23, ut003640 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
…rength changes
When the network signal strength changes, the taskbar icon should be updated accordingly.
Log: Fix the issue where the taskbar signal strength icon does not update in real-time
Influence: Taskbar signal strength display
PMS: BUG-331547
Summary by Sourcery
Ensure wireless network signal strength updates propagate to the UI in real time when the active access point changes.
Bug Fixes:
Enhancements: