Skip to content

refactor: move XdgActivation to pluginitem and simplify dock plugins#468

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
18202781743:xdgactivation
Jun 16, 2026
Merged

refactor: move XdgActivation to pluginitem and simplify dock plugins#468
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
18202781743:xdgactivation

Conversation

@18202781743

@18202781743 18202781743 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor
  1. Remove XdgActivation usage from all dock plugins (airplane,
    bluetooth, brightness, datetime, dnd, eye-comfort, keyboard,
    notification, power, shutdown, sound, wireless-casting)
  2. Move XdgActivation request to PluginItem's invokeMenuItem and
    executeCommand methods
  3. Standardize launching control-center with dde-am command without
    XdgActivation token
  4. Set XDG_ACTIVATION_TOKEN environment variable in pluginitem before
    calling plugin's invokedMenuItem
  5. Simplify command execution by using QProcess with environment
    variable

Log: Refactored XdgActivation handling for dock plugin system

Influence:

  1. Verify all dock plugin settings buttons still open control-center
    correctly
  2. Test that XDG_ACTIVATION_TOKEN is properly set when invoking plugin
    menu items
  3. Verify command execution with XdgActivation token works
  4. Test that plugins without settings (e.g., airplane mode toggle) still
    work
  5. Verify no regressions in dock plugin functionality
  6. Test keyboard layout add layout action

refactor: 将XdgActivation移到pluginitem并简化dock插件

  1. 从所有dock插件中移除XdgActivation使用(飞行模式、蓝牙、亮度、日期时
    间、勿扰、护眼、键盘布局、通知、电源、关机、声音、投屏)
  2. 将XdgActivation请求移动到PluginItem的invokeMenuItem和executeCommand方
    法中
  3. 标准化使用dde-am命令启动控制中心,不再传递XdgActivation令牌
  4. 在调用插件invokedMenuItem之前,在pluginitem中设置XDG_ACTIVATION_TOKEN
    环境变量
  5. 通过使用带环境变量的QProcess简化命令执行

Log: 重构了dock插件系统的XdgActivation处理

Influence:

  1. 验证所有dock插件设置按钮仍然正确打开控制中心
  2. 测试调用插件菜单项时是否正确设置XDG_ACTIVATION_TOKEN
  3. 验证带XdgActivation令牌的命令执行是否正常
  4. 测试无设置的插件(如飞行模式切换)是否仍然正常工作
  5. 验证dock插件功能没有回归问题
  6. 测试键盘布局添加布局的操作

Summary by Sourcery

Centralize XdgActivation handling in the dock plugin framework and standardize how dock plugins launch the control center and external commands.

Enhancements:

  • Move XdgActivation token retrieval into PluginItem for both menu invocation and command execution, setting XDG_ACTIVATION_TOKEN only around plugin callbacks.
  • Simplify dock plugins by removing per-plugin XdgActivation logic and updating them to launch the control center via a unified dde-am command pattern.

1. Remove XdgActivation usage from all dock plugins (airplane,
bluetooth, brightness, datetime, dnd, eye-comfort, keyboard,
notification, power, shutdown, sound, wireless-casting)
2. Move XdgActivation request to PluginItem's invokeMenuItem and
executeCommand methods
3. Standardize launching control-center with dde-am command without
XdgActivation token
4. Set XDG_ACTIVATION_TOKEN environment variable in pluginitem before
calling plugin's invokedMenuItem
5. Simplify command execution by using QProcess with environment
variable

Log: Refactored XdgActivation handling for dock plugin system

Influence:
1. Verify all dock plugin settings buttons still open control-center
correctly
2. Test that XDG_ACTIVATION_TOKEN is properly set when invoking plugin
menu items
3. Verify command execution with XdgActivation token works
4. Test that plugins without settings (e.g., airplane mode toggle) still
work
5. Verify no regressions in dock plugin functionality
6. Test keyboard layout add layout action

