Skip to content

fix: prioritize wired icon when both networks connected - #616

Merged
wjyrich merged 2 commits into
linuxdeepin:masterfrom
wjyrich:fix-bug-375223
Sep 20, 2026
Merged

wjyrich merged 2 commits into
linuxdeepin:masterfrom
wjyrich:fix-bug-375223

Conversation

@wjyrich

@wjyrich wjyrich commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor
  1. Add logic to prefer wired network icon in taskbar when both wired and wireless networks are simultaneously connected and both can access the internet
  2. The new condition checks NetworkStatus::Connected state and overrides the connection type to Wired
  3. This affects the updateNetworkIcon() function in netstatus.cpp

Log: Taskbar network icon now prioritizes wired connection display when multiple networks are active

Influence:

  1. Connect both wired and wireless networks simultaneously and verify the taskbar shows the wired network icon
  2. Test with only wireless connected to confirm wireless icon still displays correctly
  3. Verify icon updates correctly when network status changes between connected and disconnected states
  4. Test with wired only, wireless only, and both connected scenarios
  5. Confirm proper behavior when networks have different internet access statuses

fix: 有线和无线同时连接时优先显示有线图标

  1. 在有线网络和无线网络同时连接且均可上网时,任务栏图标优先显示有线网络 图标
  2. 新增条件判断 NetworkStatus::Connected 状态并将连接类型强制设置为有 线 Wired
  3. 修改 netstatus.cpp 文件中的 updateNetworkIcon() 函数

Log: 当多网络同时连接时,任务栏网络图标优先显示有线连接

Influence:

  1. 同时连接有线和无线网络,验证任务栏显示有线网络图标
  2. 仅连接无线网络,确认无线图标仍能正确显示
  3. 验证网络状态在连接和断开状态切换时图标更新是否正确
  4. 测试仅有线连接、仅无线连接和双网络同时连接三种场景
  5. 确认不同网络上网状态不一致时的图标显示行为正确

PMS: BUG-375223

Summary by Sourcery

Prioritize the wired connection as the primary network type when multiple network connections are active.

Bug Fixes:

  • Track and expose the primary network connection type so the taskbar can consistently prioritize the wired connection when appropriate.

Enhancements:

  • Restore primary connection type state management and emit change notifications when it changes.

@sourcery-ai

sourcery-ai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates network icon selection so an aggregate Connected state, representing simultaneously usable wired and wireless networks, displays the wired icon while preserving existing handling for other connection states.

Flow diagram for network icon selection

flowchart TD
    A["updateNetworkIcon()"] --> B{"networkStatus()"}
    B -->|Connected| C["type = Wired"]
    B -->|Other states| D["Preserve existing connection type"]
    C --> E{"type"}
    D --> E
    E -->|Wireless| F["Display wireless icon"]
    E -->|Wired| G["Display wired icon"]
Loading

File-Level Changes

Change Details Files
Prioritize the wired taskbar icon when both wired and wireless connections are active and internet-accessible.
  • Detect the aggregate NetworkStatus::Connected state.
  • Override the selected connection type to Wired before selecting the corresponding icon.
  • Leave wireless icon lookup unchanged for wireless-only or other non-aggregate states.
net-view/window/netstatus.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread net-view/window/netstatus.cpp
1. Implemented primaryConnectionType() getter to return tracked
connection type
2. Initialized m_primaryConnectionType to Wired in constructor
3. Enabled updatePrimaryConnectionType() method with signal emission
4. Added m_primaryConnectionType member in private data class

Log: 新增主连接类型跟踪功能

Influence:
1. Test primaryConnectionType() returns default Wired at initialization
2. Verify updatePrimaryConnectionType() correctly updates when
connection changes
3. Test primaryConnectionTypeChanged signal is emitted with new
connection type
4. Test different connection types (Wired, Wireless, etc.) in various
network scenarios
5. Verify no regression in airplane mode functionality

