Skip to content

fix: hide VPN and system proxy switches when no configuration exists - #638

Merged
caixr23 merged 1 commit into
linuxdeepin:masterfrom
caixr23:master
Sep 30, 2026
Merged

caixr23 merged 1 commit into
linuxdeepin:masterfrom
caixr23:master

Conversation

@caixr23

@caixr23 caixr23 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor
  1. Add Net_SysProxyEnabledable flag: the enabledable of NetSystemProxyControlItem now follows whether a system proxy configuration exists, without affecting whether the menu item itself is shown (Net_SysProxyAlwaysShow keeps the item always visible in the control center, see BUG-350619).
  2. In NetManagerThreadPrivate::doInit, track systemProxyExistChanged whenever Net_SysProxyEnabledable is set, and emit the initial enabledable state.
  3. In NetManagerPrivate::onDataChanged DeviceAvailableChanged, only hide the SystemProxyControlItem via updateItemVisible when Net_SysProxyAlwaysShow is NOT set; otherwise just update enabledable. VPNControlItem keeps the existing hide-by-existence behavior (its children are the VPN connections).
  4. In PageSystemProxy.qml, drive the switches' presence with netItem.enabledable (page: proxyConfigExist ? devCheck : null, visible: netItem.enabledable) instead of computing existence from raw proxy data.
  5. In PageVPN.qml, only show the VPN switches when the VPN control item has children (hasVpnConnection).
  6. In ProxyController::onProxyChanged, route the "auto" proxyChanged signal to queryAutoProxy(): the daemon emits proxyChanged("auto", url) when the PAC URL changes, but queryProxyDataByType only understands http/https/ftp/socks, so m_autoProxyURL was never refreshed and systemProxyExist stayed stale.

Log: When there is no VPN connection or no system proxy configuration, the VPN and system proxy menu entries no longer show their switches, while the entries themselves remain accessible for adding/importing VPN connections or configuring the proxy.

Influence:

  1. With no VPN connection and no system proxy config, open the network page: the VPN and system proxy entries show no switch (arrow only), and both pages can still be opened to add/import VPN or configure the proxy.
  2. Add a VPN connection (nmcli/import): the VPN switch appears in real time; delete all VPN connections: the switch disappears.
  3. Configure a manual proxy (any http/https/ftp/socks host) or a PAC URL: the system proxy switch appears; clear all proxy values: the switch disappears (auto PAC and manual host both covered, and the previously stale autoProxy refresh path is fixed).
  4. Dock/lock/greeter: system proxy item visibility still follows whether a proxy configuration exists (no AlwaysShow flag there), unchanged behavior vs before this change.

fix: 不存在VPN连接和系统代理配置时隐藏VPN与系统代理开关

  1. 新增 Net_SysProxyEnabledable 标志:NetSystemProxyControlItem 的 enabledable 跟随是否存在系统代理配置,且不影响菜单项本身是否显示 (Net_SysProxyAlwaysShow 仍保证控制中心菜单项恒显,见 BUG-350619)。
  2. NetManagerThreadPrivate::doInit 中,设置 Net_SysProxyEnabledable 时跟踪 systemProxyExistChanged,并下发初始 enabledable 状态。
  3. NetManagerPrivate::onDataChanged 的 DeviceAvailableChanged 分支, 仅当未设置 Net_SysProxyAlwaysShow 时才用 updateItemVisible 隐藏 SystemProxyControlItem;否则只更新 enabledable。VPNControlItem 保留 原有"按是否存在连接子项显隐"的行为。
  4. PageSystemProxy.qml 的开关显隐改为由 netItem.enabledable 驱动 (page: proxyConfigExist ? devCheck : null, visible: netItem.enabledable), 不再自行根据原始代理数据计算。
  5. PageVPN.qml 仅在 VPN 控制项存在子连接时展示开关(hasVpnConnection)。
  6. ProxyController::onProxyChanged 对 "auto" 类型的 proxyChanged 信号 改走 queryAutoProxy():daemon 在 PAC URL 变化时发出的是 proxyChanged("auto", url),而 queryProxyDataByType 只识别 http/https/ftp/socks,导致 m_autoProxyURL 从不刷新、 systemProxyExist 一直停留在旧值。

