Skip to content

Conversation

@BLumia
Copy link
Member

@BLumia BLumia commented Sep 22, 2025

部分情况下,dock驻留区域的加载早于 AM 对应的模型中的数据就绪,导致驻留加载完毕后因为有效性检查而被过滤,致使托盘区域原本驻留的应用全部未展示. 此提交新增了一个就绪信号,以供在更准确的时机通知驻留信息的加载.

Summary by Sourcery

Delay loading of docked elements until the application model signals readiness to prevent the dock from appearing empty after boot or login.

New Features:

  • Add a ready property and readyChanged signal to AMAppItemModel to indicate when the app model has finished loading
  • Expose an appModelReady property and appModelReadyChanged signal on AppsApplet
  • Introduce an initDockedElements slot in DockGlobalElementModel to reload docked elements upon app model readiness

Bug Fixes:

  • Hold off initial dock population until the application model is ready to avoid filtering out docked apps prematurely

Enhancements:

  • Add a dedicated logging category and debug messages to report docked elements load counts

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 22, 2025

Reviewer's Guide

This PR adds a readiness signal from the application manager model through the AppsApplet to the DockGlobalElementModel, ensuring that dock elements are loaded only after the app model is fully initialized, preventing empty dock states. It implements a new ready property and signal in AMAppItemModel, exposes it via a Q_PROPERTY in AppsApplet, and connects this signal in DockGlobalElementModel to delay loading dock entries until the model is ready, with added debug logging.

Sequence diagram for dock initialization with app model readiness signal

sequenceDiagram
    participant DockGlobalElementModel
    participant DAppletBridge
    participant AppsApplet
    participant AMAppItemModel

    DockGlobalElementModel->>DAppletBridge: Get AppsApplet instance
    DAppletBridge->>AppsApplet: Provide applet()
    AppsApplet->>AMAppItemModel: Initialize
    AMAppItemModel-->>AppsApplet: readyChanged(true)
    AppsApplet-->>DockGlobalElementModel: appModelReadyChanged(true)
    DockGlobalElementModel->>DockGlobalElementModel: initDockedElements(true)
    DockGlobalElementModel->>DockGlobalElementModel: loadDockedElements()
Loading

File-Level Changes

Change Details Files
Introduce a readiness signal in the application item model
  • Add m_ready member, ready() method, readyChanged signal, and Q_PROPERTY in AMAppItemModel
  • Set m_ready to true and emit readyChanged in the model’s initialization callback
applets/dde-apps/amappitemmodel.cpp
applets/dde-apps/amappitemmodel.h
Expose app model readiness in AppsApplet
  • Add Q_PROPERTY(bool appModelReady) with notify signal
  • Implement appModelReady() accessor and connect AMAppItemModel::readyChanged to appModelReadyChanged
applets/dde-apps/appsapplet.cpp
applets/dde-apps/appsapplet.h
Delay loading of dock elements until app model is ready
  • Add DAppletBridge to listen for appModelReadyChanged and connect to new initDockedElements slot
  • Implement initDockedElements slot calling loadDockedElements
  • Add QLoggingCategory and debug logging in loadDockedElements
panels/dock/taskmanager/dockglobalelementmodel.cpp
panels/dock/taskmanager/dockglobalelementmodel.h

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 there - I've reviewed your changes - here's some feedback:

  • In AMAppItemModel, setting the "ready" property via setProperty won’t update m_ready nor emit readyChanged(), so make sure you assign m_ready = true and emit readyChanged(true) when the model is ready.
  • The initial invokeMethod(loadDockedElements) call may still fire before the app model is actually ready, causing duplicate or early loads—consider removing that queued call or guarding it so elements only load once the ready signal arrives.
  • Add error handling or logging for the case where DAppletBridge.applet() returns null to surface issues instead of silently skipping the dock initialization.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In AMAppItemModel, setting the "ready" property via setProperty won’t update m_ready nor emit readyChanged(), so make sure you assign m_ready = true and emit readyChanged(true) when the model is ready.
- The initial invokeMethod(loadDockedElements) call may still fire before the app model is actually ready, causing duplicate or early loads—consider removing that queued call or guarding it so elements only load once the ready signal arrives.
- Add error handling or logging for the case where DAppletBridge.applet() returns null to surface issues instead of silently skipping the dock initialization.

## Individual Comments

### Comment 1
<location> `applets/dde-apps/amappitemmodel.cpp:65-66` </location>
<code_context>
             }
         }
+
+        setProperty("ready", true);
+        qCDebug(appsLog) << "AMAppItemModel is now ready with apps counts:" << rowCount();
     });
 }
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Directly setting the 'ready' property may bypass signal emission.

Use a setter for 'm_ready' that emits 'readyChanged' to ensure listeners are notified of state changes.

Suggested implementation:

```cpp
        setReady(true);
        qCDebug(appsLog) << "AMAppItemModel is now ready with apps counts:" << rowCount();

```

```cpp
void AMAppItemModel::setReady(bool ready)
{
    if (m_ready == ready)
        return;
    m_ready = ready;
    emit readyChanged(m_ready);
}

bool AMAppItemModel::ready() const
{
    return m_ready;

```

You must ensure that:
1. The `setReady(bool ready)` method is declared in the header file (`amappitemmodel.h`).
2. The `readyChanged(bool)` signal is declared in the header file if not already present.
3. Any code relying on the property or signal is updated to use the setter and signal as appropriate.
</issue_to_address>

### Comment 2
<location> `applets/dde-apps/amappitemmodel.h:16` </location>
<code_context>
 {
     Q_OBJECT
-
+    Q_PROPERTY(bool ready MEMBER m_ready READ ready NOTIFY readyChanged)
 public:
     explicit AMAppItemModel(QObject *parent = nullptr);
</code_context>

<issue_to_address>
**suggestion:** Using MEMBER in Q_PROPERTY with custom signal may not emit signal automatically.

To ensure 'readyChanged' is emitted when 'm_ready' changes, update 'm_ready' only via a setter that emits the signal.

Suggested implementation:

```c
    Q_PROPERTY(bool ready READ ready WRITE setReady NOTIFY readyChanged)

```

```c
signals:
    void readyChanged(bool);

public:
    void setReady(bool ready);

private:
    bool m_ready;

```

You must implement the `setReady(bool ready)` method in the corresponding `.cpp` file. The implementation should look like:

void AMAppItemModel::setReady(bool ready)
{
    if (m_ready == ready)
        return;
    m_ready = ready;
    emit readyChanged(m_ready);
}

Also, ensure all updates to `m_ready` use `setReady()` instead of direct assignment.
</issue_to_address>

### Comment 3
<location> `panels/dock/taskmanager/dockglobalelementmodel.cpp:153-155` </location>
<code_context>
                 }
             });

+    DS_NAMESPACE::DAppletBridge ddeAppsBridge("org.deepin.ds.dde-apps");
+    auto ddeAppsApplet = ddeAppsBridge.applet();
+    if (ddeAppsApplet) {
+        connect(ddeAppsApplet, SIGNAL(appModelReadyChanged(bool)), this, SLOT(initDockedElements(bool)));
+    }
+
</code_context>

<issue_to_address>
**suggestion:** Using old SIGNAL/SLOT syntax may miss compile-time checks.

Switch to the Qt5 signal-slot syntax for improved type safety: connect(ddeAppsApplet, &AppsApplet::appModelReadyChanged, this, &DockGlobalElementModel::initDockedElements);

```suggestion
    if (ddeAppsApplet) {
        connect(ddeAppsApplet, &AppsApplet::appModelReadyChanged, this, &DockGlobalElementModel::initDockedElements);
    }
```
</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 on lines +65 to +66
setProperty("ready", true);
qCDebug(appsLog) << "AMAppItemModel is now ready with apps counts:" << rowCount();
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): Directly setting the 'ready' property may bypass signal emission.

Use a setter for 'm_ready' that emits 'readyChanged' to ensure listeners are notified of state changes.

Suggested implementation:

        setReady(true);
        qCDebug(appsLog) << "AMAppItemModel is now ready with apps counts:" << rowCount();
void AMAppItemModel::setReady(bool ready)
{
    if (m_ready == ready)
        return;
    m_ready = ready;
    emit readyChanged(m_ready);
}

bool AMAppItemModel::ready() const
{
    return m_ready;

You must ensure that:

  1. The setReady(bool ready) method is declared in the header file (amappitemmodel.h).
  2. The readyChanged(bool) signal is declared in the header file if not already present.
  3. Any code relying on the property or signal is updated to use the setter and signal as appropriate.

{
Q_OBJECT

Q_PROPERTY(bool ready MEMBER m_ready READ ready NOTIFY readyChanged)
Copy link

Choose a reason for hiding this comment

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

suggestion: Using MEMBER in Q_PROPERTY with custom signal may not emit signal automatically.

To ensure 'readyChanged' is emitted when 'm_ready' changes, update 'm_ready' only via a setter that emits the signal.

Suggested implementation:

    Q_PROPERTY(bool ready READ ready WRITE setReady NOTIFY readyChanged)
signals:
    void readyChanged(bool);

public:
    void setReady(bool ready);

private:
    bool m_ready;

You must implement the setReady(bool ready) method in the corresponding .cpp file. The implementation should look like:

void AMAppItemModel::setReady(bool ready)
{
if (m_ready == ready)
return;
m_ready = ready;
emit readyChanged(m_ready);
}

Also, ensure all updates to m_ready use setReady() instead of direct assignment.

@BLumia
Copy link
Member Author

BLumia commented Sep 22, 2025

测试包:

shell-pms-334171.zip

robertkill
robertkill previously approved these changes Sep 22, 2025
}
}

setProperty("ready", true);
Copy link
Contributor

Choose a reason for hiding this comment

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

这种行为,有没有model提供的机制呀,初始化的时候,是初始化里面的数据,能使用beginResetModel这种么,

Copy link
Member Author

Choose a reason for hiding this comment

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

可以用reset,相当于要改model初始化那边填入数据时的形式,暂时没排查有没有别的影响。

Copy link
Member Author

Choose a reason for hiding this comment

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

QStandardItemModel 没提供比较方便的 reset 的方式,加上暂时未排查是否有别的影响,暂时不改为完全依赖 reset 状态来载入任务栏驻留状态的写法。

部分情况下,dock驻留区域的加载早于 AM 对应的模型中的数据就绪,导致驻留
加载完毕后因为有效性检查而被过滤,致使托盘区域原本驻留的应用全部未展
示. 此提交新增了一个就绪信号,以供在更准确的时机通知驻留信息的加载.

PMS: BUG-334171
Log:
@deepin-ci-robot
Copy link

deepin pr auto review

根据提供的git diff,我来对代码进行审查,并提出改进意见:

  1. 代码逻辑和结构:

优点:

  • 增加了AMAppItemModel的ready状态管理,使模型加载状态可追踪
  • 通过Q_PROPERTY暴露了ready状态,便于Qt元对象系统访问
  • 添加了信号机制,实现了状态变化的通知机制
  • 使用了QLoggingCategory进行日志管理,提高了日志的可控性

改进建议:

  • 在AMAppItemModel中,m_ready的初始化应该在构造函数初始化列表中完成,而不是单独赋值
  • AppsApplet中的m_appModelReady成员变量似乎未被使用,可以考虑移除
  • DockGlobalElementModel中的initDockedElements函数参数unused未被使用,应该移除该参数
  1. 代码质量:

优点:

  • 代码结构清晰,类之间的关系明确
  • 使用了Qt的信号槽机制进行组件间通信
  • 遵循了Qt的命名约定

改进建议:

  • 在AMAppItemModel中,当模型加载完成时,应该先设置m_ready为true,再发出信号,这样可以确保状态的一致性
  • 在DockGlobalElementModel中,loadDockedElements函数过长,可以考虑拆分为更小的函数
  • 建议添加更多的错误处理机制,特别是在处理DBus调用时
  1. 代码性能:

优点:

  • 使用了Qt的模型/视图架构,提高了数据管理的效率
  • 通过信号槽机制实现了组件间的松耦合

改进建议:

  • 在AMAppItemModel中,appItem函数使用线性搜索,如果项目数量很大,可以考虑使用QHash来存储appItem,以提高查找效率
  • 在DockGlobalElementModel中,loadDockedElements函数每次都会重新加载所有数据,可以考虑增量更新机制
  1. 代码安全:

优点:

  • 使用了Qt的类型安全机制
  • 添加了日志记录,便于问题追踪

改进建议:

  • 在处理DBus调用时,应该添加更多的错误检查和异常处理
  • 在AMAppItemModel中,对m_manager的访问应该添加空指针检查
  • 在AppsApplet中,对m_appModel的访问也应该添加空指针检查

总结:
这些改动主要是为了增加模型加载状态的可追踪性,并改进了日志记录。整体来说,代码质量有所提升,但仍有一些可以优化的地方,特别是在性能和错误处理方面。建议按照上述建议进行改进,以提高代码的健壮性和可维护性。

@BLumia BLumia requested a review from 18202781743 September 23, 2025 03:11
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@BLumia BLumia merged commit 6c9ba31 into linuxdeepin:master Sep 23, 2025
10 of 11 checks passed
@BLumia BLumia deleted the pms-334171 branch September 23, 2025 05:05
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.

4 participants