refactor: 将XdgActivation移到pluginitem并简化dock插件

1. 从所有dock插件中移除XdgActivation使用(飞行模式、蓝牙、亮度、日期时
间、勿扰、护眼、键盘布局、通知、电源、关机、声音、投屏)
2. 将XdgActivation请求移动到PluginItem的invokeMenuItem和executeCommand方
法中
3. 标准化使用dde-am命令启动控制中心,不再传递XdgActivation令牌
4. 在调用插件invokedMenuItem之前,在pluginitem中设置XDG_ACTIVATION_TOKEN
环境变量
5. 通过使用带环境变量的QProcess简化命令执行

Log: 重构了dock插件系统的XdgActivation处理

Influence:
1. 验证所有dock插件设置按钮仍然正确打开控制中心
2. 测试调用插件菜单项时是否正确设置XDG_ACTIVATION_TOKEN
3. 验证带XdgActivation令牌的命令执行是否正常
4. 测试无设置的插件(如飞行模式切换)是否仍然正常工作
5. 验证dock插件功能没有回归问题
6. 测试键盘布局添加布局的操作
@sourcery-ai

sourcery-ai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Reviewer's Guide

Centralizes XdgActivation handling in PluginItem and removes per-plugin logic while standardizing how dock plugins launch control-center via dde-am and execute commands with XDG_ACTIVATION_TOKEN set via QProcess.

Sequence diagram for PluginItem invokeMenuItem central XdgActivation handling

sequenceDiagram
    participant PluginItem
    participant XdgActivation as tray_XdgActivation
    participant Environment
    participant PluginsItemInterface

    PluginItem->>XdgActivation: requestToken()
    XdgActivation-->>PluginItem: tokenReady(token)
    alt token not empty
        PluginItem->>Environment: qputenv(XDG_ACTIVATION_TOKEN, token)
        PluginItem->>PluginsItemInterface: invokedMenuItem(m_itemKey, menuId, checked)
        PluginItem->>Environment: qunsetenv(XDG_ACTIVATION_TOKEN)
    else token empty
        PluginItem->>PluginsItemInterface: invokedMenuItem(m_itemKey, menuId, checked)
    end
    PluginItem->>XdgActivation: deleteLater()
Loading

Sequence diagram for PluginItem executeCommand with XDG_ACTIVATION_TOKEN

sequenceDiagram
    participant PluginItem
    participant XdgActivation as tray_XdgActivation
    participant QProcess

    PluginItem->>XdgActivation: requestToken()
    XdgActivation-->>PluginItem: tokenReady(token)
    PluginItem->>QProcess: QProcess()
    PluginItem->>QProcess: setProcessEnvironment(systemEnvironment + XDG_ACTIVATION_TOKEN)
    PluginItem->>QProcess: startDetached(program, commandList)
    PluginItem->>XdgActivation: deleteLater()
Loading

File-Level Changes

Change Details Files
Centralize XdgActivation handling in PluginItem for menu actions and command execution.
  • Add tray::XdgActivation usage in PluginItem::invokeMenuItem to request a token before invoking plugin menu items.
  • Set and unset XDG_ACTIVATION_TOKEN around plugin invokedMenuItem calls based on the received token.
  • Refactor executeCommand to request an activation token, prepare a QProcess with a copied environment, insert XDG_ACTIVATION_TOKEN if present, and startDetached the target program.
src/loader/pluginitem.cpp
Simplify dock plugins by removing direct XdgActivation usage and standardizing control-center launches.
  • Remove xdgactivation.h includes and per-plugin tray::XdgActivation token handling from dock plugins.
  • Update each plugin settings/menu handler to build a simple dde-am argument list with --by-user org.deepin.dde.control-center and the appropriate -p page, without XDG_ACTIVATION_TOKEN injection.
  • Keep non-settings actions (toggles, layout selection, etc.) unchanged while ensuring they still emit existing signals like requestHideApplet where applicable.