Log: 不存在VPN连接或系统代理配置时,VPN 与系统代理菜单项不再展示开关,
菜单项本身仍可点开用于添加/导入VPN或配置代理。

Influence:

  1. 无VPN连接且无系统代理配置时打开网络页:VPN 与系统代理菜单项不显示 开关(仅箭头),仍可进入页面添加/导入VPN或配置代理。
  2. 添加一个VPN连接(nmcli/导入):VPN 开关实时出现;删除全部VPN连接: 开关消失。
  3. 配置手动代理(任一 http/https/ftp/socks host)或 PAC URL:系统代理 开关出现;清空全部代理值:开关消失(自动PAC与手动host均覆盖,并修复了 此前 autoProxy 刷新不到位的缺陷)。
  4. dock/锁屏/greeter:系统代理项仍按是否存在代理配置显隐(不带 AlwaysShow 标志),行为与改动前一致。

PMS: BUG-378285

Summary by Sourcery

Hide VPN and system proxy switches without configurations while keeping their configuration pages accessible and ensuring proxy state updates remain accurate.

Bug Fixes:

  • Hide VPN and system proxy switches when no corresponding configuration exists while keeping both menu entries available for adding or configuring connections.
  • Refresh automatic proxy configuration state correctly when PAC settings change.
  • Update proxy existence detection for manual host and port changes.

Enhancements:

  • Keep system proxy menu visibility independent from switch availability when the always-show flag is enabled, while preserving existing visibility behavior in other contexts.

@sourcery-ai

sourcery-ai Bot commented Sep 30, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR makes VPN and system proxy switches conditional on actual configuration existence without removing the corresponding menu entries, preserves context-specific system proxy visibility semantics, and fixes stale proxy-existence state for PAC and manual proxy updates.

Sequence diagram for proxy configuration state updates

sequenceDiagram
    participant ProxySettings as ProxySettings
    participant NetworkProxy as NetworkProxy
    participant ProxyController as ProxyController
    participant NetManagerThread as NetManagerThread
    participant SystemProxyItem as SystemProxyItem
    participant SystemProxyPage as SystemProxyPage

    ProxySettings->>NetworkProxy: onConfigChanged(key)
    NetworkProxy-->>ProxyController: proxyChanged(type, value)
    alt type is auto
        ProxyController->>ProxyController: queryAutoProxy()
    else manual proxy type
        ProxyController->>ProxyController: queryProxyDataByType(type)
    end
    ProxyController-->>NetManagerThread: systemProxyExistChanged(exists)
    NetManagerThread->>NetManagerThread: onSystemProxyExistChanged(exists)
    NetManagerThread-->>SystemProxyItem: updateenabledable(exists)
    SystemProxyItem-->>SystemProxyPage: enabledable
    SystemProxyPage->>SystemProxyPage: visible = netItem.enabledable
Loading

Flow diagram for VPN switch visibility

flowchart TD
    VPNControlItem[VPN control item] --> ConnectionChildren{Has VPN connection children?}
    ConnectionChildren -- Yes --> ShowSwitch[Show VPN switch]
    ConnectionChildren -- No --> HideSwitch[Hide VPN switch]
    VPNControlItem --> OpenPage[Keep VPN page available for add or import]
Loading

File-Level Changes

Change Details Files
Decouple the system proxy control item's switch state from menu-item visibility by introducing a configuration-existence-driven enabledable flag.
  • Add Net_SysProxyEnabledable to the relevant runtime flag sets.
  • Initialize and continuously propagate system proxy existence through enabledable state.
  • Preserve AlwaysShow menu visibility while retaining existence-based visibility for dock, lock, and greeter contexts.