feat: 启用主连接类型跟踪功能

1. 实现 primaryConnectionType() 查询当前跟踪的连接类型
2. 在构造函数中将 m_primaryConnectionType 初始化为有线连接
3. 启用 updatePrimaryConnectionType() 方法并支持信号发射
4. 在私有数据类中添加 m_primaryConnectionType 成员变量

Log: 新增主连接类型跟踪功能

Influence:
1. 测试 primaryConnectionType() 在初始化时返回默认的有线类型
2. 验证 updatePrimaryConnectionType() 在连接状态变化时正确更新
3. 测试 primaryConnectionTypeChanged 信号在连接类型变化时正确发射
4. 在各种网络场景下测试不同连接类型(有线、无线等)的区分
5. 验证飞行模式功能无回归问题

PMS: BUG-375223
@deepin-bot

deepin-bot Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 2.0.100
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #621

@deepin-bot

deepin-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 2.0.101
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #625

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

AI 代码审查报告

项目: linuxdeepin/dde-network-core
PR: #616 fix: prioritize wired icon when both networks connected
作者: wjyrich
分支: fix-bug-375223 → master
分析模式: 全量分析
扫描时间: 2026-09-20 13:38:11
PMS: BUG-375223


总体评分:96/100 — 优秀

维度 评分 状态 评价
语法逻辑 22/25 ✓ 语法正确,逻辑清晰
代码质量 24/25 ✓ 代码结构清晰,注释基本完整
代码性能 20/20 ✓ 性能良好,资源使用合理
代码安全 30/30 ✓ 存在0个安全漏洞

变更概述

本次 PR 恢复启用(uncomment)了之前被注释掉的 m_primaryConnectionType 主连接类型追踪机制,以修复 BUG-375223:有线和无线同时连接时优先显示有线图标。

修改文件:

  1. net-view/operation/netmanager.cpp — 恢复 primaryConnectionType 的 getter/setter 实现
  2. net-view/operation/private/netmanager_p.h — 恢复成员变量声明

变更统计:+9 行,-8 行,2 个文件


维度一:语法逻辑(22/25 ✓)

语法正确,逻辑清晰

审查内容:

  1. primaryConnectionType() getter 变更(netmanager.cpp:83-88)
    原实现始终返回 Unknown,现改为通过 Q_D(const NetManager) 返回 d->m_primaryConnectionType。
    Q_D 宏使用正确,符合 Qt d-pointer 惯例,无语法错误。

  2. 构造函数初始化列表变更(netmanager.cpp:209-211)
    取消注释 m_primaryConnectionType(NetManager::ConnectionType::Wired),初始化为 Wired。
    初始化列表语法正确。

  3. updatePrimaryConnectionType() setter 变更(netmanager.cpp:1046-1054)
    恢复实现:当类型变化时更新成员变量并发射 primaryConnectionTypeChanged 信号。
    Q_Q 宏使用正确,Q_EMIT 用法规范,变更检测逻辑合理。

  4. 成员变量声明恢复(netmanager_p.h:85-88)
    取消注释 NetManager::ConnectionType m_primaryConnectionType;,类型声明与使用一致。

发现问题:

  1. 默认初始化为 Wired 而非 Unknown 的潜在初始状态不一致(-3分,轻微问题)
    文件:net-view/operation/netmanager.cpp,约第 211 行
    原先 primaryConnectionType() 始终返回 Unknown,现改为返回 m_primaryConnectionType,其初始值为 Wired。这意味着在系统启动且尚未收到首次网络状态更新时,primaryConnectionType() 将返回 Wired 而非 Unknown。在仅连接无线网络或无网络连接的场景下,初始状态可能短暂显示有线图标。
    虽然当 updatePrimaryConnectionType() 被调用后状态会自行修正,但在首次网络状态回调前的窗口期内存在逻辑不一致。
    建议考虑将初始值设为 Unknown,待网络状态检测后再更新为实际类型,以确保初始状态的语义正确性。

