Skip to content

Conversation

@pengfeixx
Copy link
Contributor

@pengfeixx pengfeixx commented Jan 5, 2026

Fix taskbar failing to cancel app pinning

Log: Fix taskbar failing to cancel app pinning
pms: BUG-343145

Summary by Sourcery

Bug Fixes:

  • Ensure canceling an app's docked/pinned state succeeds even when the corresponding app item cannot be obtained from the desktop file parser.

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 5, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Ensures that canceling app pinning (undocking) correctly updates the docked state even when no AppItem instance is available, preventing the taskbar operation from failing.

Sequence diagram for undocking when AppItem is missing

sequenceDiagram
    actor User
    participant TaskbarUI
    participant TaskManager
    participant DesktopfileParser

    User->>TaskbarUI: cancelPin(appID)
    TaskbarUI->>TaskManager: RequestUndock(appID)
    TaskManager->>DesktopfileParser: loadApp(appID)
    TaskManager->>DesktopfileParser: getAppItem()
    DesktopfileParser-->>TaskManager: null AppItem
    alt AppItem is null
        TaskManager->>DesktopfileParser: setDocked(false)
        TaskManager-->>TaskbarUI: true
        TaskbarUI-->>User: undockSucceeded
    end
Loading

Class diagram for TaskManager undocking flow update

classDiagram
    class TaskManager {
        +bool RequestUndock(QString appID)
    }

    class DesktopfileParser {
        +QPointer~AppItem~ getAppItem()
        +void setDocked(bool docked)
    }

    class AppItem {
        +void setDocked(bool docked)
    }

    TaskManager --> DesktopfileParser : uses
    DesktopfileParser --> AppItem : creates_or_owns
Loading

File-Level Changes

Change Details Files
Fix undock (cancel pinning) behavior when no AppItem is returned from the desktop file parser.
  • Adjust RequestUndock to treat a null AppItem as a successful undock operation rather than a failure
  • Explicitly set the desktop file parser's docked state to false when AppItem is null to keep state consistent
panels/dock/taskmanager/taskmanager.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

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 left some high level feedback:

  • Consider moving desktopfileParser->setDocked(false); outside the if (appitem.isNull()) branch so that the docked state is updated consistently regardless of whether an AppItem exists, and the condition only controls the return value and appitem->setDocked(false) call.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider moving `desktopfileParser->setDocked(false);` outside the `if (appitem.isNull())` branch so that the docked state is updated consistently regardless of whether an `AppItem` exists, and the condition only controls the return value and `appitem->setDocked(false)` call.

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

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, pengfeixx

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

Fix taskbar failing to cancel app pinning

Log: Fix taskbar failing to cancel app pinning
pms: BUG-343145
@deepin-ci-robot
Copy link

deepin pr auto review

我来帮你分析这段代码的修改:

  1. 代码逻辑分析:
    这段代码是处理从任务栏取消停靠应用的逻辑。原来的逻辑是:
  • 如果找不到对应的 AppItem,直接返回 false
  • 如果找到 AppItem,调用 setDocked(false) 并返回 true

修改后的逻辑是:

  • 如果找不到对应的 AppItem,先设置 desktopfileParser 的 docked 状态为 false,然后返回 true
  • 如果找到 AppItem,仍然调用 setDocked(false) 并返回 true
  1. 存在的问题和改进建议:

a) 逻辑一致性:

  • 修改后的代码在找不到 AppItem 时返回 true,这可能会让调用者误以为操作成功
  • 建议统一返回值的语义:要么都返回操作是否成功,要么都返回操作是否完成

b) 错误处理:

  • 当找不到 AppItem 时,直接设置 desktopfileParser 的状态可能会造成状态不一致
  • 建议添加日志记录,方便调试和追踪问题

c) 代码安全性:

  • 使用 QPointer 是好的做法,可以防止悬空指针
  • 但建议在设置状态前检查 desktopfileParser 是否有效
  1. 改进后的代码建议:
bool TaskManager::RequestUndock(QString appID)
{
    if (!desktopfileParser) {
        qWarning() << "DesktopFileParser is null";
        return false;
    }
    
    QPointer<AppItem> appitem = desktopfileParser->getAppItem();
    if (appitem.isNull()) {
        // 记录日志
        qWarning() << "Cannot find AppItem for appID:" << appID;
        // 设置解析器状态
        desktopfileParser->setDocked(false);
        return false; // 建议返回 false 表示未找到应用
    }
    
    appitem->setDocked(false);
    return true;
}
  1. 主要改进点:
  • 添加了对 desktopfileParser 的空指针检查
  • 添加了日志记录,便于调试
  • 统一了返回值的语义(true 表示成功找到并处理应用,false 表示未找到或出错)
  • 保持了原有的状态设置逻辑

这样的修改使代码更加健壮,更容易维护,并且提供了更好的错误处理机制。

@pengfeixx
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Jan 5, 2026

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit 118f9c1 into linuxdeepin:master Jan 5, 2026
8 of 11 checks passed
@pengfeixx pengfeixx deleted the fix-343145 branch January 5, 2026 10:00
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