net-view/operation/nettype.h
net-view/operation/private/netmanagerthreadprivate.cpp
net-view/operation/netmanager.cpp
Hide VPN and system proxy switches when their underlying configuration is absent while keeping the entries available for configuration.
  • Use netItem.enabledable to control system proxy switch visibility.
  • Only create/show VPN switch pages when the VPN control item has child connections.
  • Keep system proxy pages accessible even when no proxy configuration exists.
dcc-network/qml/PageSystemProxy.qml
dcc-network/qml/PageVPN.qml
Improve proxy configuration change detection so system proxy existence updates correctly for manual and PAC configurations.
  • Treat proxy port changes as configuration changes alongside host changes.
  • Route auto proxy change notifications through queryAutoProxy to refresh the PAC URL and existence state.
network-service-plugin/src/session/networkproxy.cpp
src/proxycontroller.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 ✨

18202781743
18202781743 previously approved these changes Sep 30, 2026
1. Add Net_SysProxyEnabledable flag: the enabledable of
   NetSystemProxyControlItem now follows whether a system proxy
   configuration exists, without affecting whether the menu item
   itself is shown (Net_SysProxyAlwaysShow keeps the item always
   visible in the control center, see BUG-350619).
2. In NetManagerThreadPrivate::doInit, track systemProxyExistChanged
   whenever Net_SysProxyEnabledable is set, and emit the initial
   enabledable state.
3. In NetManagerPrivate::onDataChanged DeviceAvailableChanged, only
   hide the SystemProxyControlItem via updateItemVisible when
   Net_SysProxyAlwaysShow is NOT set; otherwise just update
   enabledable. VPNControlItem keeps the existing hide-by-existence
   behavior (its children are the VPN connections).
4. In PageSystemProxy.qml, drive the switches' presence with
   netItem.enabledable (page: proxyConfigExist ? devCheck : null,
   visible: netItem.enabledable) instead of computing existence from
   raw proxy data.
5. In PageVPN.qml, only show the VPN switches when the VPN control
   item has children (hasVpnConnection).
6. In ProxyController::onProxyChanged, route the "auto" proxyChanged
   signal to queryAutoProxy(): the daemon emits proxyChanged("auto",
   url) when the PAC URL changes, but queryProxyDataByType only
   understands http/https/ftp/socks, so m_autoProxyURL was never
   refreshed and systemProxyExist stayed stale.

Log: When there is no VPN connection or no system proxy
configuration, the VPN and system proxy menu entries no longer show
their switches, while the entries themselves remain accessible for
adding/importing VPN connections or configuring the proxy.

Influence:
1. With no VPN connection and no system proxy config, open the
   network page: the VPN and system proxy entries show no switch
   (arrow only), and both pages can still be opened to add/import
   VPN or configure the proxy.
2. Add a VPN connection (nmcli/import): the VPN switch appears in
   real time; delete all VPN connections: the switch disappears.
3. Configure a manual proxy (any http/https/ftp/socks host) or a PAC
   URL: the system proxy switch appears; clear all proxy values: the
   switch disappears (auto PAC and manual host both covered, and the
   previously stale autoProxy refresh path is fixed).
4. Dock/lock/greeter: system proxy item visibility still follows
   whether a proxy configuration exists (no AlwaysShow flag there),
   unchanged behavior vs before this change.

fix: 不存在VPN连接和系统代理配置时隐藏VPN与系统代理开关

1. 新增 Net_SysProxyEnabledable 标志:NetSystemProxyControlItem 的
   enabledable 跟随是否存在系统代理配置,且不影响菜单项本身是否显示
   (Net_SysProxyAlwaysShow 仍保证控制中心菜单项恒显,见 BUG-350619)。
2. NetManagerThreadPrivate::doInit 中,设置 Net_SysProxyEnabledable
   时跟踪 systemProxyExistChanged,并下发初始 enabledable 状态。
3. NetManagerPrivate::onDataChanged 的 DeviceAvailableChanged 分支,
   仅当未设置 Net_SysProxyAlwaysShow 时才用 updateItemVisible 隐藏
   SystemProxyControlItem;否则只更新 enabledable。VPNControlItem 保留
   原有"按是否存在连接子项显隐"的行为。
4. PageSystemProxy.qml 的开关显隐改为由 netItem.enabledable 驱动
   (page: proxyConfigExist ? devCheck : null, visible: netItem.enabledable),
   不再自行根据原始代理数据计算。
5. PageVPN.qml 仅在 VPN 控制项存在子连接时展示开关(hasVpnConnection)。
6. ProxyController::onProxyChanged 对 "auto" 类型的 proxyChanged 信号
   改走 queryAutoProxy():daemon 在 PAC URL 变化时发出的是
   proxyChanged("auto", url),而 queryProxyDataByType 只识别
   http/https/ftp/socks,导致 m_autoProxyURL 从不刷新、
   systemProxyExist 一直停留在旧值。

Log: 不存在VPN连接或系统代理配置时,VPN 与系统代理菜单项不再展示开关,
菜单项本身仍可点开用于添加/导入VPN或配置代理。

Influence:
1. 无VPN连接且无系统代理配置时打开网络页:VPN 与系统代理菜单项不显示
   开关(仅箭头),仍可进入页面添加/导入VPN或配置代理。
2. 添加一个VPN连接(nmcli/导入):VPN 开关实时出现;删除全部VPN连接:
   开关消失。
3. 配置手动代理(任一 http/https/ftp/socks host)或 PAC URL:系统代理
   开关出现;清空全部代理值:开关消失(自动PAC与手动host均覆盖,并修复了
   此前 autoProxy 刷新不到位的缺陷)。
4. dock/锁屏/greeter:系统代理项仍按是否存在代理配置显隐(不带
   AlwaysShow 标志),行为与改动前一致。

PMS: BUG-378285
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 99 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 代码变更逻辑清晰,正确实现了当不存在VPN连接和系统代理配置时隐藏开关的功能。修复了autoProxy刷新不到位的缺陷,扩展了端口变化检测。无安全漏洞,代码质量良好,注释完整。

提交信息: fix: hide VPN and system proxy switches when no configuration exists
关联Bug: BUG-378285, BUG-350619
修改文件: 7个文件,新增26行,删除17行
分析模式: 全量分析(GitHub PR)


🔍 四维度评分

维度 评分 满分 状态
语法逻辑 25 25 ✅ 通过
代码质量 24 25 ✅ 通过
代码性能 20 20 ✅ 通过
代码安全 30 30 ✅ 通过

详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰

潜在问题:
✅ 未发现明显问题

分析详情:

  • QML 属性绑定正确:hasVpnConnection 使用 !!netItem && netItem.children.length > 0 正确处理了 netItem 为 null 的情况
  • C++ 标志位操作正确:Net_SysProxyEnabledable = 0x10000000 不与现有标志冲突(前一个为 0x08000000)
  • netmanagerthreadprivate.cpp 中条件从 !Net_SysProxyAlwaysShow 改为 Net_SysProxyEnabledable 逻辑正确
  • proxycontroller.cpp 中 "auto" 类型路由修复正确——daemon 发送 proxyChanged("auto", url) 但 queryProxyDataByType 只识别 http/https/ftp/socks
  • networkproxy.cpp 扩展检测 "port" 变化逻辑正确

2. 代码质量 ✅

评价: 代码结构清晰,注释完整

潜在问题:

  1. net-view/operation/netmanager.cpp 第610行,函数 NetManagerPrivate::onDataChanged:条件表达式较长,可读性略受影响。(item->itemType() == NetType::SystemProxyControlItem && !flags().testFlags(NetType::Net_SysProxyAlwaysShow)) || item->itemType() == NetType::VPNControlItem 该条件表达式在一行内包含多个逻辑运算,建议适当拆分或提取为辅助函数以提升可读性

建议:
建议将复杂条件提取为命名变量或辅助函数,如 bool sysProxyCanHide = (item->itemType() == NetType::SystemProxyControlItem && !flags().testFlags(NetType::Net_SysProxyAlwaysShow));

