Skip to content

Conversation

@18202781743
Copy link
Contributor

@18202781743 18202781743 commented Dec 22, 2025

  1. Removed unused sourceModel and sourceRow variables that were causing
    incorrect behavior
  2. Simplified logic by removing separate handling for active vs docked
    applications
  3. Consolidated all action handling into a single code path using dde-am
  4. Added debug logging for troubleshooting instance requests

The previous implementation had separate code paths for active
applications (using ActiveAppModel) and docked applications (using
DBus). This caused inconsistencies in how applications were launched.
Now all instance requests are handled uniformly through the dde-am
command, ensuring consistent behavior regardless of whether the app is
currently active or docked.

Log: Fixed inconsistent application launching behavior in dock

Influence:

  1. Test clicking on dock icons to launch applications
  2. Test right-click menu actions on dock icons
  3. Verify new instance creation for multi-instance applications
  4. Test dock/undock actions work correctly
  5. Verify close window/close all actions function properly
  6. Check debug logs for instance request tracking

fix: 修复任务栏模型中实例请求处理问题

  1. 移除了导致错误行为的未使用 sourceModel 和 sourceRow 变量
  2. 通过移除活动应用和停靠应用的单独处理逻辑来简化代码
  3. 将所有操作处理统一到使用 dde-am 的单一代码路径中
  4. 添加了调试日志以便排查实例请求问题

之前的实现为活动应用(使用 ActiveAppModel)和停靠应用(使用 DBus)设置
了不同的代码路径,这导致应用程序启动行为不一致。现在所有实例请求都通过
dde-am 命令统一处理,确保无论应用当前是否活动,都能获得一致的行为。

Log: 修复了任务栏中应用程序启动行为不一致的问题

Influence:

  1. 测试点击任务栏图标启动应用程序
  2. 测试任务栏图标的右键菜单操作
  3. 验证多实例应用程序的新实例创建
  4. 测试停靠/取消停靠操作是否正常工作
  5. 验证关闭窗口/关闭所有操作功能正常
  6. 检查调试日志中的实例请求跟踪

PMS: BUG-343311

Summary by Sourcery

Unify dock task manager instance request handling through dde-am for consistent app launch behavior and action processing.

Bug Fixes:

  • Fix inconsistent application launch behavior between active and docked apps in the dock task manager.

Enhancements:

  • Simplify dock instance request logic by removing separate ActiveAppModel and DBus code paths and relying on a single dde-am based flow.
  • Add debug logging for dock instance requests to aid troubleshooting.

Tests:

  • Ensure dock icon clicks, context menu actions, multi-instance launches, dock/undock, and close window/close all behaviors work correctly under the unified instance handling.

1. Removed unused sourceModel and sourceRow variables that were causing
incorrect behavior
2. Simplified logic by removing separate handling for active vs docked
applications
3. Consolidated all action handling into a single code path using dde-am
4. Added debug logging for troubleshooting instance requests

The previous implementation had separate code paths for active
applications (using ActiveAppModel) and docked applications (using
DBus). This caused inconsistencies in how applications were launched.
Now all instance requests are handled uniformly through the dde-am
command, ensuring consistent behavior regardless of whether the app is
currently active or docked.

Log: Fixed inconsistent application launching behavior in dock

Influence:
1. Test clicking on dock icons to launch applications
2. Test right-click menu actions on dock icons
3. Verify new instance creation for multi-instance applications
4. Test dock/undock actions work correctly
5. Verify close window/close all actions function properly
6. Check debug logs for instance request tracking

fix: 修复任务栏模型中实例请求处理问题

1. 移除了导致错误行为的未使用 sourceModel 和 sourceRow 变量
2. 通过移除活动应用和停靠应用的单独处理逻辑来简化代码
3. 将所有操作处理统一到使用 dde-am 的单一代码路径中
4. 添加了调试日志以便排查实例请求问题

之前的实现为活动应用(使用 ActiveAppModel)和停靠应用(使用 DBus)设置
了不同的代码路径,这导致应用程序启动行为不一致。现在所有实例请求都通过
dde-am 命令统一处理,确保无论应用当前是否活动,都能获得一致的行为。

Log: 修复了任务栏中应用程序启动行为不一致的问题

Influence:
1. 测试点击任务栏图标启动应用程序
2. 测试任务栏图标的右键菜单操作
3. 验证多实例应用程序的新实例创建
4. 测试停靠/取消停靠操作是否正常工作
5. 验证关闭窗口/关闭所有操作功能正常
6. 检查调试日志中的实例请求跟踪

PMS: BUG-343311
@sourcery-ai
Copy link