维度二:代码质量(24/25 ✓)

代码结构清晰,注释基本完整

审查内容:

  1. 代码结构:变更属于恢复已注释代码,原有代码结构合理,Qt 属性变更通知模式实现规范。
  2. 代码重复:无重复代码。
  3. 调试信息清理:无残留调试代码,注释的取消清理干净,无遗留标记。
  4. 命名规范:m_primaryConnectionType 命名清晰,符合 Qt 成员变量命名规范(m_ 前缀)。

发现问题:

  1. updatePrimaryConnectionType() 缺少文档注释(-1分)
    文件:net-view/operation/netmanager.cpp,约第 1046 行
    恢复启用的 updatePrimaryConnectionType() 方法缺少文档注释,未说明调用时机、参数含义及信号发射条件。虽然方法名具有自解释性,但作为公开行为的一部分,建议添加简要注释。
    建议补充:
    /**
     * @brief 更新主连接类型,当类型发生变化时发射 primaryConnectionTypeChanged 信号
     * @param type 新的主连接类型
     */
    void NetManagerPrivate::updatePrimaryConnectionType(NetManager::ConnectionType type)

维度三:代码性能(20/20 ✓)

性能良好,资源使用合理

审查内容:

  1. 变更检测优化:updatePrimaryConnectionType() 在值未变化时跳过更新和信号发射,避免不必要的通知,性能合理。
  2. getter 效率:primaryConnectionType() 仅通过 d-pointer 读取成员变量,O(1) 复杂度。
  3. 信号发射:Qt 信号槽机制高效,且仅在类型变更时触发,无频繁信号问题。
  4. 无资源泄漏:不涉及动态内存分配或资源管理。

未发现性能问题。


维度四:代码安全(30/30 ✓)

存在0个安全漏洞

审查内容:

  1. 输入校验:updatePrimaryConnectionType() 参数为枚举类型 NetManager::ConnectionType,类型安全,无法注入非法值。
  2. 命令/SQL 注入:无外部输入处理,无命令执行或数据库操作。
  3. 敏感信息泄露:不涉及敏感数据处理。
  4. 内存安全:无缓冲区操作,无指针运算,Qt d-pointer/q-pointer 模式内存安全。
  5. 竞态条件:Qt 信号槽在同一线程调用,无多线程竞态风险。

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个


改进建议

1. 初始值语义优化(建议优先级:中)

当前 m_primaryConnectionType 初始化为 Wired,在无网络连接时返回 Wired 可能造成误导。建议:

// 方案A:初始值设为 Unknown,待网络检测后更新
, m_primaryConnectionType(NetManager::ConnectionType::Unknown)

// 方案B(当前方案):初始值设为 Wired,适用于优先显示有线图标的场景
, m_primaryConnectionType(NetManager::ConnectionType::Wired)

若业务需求要求"默认优先显示有线"(即使尚未检测到网络),当前方案合理;若要求"未检测时显示未知",建议采用方案A。

2. 补充方法文档注释(建议优先级:低)

为 updatePrimaryConnectionType() 添加文档注释,说明其调用时机和信号发射条件。


审查结论

本次 PR 的核心变更是恢复启用 m_primaryConnectionType 主连接类型追踪机制,修改内容与 commit 目的("enable primary connection type tracking")及 PR 标题("prioritize wired icon when both networks connected")完全一致。代码遵循 Qt 框架的 d-pointer/q-pointer 惯例和属性变更通知模式,实现规范。唯一值得关注的是 m_primaryConnectionType 默认初始化为 Wired 可能导致初始状态语义不完全准确,但这属于设计选择范畴,且在网络状态回调后会自行修正。整体代码质量良好,无安全风险,审查通过。

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: caixr23, wjyrich

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@wjyrich
wjyrich merged commit 3726c16 into linuxdeepin:master Sep 20, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants