Skip to content

fix: pass activation token to control center navigation#572

Open
18202781743 wants to merge 1 commit into
linuxdeepin:masterfrom
18202781743:master
Open

fix: pass activation token to control center navigation#572
18202781743 wants to merge 1 commit into
linuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743

@18202781743 18202781743 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor
  1. Replace direct call to m_manager->exec(NetManager::GoToControlCenter, "") with m_manager->gotoControlCenter(token)
  2. Retrieve XDG_ACTIVATION_TOKEN from environment for proper window
    activation chain
  3. Fix focus issue when opening control center from network menu

Log: Fixed control center window focus when navigating from network menu

Influence:

  1. Test opening control center via network tray menu on different
    desktop environments
  2. Verify control center window is properly focused on activation
  3. Test the navigation when launched from various contexts (tray,
    keyboard shortcut)
  4. Verify no regression in other menu item functions (proxy settings,
    etc.)

fix: 传递激活令牌到控制中心导航

  1. 将对 m_manager->exec(NetManager::GoToControlCenter, "") 的直接调用
    替换为 m_manager->gotoControlCenter(token)
  2. 从环境变量获取 XDG_ACTIVATION_TOKEN 以实现正确的窗口激活链
  3. 修复从网络菜单打开控制中心时的焦点问题

Log: 修复从网络菜单打开控制中心时的窗口焦点问题

Influence:

  1. 验证在不同桌面环境通过网络托盘菜单打开控制中心
  2. 验证控制中心窗口在激活时是否正确获得焦点
  3. 测试从不同上下文(托盘、快捷键)启动导航的情况
  4. 验证其他菜单项功能(代理设置等)无回归问题

PMS: BUG-367651

Summary by Sourcery

Pass XDG activation token when navigating from the network status menu to the control center to ensure correct window activation and focus.

Bug Fixes:

  • Resolve control center window focus issues when opened from the network menu by wiring activation tokens into navigation.

Enhancements:

  • Update netstatus menu handling to use a dedicated control center navigation API instead of a generic exec call.

1. Replace direct call to `m_manager->exec(NetManager::GoToControlCenter,
"")` with `m_manager->gotoControlCenter(token)`
2. Retrieve `XDG_ACTIVATION_TOKEN` from environment for proper window
activation chain
3. Fix focus issue when opening control center from network menu

Log: Fixed control center window focus when navigating from network menu

Influence:
1. Test opening control center via network tray menu on different
desktop environments
2. Verify control center window is properly focused on activation
3. Test the navigation when launched from various contexts (tray,
keyboard shortcut)
4. Verify no regression in other menu item functions (proxy settings,
etc.)

fix: 传递激活令牌到控制中心导航

1. 将对 `m_manager->exec(NetManager::GoToControlCenter, "")` 的直接调用
替换为 `m_manager->gotoControlCenter(token)`
2. 从环境变量获取 `XDG_ACTIVATION_TOKEN` 以实现正确的窗口激活链
3. 修复从网络菜单打开控制中心时的焦点问题

Log: 修复从网络菜单打开控制中心时的窗口焦点问题

Influence:
1. 验证在不同桌面环境通过网络托盘菜单打开控制中心
2. 验证控制中心窗口在激活时是否正确获得焦点
3. 测试从不同上下文(托盘、快捷键)启动导航的情况
4. 验证其他菜单项功能(代理设置等)无回归问题

PMS: BUG-367651
@sourcery-ai

sourcery-ai Bot commented Jul 1, 2026

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

Reviewer's Guide

Updates network menu handling so that opening the Control Center passes through the XDG activation token and uses a dedicated navigation API, fixing focus behavior when launched from the network tray.

Sequence diagram for passing XDG activation token to Control Center navigation

sequenceDiagram
    actor User
    participant NetStatus
    participant NetManager
    participant ControlCenter

    User->>NetStatus: invokeMenuItem(MenuSettings)
    NetStatus->>NetStatus: qEnvironmentVariable(XDG_ACTIVATION_TOKEN)
    NetStatus->>NetManager: gotoControlCenter(token)
    NetManager->>ControlCenter: gotoControlCenter(token)
    ControlCenter-->>User: focused window activated
Loading

File-Level Changes

Change Details Files
Use activation-aware navigation API for opening Control Center from network menu
  • Replaced direct exec-based navigation to the Control Center with a call to a dedicated gotoControlCenter(token) API
  • Read XDG_ACTIVATION_TOKEN from the environment and passed it to the navigation call to preserve proper window activation/focus chain
  • Adjusted switch-case for MenuSettings handling to use scoped block and ensured no behavior changes for other menu items
net-view/window/netstatus.cpp
Update SPDX copyright header
  • Extended the SPDX copyright year range to 2026 in netstatus.cpp
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 left some high level feedback:

  • Consider handling the case where XDG_ACTIVATION_TOKEN is empty or unset (e.g., Wayland vs. X11) by falling back to the previous exec(NetManager::GoToControlCenter, "") behavior or a suitable default to avoid changing behavior in non-Wayland environments.
  • The MenuSettings case block formatting (} break;) is slightly inconsistent with the surrounding switch cases; aligning the brace and break with the project's usual style would improve readability.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider handling the case where `XDG_ACTIVATION_TOKEN` is empty or unset (e.g., Wayland vs. X11) by falling back to the previous `exec(NetManager::GoToControlCenter, "")` behavior or a suitable default to avoid changing behavior in non-Wayland environments.
- The `MenuSettings` case block formatting (`}   break;`) is slightly inconsistent with the surrounding switch cases; aligning the brace and `break` with the project's usual style would improve readability.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, 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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码完美修复了Wayland环境下控制中心窗口激活焦点缺失的问题
逻辑完全正确且符合Wayland标准协议规范,无任何扣分项

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

NetStatus::invokeMenuItem 函数的 MenuItemKey::MenuSettings 分支中,增加了花括号限定局部变量 token 的作用域,使用 qEnvironmentVariable 正确读取环境变量并传递给新接口,语法与逻辑均无误
建议:保持现有实现

  • 2.代码质量(良好)✓

代码修改精准且克制,仅针对焦点激活问题进行最小化修改,通过引入局部作用域避免了变量污染,同时更新了版权年份,符合规范
建议:保持现有实现

  • 3.代码性能(高效)✓

qEnvironmentVariable 仅在用户点击设置菜单时触发一次轻量级的字符串环境变量读取操作,无额外系统调用或资源消耗,无性能问题
建议:保持现有实现

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码遵循Wayland安全激活协议,XDG_ACTIVATION_TOKEN 作为由Compositor生成的安全令牌被原样提取并通过进程间通信传递,不涉及命令拼接、Shell执行或路径遍历,整体安全无风险

  • 建议:保持现有实现

■ 【改进建议代码示例】

// 当前代码已为最佳实践,无需额外修改,此处展示完整上下文以供校验编译
void NetStatus::invokeMenuItem(const QString &menuId)
{
    // ... 其他分支逻辑
    case MenuItemKey::MenuProxyDisabled:
        m_manager->setProxyEnabled(false);
        break;
    case MenuItemKey::MenuSettings: {
        const auto token = qEnvironmentVariable("XDG_ACTIVATION_TOKEN");
        m_manager->gotoControlCenter(token);
    }   break;
    default:
        break;
    }
    // ...
}

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