sourcery-ai bot commented Dec 22, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Unifies dock task manager instance request handling to always invoke dde-am, removing separate ActiveAppModel/DBus paths, cleaning up unused variables, and adding debug logging for better traceability of dock actions.

Sequence diagram for unified dock instance request handling

sequenceDiagram
    actor User
    participant DockUI
    participant DockGlobalElementModel
    participant QProcess_dde_am

    User->>DockUI: Click dock icon / select context menu action
    DockUI->>DockGlobalElementModel: requestNewInstance(index, action)

    alt action == DOCK_ACTION_DOCK
        DockGlobalElementModel->>DockGlobalElementModel: requestDock(index, true)
        DockGlobalElementModel-->>DockUI: return
    else action == DOCK_ACTION_UNDOCK
        DockGlobalElementModel->>DockGlobalElementModel: requestDock(index, false)
        DockGlobalElementModel-->>DockUI: return
    else action == DOCK_ACTION_CLOSEWINDOW or DOCK_ACTION_CLOSEALL
        DockGlobalElementModel->>DockGlobalElementModel: requestClose(index, false)
        DockGlobalElementModel-->>DockUI: return
    else other action or empty action
        DockGlobalElementModel->>DockGlobalElementModel: qDebug(Requesting new instance, id)
        DockGlobalElementModel->>QProcess_dde_am: start("dde-am", [--by-user, id, action])
        QProcess_dde_am-->>DockGlobalElementModel: waitForFinished()
        DockGlobalElementModel-->>DockUI: return
    end
Loading

Updated class diagram for DockGlobalElementModel instance handling

classDiagram
    class DockGlobalElementModel {
        -m_data
        +requestNewInstance(index, action)
        +requestDock(index, dock)
        +requestClose(index, closeAll)
    }

    class QProcess {
        +setProcessChannelMode(mode)
        +start(program, arguments)
        +waitForFinished()
    }

    class DdeAmCommand {
        +program : string
        +arguments : list
        +execute(by_user, id, action)
    }

    DockGlobalElementModel --> QProcess : uses
    DockGlobalElementModel --> DdeAmCommand : invokes dde-am

    class ActiveAppModel
    class ApplicationManager1Application

    DockGlobalElementModel ..> ActiveAppModel : removed_dependency
    DockGlobalElementModel ..> ApplicationManager1Application : removed_dbus_launch_path
Loading

File-Level Changes

Change Details Files
Unify all dock instance and action handling through dde-am instead of split ActiveAppModel/DBus logic.
  • Remove retrieval of source model and row from stored data, eliminating now-unused variables.
  • Handle dock, undock, and close actions first and early-return, regardless of app active/docked state.
  • For all remaining actions (including the previously special-cased empty action), synchronously execute dde-am --by-user <id> <action> via QProcess.
  • Delete the conditional branch that routed empty actions to ActiveAppModel or DBus Launch, ensuring a single launch/activate code path.
panels/dock/taskmanager/dockglobalelementmodel.cpp
Improve observability of instance requests from the dock model.
  • Add a qDebug log line at the start of requestNewInstance to print index, action, and application id for each request.
panels/dock/taskmanager/dockglobalelementmodel.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

@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码变更进行审查:

  1. 代码逻辑变更分析:
    原代码处理了三种情况:
  • 特殊动作(DOCK_ACTION_DOCK、DOCK_ACTION_UNDOCK、DOCK_ACTION_CLOSEWINDOW、DOCK_ACTION_CLOSEALL)
  • 应用自定义动作
  • 空动作(启动/激活应用)

新代码将后两种情况合并,统一使用dde-am命令处理。

  1. 改进建议:

a) 代码逻辑问题:

  • 新代码移除了对sourceModel和sourceRow的使用,但这两个变量可能包含重要的上下文信息
  • 将应用启动和自定义动作都统一通过dde-am处理,可能会增加不必要的进程开销

b) 错误处理:

  • 缺少对QProcess执行结果的检查
  • 没有处理dde-am命令执行失败的情况

c) 性能考虑:

  • 每次都创建新的QProcess对象,可能影响性能
  • waitForFinished()会阻塞主线程

d) 安全性:

  • 没有对id和action参数进行验证
  • 直接执行外部命令可能存在安全风险
  1. 具体改进建议:
void DockGlobalElementModel::requestNewInstance(const QModelIndex &index, const QString &action)
{
    if (!index.isValid()) {
        qWarning(dockGlobalElementModelLog) << "Invalid index provided";
        return;
    }

    auto data = m_data.value(index.row());
    if (data.empty()) {
        qWarning(dockGlobalElementModelLog) << "No data found for index:" << index;
        return;
    }

    auto id = std::get<0>(data);
    if (id.isEmpty()) {
        qWarning(dockGlobalElementModelLog) << "Empty application ID";
        return;
    }

    qDebug(dockGlobalElementModelLog) << "Requesting new instance for index:" << index 
                                      << "with action:" << action 
                                      << "id:" << id;

    // Handle special actions first
    if (action == DOCK_ACTION_DOCK) {
        requestDock(index);
        return;
    } else if (action == DOCK_ACTION_UNDOCK) {
        requestUndock(index);
        return;
    } else if (action == DOCK_ACTION_CLOSEWINDOW || action == DOCK_ACTION_CLOSEALL) {
        requestClose(index, false);
        return;
    }

    // 使用QProcess::startDetached避免阻塞主线程
    bool success = QProcess::startDetached("dde-am", {"--by-user", id, action});
    if (!success) {
        qWarning(dockGlobalElementModelLog) << "Failed to execute dde-am command";
        // 可以考虑回退到原来的实现
        handleFallbackLaunch(id);
    }
}

void DockGlobalElementModel::handleFallbackLaunch(const QString &id)
{
    QString dbusPath = QStringLiteral("/org/desktopspec/ApplicationManager1/") + escapeToObjectPath(id);
    using Application = org::desktopspec::ApplicationManager1::Application;
    Application appInterface(QStringLiteral("org.desktopspec.ApplicationManager1"), 
                           dbusPath, 
                           QDBusConnection::sessionBus());

    if (appInterface.isValid()) {
        appInterface.Launch(QString(), QStringList(), QVariantMap());
    } else {
        qWarning(dockGlobalElementModelLog) << "Failed to launch application via DBus:" << id;
    }
}
  1. 主要改进点:
  • 增加了参数有效性检查
  • 使用startDetached替代waitForFinished避免阻塞
  • 添加了错误处理和日志记录
  • 保留了原有的DBus启动方式作为备用方案
  • 分离了核心逻辑到独立函数中,提高代码可维护性
  1. 安全性改进:
  • 添加了输入验证
  • 增加了错误处理
  • 使用了更安全的进程启动方式

这些改进可以提高代码的健壮性、安全性和可维护性,同时保持原有功能的完整性。

Copy link

@sourcery-ai sourcery-ai bot left a comment

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:

  • The new qDebug in requestNewInstance logs the full QModelIndex and fires on every instance request; consider reducing the verbosity or logging only the essential fields (row, id, action) to avoid noisy or expensive debug output in common code paths.
  • By routing all (including empty) actions through dde-am with a synchronous waitForFinished, the UI thread may now block for simple launch/activate operations that previously used DBus/ActiveAppModel; consider using an asynchronous start (e.g., startDetached or avoiding waitForFinished) to keep the dock responsive.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `qDebug` in `requestNewInstance` logs the full `QModelIndex` and fires on every instance request; consider reducing the verbosity or logging only the essential fields (row, id, action) to avoid noisy or expensive debug output in common code paths.
- By routing all (including empty) actions through `dde-am` with a synchronous `waitForFinished`, the UI thread may now block for simple launch/activate operations that previously used DBus/ActiveAppModel; consider using an asynchronous start (e.g., `startDetached` or avoiding `waitForFinished`) to keep the dock responsive.

## Individual Comments

### Comment 1
<location> `panels/dock/taskmanager/dockglobalelementmodel.cpp:423` </location>
<code_context>
         QProcess process;
         process.setProcessChannelMode(QProcess::MergedChannels);
         process.start("dde-am", {"--by-user", id, action});
         process.waitForFinished();
-        return;
-    }
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Synchronous `waitForFinished()` now potentially blocks the UI for common actions.

Previously, `waitForFinished()` only ran for non-empty actions; now it also runs for the default (empty) action, which is likely the most common path. This can block the UI thread until `dde-am` exits. Consider making this call asynchronous (e.g., use signals instead of `waitForFinished()`) or restrict the synchronous wait to non-interactive or rare actions.
</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.

QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
process.start("dde-am", {"--by-user", id, action});
process.waitForFinished();
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Synchronous waitForFinished() now potentially blocks the UI for common actions.

Previously, waitForFinished() only ran for non-empty actions; now it also runs for the default (empty) action, which is likely the most common path. This can block the UI thread until dde-am exits. Consider making this call asynchronous (e.g., use signals instead of waitForFinished()) or restrict the synchronous wait to non-interactive or rare actions.

@deepin-ci-robot
Copy link

[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

@18202781743 18202781743 merged commit 3bcaa66 into linuxdeepin:master Dec 22, 2025
10 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