plugins/dde-dock/dnd-mode/dndmodeitem.cpp
plugins/dde-dock/airplane-mode/airplanemodeitem.cpp
plugins/dde-dock/bluetooth/bluetoothitem.cpp
plugins/dde-dock/brightness/brightnessitem.cpp
plugins/dde-dock/datetime/datetimeplugin.cpp
plugins/dde-dock/eye-comfort-mode/eyecomfortmodeitem.cpp
plugins/dde-dock/keyboard-layout/dbusadaptors.cpp
plugins/dde-dock/notification/notificationplugin.cpp
plugins/dde-dock/power/powerplugin.cpp
plugins/dde-dock/shutdown/shutdownplugin.cpp
plugins/dde-dock/sound/soundview.cpp
plugins/dde-network-display-ui/plugins/dock-wirelesscasting-plugin/src/wirelesscastingitem.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 found 1 issue, and left some high level feedback:

  • In PluginItem::executeCommand, the QProcess environment you set is never used because you call process.startDetached(program, commandList), which uses the static overload and ignores the instance’s environment; either use the parameterless startDetached() after configuring program/arguments or use a static overload that accepts an environment.
  • The use of qputenv/qunsetenv around XDG_ACTIVATION_TOKEN in PluginItem::invokeMenuItem introduces a global process-wide change that could race or conflict if multiple PluginItem instances invoke menu items concurrently; consider a more localized way to pass the token (e.g., through QProcessEnvironment only for spawned processes) instead of mutating the global environment.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In PluginItem::executeCommand, the QProcess environment you set is never used because you call process.startDetached(program, commandList), which uses the static overload and ignores the instance’s environment; either use the parameterless startDetached() after configuring program/arguments or use a static overload that accepts an environment.
- The use of qputenv/qunsetenv around XDG_ACTIVATION_TOKEN in PluginItem::invokeMenuItem introduces a global process-wide change that could race or conflict if multiple PluginItem instances invoke menu items concurrently; consider a more localized way to pass the token (e.g., through QProcessEnvironment only for spawned processes) instead of mutating the global environment.

## Individual Comments

### Comment 1
<location path="src/loader/pluginitem.cpp" line_range="48-55" />
<code_context>
     if (menuId == SHIFT) {
         AMC_PTR->toggle();
     } else if (menuId == SETTINGS) {
-        auto *activation = new tray::XdgActivation(this);
-        connect(activation, &tray::XdgActivation::tokenReady, this, [activation](const QString &token) {
-            QStringList args {"--by-user", "org.deepin.dde.control-center"};
-            if (!token.isEmpty())
-                args << "-e" << "XDG_ACTIVATION_TOKEN=" + token;
-            args << "--" << "-p" << "network/airplaneMode";
-            QProcess::startDetached("dde-am", args);
-            activation->deleteLater();
-        }, Qt::SingleShotConnection);
-        activation->requestToken();
</code_context>
<issue_to_address>
**issue (bug_risk):** Using qputenv/qunsetenv for XDG_ACTIVATION_TOKEN is process-global and can race with other code.

This approach depends on `invokedMenuItem` being strictly synchronous: any async work it triggers (queued signals, timers, other threads) could observe no token or the wrong token. While the token is set, any unrelated child processes started in this process will also inherit it. Please either scope the token to specific process launches (e.g., via a per-process `QProcessEnvironment` instead of mutating the global environment) or clearly guarantee/document that `invokedMenuItem` is synchronous and does not start background work that launches processes.
</issue_to_address>

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.

Comment thread src/loader/pluginitem.cpp
@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

@18202781743: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
github-pr-review-ci 6fcf3fc link unknown /test github-pr-review-ci

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@18202781743

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot deepin-bot Bot merged commit 977a976 into linuxdeepin:master Jun 16, 2026
8 of 11 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