Skip to content

fix: Optimized tray window icon sorting#1489

Open
JWWTSL wants to merge 1 commit intolinuxdeepin:masterfrom
JWWTSL:master
Open

fix: Optimized tray window icon sorting#1489
JWWTSL wants to merge 1 commit intolinuxdeepin:masterfrom
JWWTSL:master

Conversation

@JWWTSL
Copy link
Contributor

@JWWTSL JWWTSL commented Mar 9, 2026

log: TraySortOrderModel::registerToSection() used prepend() to insert newly registered tray items at the beginning of the list, causing tray icons to display in launch order rather than saved order after application restart. Changed prepend() to append(), adding newly registered tray items to the end of the list. This preserves the positional order of existing items, ensuring tray icons display in their last-saved positions.

pms: bug-299965

Summary by Sourcery

Bug Fixes:

  • Ensure newly registered tray icons are appended after existing ones so icons appear in the last-saved order after application restart.

log: TraySortOrderModel::registerToSection() used prepend() to insert newly registered tray items at the beginning of the list, causing tray icons to display in launch order rather than saved order after application restart. Changed prepend() to append(), adding newly registered tray items to the end of the list. This preserves the positional order of existing items, ensuring tray icons display in their last-saved positions.

pms: bug-299965
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: JWWTSL

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

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 9, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts tray item registration order so new tray icons are added to the end of the section, preserving the saved ordering of existing tray icons across application restarts.

Sequence diagram for tray icon registration with optimized sorting

sequenceDiagram
    actor User
    participant SystemTray
    participant TraySortOrderModel
    participant SectionList

    User->>SystemTray: Launch application
    SystemTray->>TraySortOrderModel: registerToSection(surfaceId, sectionId)
    TraySortOrderModel->>SectionList: contains(surfaceId)?
    alt surfaceId not in section
        SectionList-->>TraySortOrderModel: false
        TraySortOrderModel->>SectionList: append(surfaceId)
    else surfaceId already in section
        SectionList-->>TraySortOrderModel: true
        TraySortOrderModel-->>SystemTray: no change
    end
    SystemTray-->>User: Show tray icons in last saved order
Loading

File-Level Changes

Change Details Files
Change tray item registration to append new items instead of prepending, preserving existing tray icon order.
  • Update TraySortOrderModel::registerToSection to use append when inserting a new surfaceId into a section list
  • Add inline comments explaining that new tray items are added to the end to maintain the positional order of existing tray items across restarts
panels/dock/tray/traysortordermodel.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:

  • The new inline comments are in Chinese; consider aligning the comment language with the rest of the file/repository for consistency and easier maintenance.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new inline comments are in Chinese; consider aligning the comment language with the rest of the file/repository for consistency and easier maintenance.

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

deepin pr auto review

这段代码修改的目的是调整托盘图标在配置列表中的插入顺序。以下是对该 git diff 的详细审查意见:

1. 语法逻辑

  • 审查结果通过
  • 分析
    • 代码逻辑从 section->prepend(surfaceId)(添加到头部)修改为 section->append(surfaceId)(添加到尾部)。
    • 逻辑上是自洽的。注释解释了意图:将新发现的项添加到列表末尾,而不是头部。
    • 这通常意味着当一个新的应用图标出现在托盘区时,它会被放在现有图标的后面,而不是插入到最前面,从而避免打乱用户已经习惯的图标布局。

2. 代码质量

  • 审查结果良好
  • 分析
    • 注释清晰:新增的中文注释很好地解释了修改的原因("保持已有项的位置顺序")和效果("确保应用重启后...按上次保存的顺序显示"),这对于后续维护非常有帮助。
    • 可读性:代码结构简单,易于理解。

3. 代码性能

  • 审查结果通过
  • 分析
    • 对于 QStringList 或类似的列表容器,append 操作通常的时间复杂度是均摊 $O(1)$(均摊常数时间),或者 $O(n)$(如果是需要频繁重分配内存的链表或向量,但在 Qt 容器中优化较好)。
    • 相比之下,prependQListQStringList 中通常需要移动所有现有元素,时间复杂度为 $O(n)$
    • 改进点:从性能角度看,将 prepend 改为 append 实际上是一个优化,避免了在列表头部插入时可能发生的大量内存移动操作,尤其是在托盘图标数量较多的情况下。

4. 代码安全

  • 审查结果通过
  • 分析
    • 代码在修改前已经检查了 if (!section->contains(surfaceId)),确保了不会重复添加相同的 ID,保证了数据的唯一性。
    • section 指针的有效性在调用此函数前通常由上层逻辑保证(假设调用者已正确初始化),且此处仅涉及列表操作,没有内存泄漏或越界风险。

总结与改进建议

这段修改是一个合理且正向的改进。它解决了新图标插入导致旧图标顺序被打乱的用户体验问题,同时顺便提升了插入操作的效率。

建议:
虽然目前的修改已经很好,但可以进一步确认以下场景以增强健壮性:

  1. 确认容器类型:确保 section 指向的容器类型(推测为 QStringList)在频繁 append 时内存分配策略是高效的(Qt 容器通常没问题)。
  2. 边界检查:虽然当前逻辑看起来没问题,但可以确认 surfaceId 是否为空字符串。如果 surfaceId 可能为空且不应被记录,可以在 contains 检查之前增加 if (surfaceId.isEmpty()) return;。不过,这取决于业务逻辑是否允许空 ID。

总体而言,这是一个高质量的代码提交。

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.

2 participants