代码亮点:

  • 变量重命名 isHost → isValueChanged 显著提升代码可读性
  • proxycontroller.cpp 中添加了清晰的注释解释 auto proxy 路由的原因
  • nettype.h 中新增 Net_SysProxyEnabledable 标志附带说明注释
  • 版权年份正确更新(2025→2025-2026, 2018-2022→2018-2026)
  • 无重复代码,无调试代码残留

3. 代码性能 ✅

评价: 性能良好,资源使用合理

潜在问题:
✅ 未发现明显问题

分析详情:

  • 变更主要是条件判断和信号路由,性能影响可忽略
  • queryAutoProxy() 替代 queryProxyDataByType() 处理 "auto" 类型,直接查询正确数据,效率更高
  • QML 属性绑定 hasVpnConnection 惰性求值,无性能隐患

4. 代码安全 🔒

评价: 存在0个安全漏洞

🔐 发现 0 个安全漏洞

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

安全漏洞详情:
✅ 未发现安全漏洞

分析详情:

  • 无用户输入处理变更,不存在注入风险
  • 无硬编码密钥或敏感信息
  • 无缓冲区溢出风险
  • 变更纯粹为 UI 可见性控制和信号路由逻辑
  • 无文件路径操作
  • 无网络协议变更

📁 逐文件分析

文件 变更说明 分析结论
dcc-network/qml/PageSystemProxy.qml 将两处 Switch 的 enabled 改为 visible 正确:无代理配置时完全隐藏开关而非仅禁用
dcc-network/qml/PageVPN.qml 新增 hasVpnConnection 属性,条件渲染开关页面 正确:null 守卫完善,无VPN连接时不渲染开关
net-view/operation/netmanager.cpp SystemProxyControlItem 可见性增加 AlwaysShow 判断 正确:AlwaysShow 时仅更新 enabledable 不隐藏
net-view/operation/nettype.h 新增 Net_SysProxyEnabledable 标志 正确:标志值无冲突,各平台 Flags 集合更新合理
net-view/operation/private/netmanagerthreadprivate.cpp 条件从 !AlwaysShow 改为 Enabledable 正确:语义更精确,确保各平台正确连接信号
network-service-plugin/src/session/networkproxy.cpp 重命名变量,扩展 port 变化检测 正确:修复端口变更不触发信号的缺陷
src/proxycontroller.cpp "auto" 类型单独走 queryAutoProxy() 正确:修复 m_autoProxyURL 不刷新的关键缺陷

💡 改进建议代码示例

// netmanager.cpp - 建议将复杂条件提取为命名变量
void NetManagerPrivate::onDataChanged(int dataType, const QString &id, const QVariant &value)
{
    // ...
    NetControlItemPrivate *item = NetItemPrivate::toItem<NetControlItemPrivate>(findItem(id));
    if (item) {
        item->updateenabledable(value.toBool());
        
        // 提取复杂条件为命名变量,提升可读性
        bool isSystemProxy = item->itemType() == NetType::SystemProxyControlItem;
        bool canHideSystemProxy = isSystemProxy && !flags().testFlags(NetType::Net_SysProxyAlwaysShow);
        bool isVpn = item->itemType() == NetType::VPNControlItem;
        
        if (canHideSystemProxy || isVpn) {
            updateItemVisible(item->id(), value.toBool());
            return;
        }
    }
    // ...
}

📋 审查检查清单

  • 已按四维度标准完成代码分析(语法逻辑、代码质量、代码性能、代码安全)
  • 代码安全维度包含"存在0个安全漏洞"
  • 安全漏洞已按等级分类(无漏洞)
  • 包含漏洞对比统计行(新增0/减少0/持平0)
  • 每个维度标记✓/✕与评价词一致
  • 审查结论考虑了 commit message 的目的(修复VPN和系统代理开关显隐行为)
  • 问题定位准确,行号和函数名正确
  • 环境变量使用正确,文件路径无误

本报告由 AI 代码审查工具自动生成

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, caixr23, mhduiy

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

@caixr23
caixr23 merged commit 270cd58 into linuxdeepin:master Sep 30, 2026
14 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.

4 participants