Skip to content

fix: optimize app properties and trash monitoring - #1690

Open
wjyrich wants to merge 1 commit into
linuxdeepin:masterfrom
wjyrich:task-393709
Open

fix: optimize app properties and trash monitoring#1690
wjyrich wants to merge 1 commit into
linuxdeepin:masterfrom
wjyrich:task-393709

Conversation

@wjyrich

@wjyrich wjyrich commented Aug 5, 2026

Copy link
Copy Markdown
Contributor
  1. Refactor AMAppItem property change handling to process only changed properties instead of re-fetching all data
  2. Add vendor and genericName properties to AppItem model for better app information display
  3. Add TrashMonitor class using GIO to dynamically update trash icon state
  4. Add comprehensive app management methods to AppsApplet (launch, autostart, scale, desktop operations)
  5. Fix AMAppItemModel initialization to prevent duplicate app entries and properly emit ready state
  6. Improve dock global element model to forward data changes from source apps model

Log: Enhanced application properties handling with targeted updates, dynamic trash icon updates, and new applet management APIs

Influence:

  1. Test app icon updates when application metadata changes via D-Bus
  2. Verify trash icon changes when files are added/removed from trash
  3. Test launchApp with and without activation token
  4. Verify sendToDesktop and removeFromDesktop operations work correctly
  5. Test disableScale behavior with various environment configurations
  6. Verify autoStart property updates correctly persist
  7. Test dock app icon updates when app properties change
  8. Verify no duplicate app entries appear under various load scenarios

fix: 优化应用程序属性和回收站监控

  1. 重构 AMAppItem 属性变更处理,仅处理变更的属性而不是重新获取全部数据
  2. 为 AppItem 模型添加厂商和通用名称属性,优化应用信息显示
  3. 添加使用 GIO 的 TrashMonitor 类,动态更新回收站图标状态
  4. 为 AppsApplet 添加全面的应用管理方法(启动、自启动、缩放、桌面操作)
  5. 修复 AMAppItemModel 初始化逻辑,防止重复应用条目并正确发出就绪状态
  6. 改进 dock 全局元素模型,正确转发源应用模型的数据变更

Log: 增强应用属性处理机制,支持定向更新,增加回收站图标动态更新和应用管
理 API

Influence:

  1. 测试通过 D-Bus 修改应用元数据时图标是否及时更新
  2. 验证向回收站添加/删除文件时图标是否自动切换
  3. 测试带激活令牌和不带激活令牌时的应用启动功能
  4. 验证发送到桌面和从桌面移除操作是否正常
  5. 测试各种环境配置下禁用缩放功能的行为
  6. 验证自启动属性修改后是否正确持久化
  7. 测试应用属性变更时 dock 图标是否同步更新
  8. 验证各种加载场景下不会出现重复应用条目

PMS: TASK-393709

Summary by Sourcery

Refine application metadata handling and expose new applet APIs while integrating trash state monitoring and improving dock synchronization.

New Features:

  • Expose AppsApplet QML invokables for launching apps, managing autostart and scaling, and handling desktop shortcuts.
  • Add vendor and genericName roles to AppItem/AppItemModel for richer application metadata in the UI.
  • Introduce a TrashMonitor based on GIO and wire it into AMAppItemModel to keep the trash app icon in sync with trash contents.

Bug Fixes:

  • Prevent duplicate entries in AMAppItemModel initialization and correctly emit the ready state.
  • Fix AMAppItem on-desktop state mapping and ensure actions JSON is cleared when there are no actions.

Enhancements:

  • Optimize AMAppItem property change handling to update only modified fields from DBus PropertiesChanged signals.
  • Propagate app model dataChanged events into DockGlobalElementModel so docked items reflect updated app metadata.
  • Hook up trash icon updates on relevant model changes and adjust build system to link against GLib/GIO.

@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.

Sorry @wjyrich, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: wjyrich

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

sourcery-ai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Reviewer's Guide

Refactors application manager integration to perform targeted AMAppItem property updates, enrich AppItem metadata, introduce a GIO-based TrashMonitor for dynamic trash icon state, extend AppsApplet with app management APIs, fix AMAppItemModel initialization/ready signaling (including trash icon updates and deduplication), and propagate app model data changes into the dock's global element model.

Sequence diagram for AMAppItem targeted property updates

sequenceDiagram
    participant AM_Application as ApplicationManager_Application
    participant DBus as DBus
    participant AMAppItem as AMAppItem
    participant AppItem as AppItem
    participant AppItemModel as AppItemModel

    AM_Application->>DBus: PropertiesChanged
    DBus->>AMAppItem: onPropertyChanged(QDBusMessage)
    AMAppItem->>AMAppItem: qdbus_cast QVariantMap changedProperties
    alt [Name/GenericName/X_Deepin_Vendor changed]
        AMAppItem->>AppItem: setGenericName()
        AMAppItem->>AppItem: setVendor()
        AMAppItem->>AppItem: setAppName()
    end
    alt [Icons changed]
        AMAppItem->>AppItem: setAppIconName()
    end
    alt [Categories changed]
        AMAppItem->>AppItem: setDDECategories()
        AMAppItem->>AppItem: setCategories()
    end
    alt [Actions or ActionName changed]
        AMAppItem->>AMAppItem: updateActions()
        AMAppItem->>AppItem: setActions()
    end
    AppItem-->>AppItemModel: dataChanged(...) emits
Loading

Sequence diagram for TrashMonitor-driven trash icon updates

sequenceDiagram
    participant FS as GIO_trash
    participant GIO as GFileMonitor
    participant TrashMonitor as TrashMonitor
    participant AMAppItemModel as AMAppItemModel
    participant TrashItem as AMAppItem_dde_trash

    FS-->>GIO: file event
    GIO->>TrashMonitor: onTrashChanged(...)
    TrashMonitor->>TrashMonitor: updateState()
    TrashMonitor-->>AMAppItemModel: emptyChanged(bool)
    AMAppItemModel->>AMAppItemModel: updateTrashIcon()
    AMAppItemModel->>TrashItem: setAppIconName(user-trash | user-trash-full)
Loading

File-Level Changes

Change Details Files
Extend AppsApplet to expose app model readiness, category metadata, and rich application management operations for launch, autostart, scaling, and desktop shortcuts.
  • Expose appModel, groupModel, appModelReady, and ddeCategories via Q_PROPERTY and helper accessors
  • Add a private application() helper to resolve AMAppItem by desktopId while normalizing .desktop suffix
  • Implement launchApp() using QProcess to invoke dde-am with optional activation token and error logging
  • Add autoStart()/setAutoStart() and disableScale()/setDisableScale() that manipulate AMAppItem D-Bus properties and environment variables
  • Add isOnDesktop(), sendToDesktop(), and removeFromDesktop() wrappers around AMAppItem D-Bus methods with error-checked replies
applets/dde-apps/appsapplet.cpp
applets/dde-apps/appsapplet.h
Refine AMAppItem to initialize vendor/genericName and handle D-Bus property change signals by updating only changed AppItem fields.
  • Connect to org.freedesktop.DBus.Properties::PropertiesChanged on each AM application object
  • Initialize AppItem::genericName and AppItem::vendor from AM metadata and adjust isOnDesktop key
  • In onPropertyChanged(), filter by Application interface, parse the changed-properties map, and selectively update AppItem fields (names, icons, flags, categories, timestamps, execs, desktop source path, actions, etc.)
  • Ensure actions JSON is cleared when no actions exist instead of retaining stale data
applets/dde-apps/amappitem.cpp
Fix AMAppItemModel initialization, introduce trash monitoring, and ensure trash icon reflects actual trash state without duplicate applications.
  • Create and own a TrashMonitor instance and hook its emptyChanged signal to updateTrashIcon()
  • Enhance GetManagedObjects() completion handler to skip empty paths, deduplicate by DesktopIdRole, and properly set m_ready and emit readyChanged
  • Update AMAppItemModel constructor wiring to append new AMAppItem rows and refresh trash icon on additions and on relevant dataChanged events
  • Implement updateTrashIcon() to toggle dde-trash's icon between user-trash and user-trash-full based on TrashMonitor::isEmpty()
applets/dde-apps/amappitemmodel.cpp
applets/dde-apps/amappitemmodel.h
applets/dde-apps/trashmonitor.cpp
applets/dde-apps/trashmonitor.h
applets/dde-apps/CMakeLists.txt
Extend AppItem/AppItemModel roles to carry vendor and genericName metadata into the model layer.
  • Add VendorRole and GenericNameRole to AppItemModel::Roles and expose them in roleNames()
  • Implement AppItem::vendor/genericName getters and setters that store data under the new roles
applets/dde-apps/appitem.cpp
applets/dde-apps/appitem.h
applets/dde-apps/appitemmodel.cpp
applets/dde-apps/appitemmodel.h
Propagate app model data changes into DockGlobalElementModel so dock entries stay in sync with application metadata.
  • Connect to the apps model's dataChanged signal and, for each affected source row present in m_data, emit corresponding dataChanged from the dock model
  • When DesktopIdRole changes, also mark ItemIdRole as changed so consumers relying on item IDs get notified
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

@wjyrich

wjyrich commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

/test github-pr-review-ci

1. Refactor AMAppItem property change handling to process only changed
properties instead of re-fetching all data
2. Add vendor and genericName properties to AppItem model for better app
information display
3. Add TrashMonitor class using GIO to dynamically update trash icon
state
4. Add comprehensive app management methods to AppsApplet (launch,
autostart, scale, desktop operations)
5. Fix AMAppItemModel initialization to prevent duplicate app entries
and properly emit ready state
6. Improve dock global element model to forward data changes from source
apps model

Log: Enhanced application properties handling with targeted updates,
dynamic trash icon updates, and new applet management APIs

Influence:
1. Test app icon updates when application metadata changes via D-Bus
2. Verify trash icon changes when files are added/removed from trash
3. Test launchApp with and without activation token
4. Verify sendToDesktop and removeFromDesktop operations work correctly
5. Test disableScale behavior with various environment configurations
6. Verify autoStart property updates correctly persist
7. Test dock app icon updates when app properties change
8. Verify no duplicate app entries appear under various load scenarios

fix: 优化应用程序属性和回收站监控

1. 重构 AMAppItem 属性变更处理,仅处理变更的属性而不是重新获取全部数据
2. 为 AppItem 模型添加厂商和通用名称属性,优化应用信息显示
3. 添加使用 GIO 的 TrashMonitor 类,动态更新回收站图标状态
4. 为 AppsApplet 添加全面的应用管理方法(启动、自启动、缩放、桌面操作)
5. 修复 AMAppItemModel 初始化逻辑,防止重复应用条目并正确发出就绪状态
6. 改进 dock 全局元素模型,正确转发源应用模型的数据变更

Log: 增强应用属性处理机制,支持定向更新,增加回收站图标动态更新和应用管
理 API

Influence:
1. 测试通过 D-Bus 修改应用元数据时图标是否及时更新
2. 验证向回收站添加/删除文件时图标是否自动切换
3. 测试带激活令牌和不带激活令牌时的应用启动功能
4. 验证发送到桌面和从桌面移除操作是否正常
5. 测试各种环境配置下禁用缩放功能的行为
6. 验证自启动属性修改后是否正确持久化
7. 测试应用属性变更时 dock 图标是否同步更新
8. 验证各种加载场景下不会出现重复应用条目

PMS: TASK-393709
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:89分

■ 【总体评价】

代码成功修复了DBus属性名不匹配与信号处理死锁问题,但属性变更回调中仍残留潜在的同步调用风险
逻辑基本正确但因信号处理函数中存在非致命的同步DBus调用fallback瑕疵扣11分

■ 【详细分析】

  • 1.语法逻辑(基本正确)✕

amappitem.cpp中的onPropertyChanged函数在处理Name、GenericName等属性变更时,对于未发生变化的属性采用了调用Application::name()等基类同步DBus方法作为fallback。在DBus信号回调中进行同步调用极易引发死锁,原代码正是因此被重构,但重构未彻底消除此风险
潜在问题:当仅GenericName属性变更时,会同步调用Application::name()获取未变更的Name属性,若后端在发送信号时持有锁,将导致线程死锁
建议:在构造函数中将初始属性值缓存为类成员变量,或在onPropertyChanged中仅更新变化的属性,避免任何同步DBus调用;或者为底层QDBusAbstractInterface开启缓存模式

  • 2.代码质量(符合规范)✓

代码命名符合Qt规范,使用匿名命名空间限制作用域,日志分类清晰,新增的TrashMonitor类职责单一
潜在问题:appsapplet.cpp中sendToDesktop与removeFromDesktop函数的异步DBus调用处理逻辑高度重复
建议:提取一个通用的异步DBus调用模板方法,减少代码冗余

  • 3.代码性能(高效)✓

onPropertyChanged从全量同步拉取重构为基于QVariantMap的增量按需更新,彻底消除了原实现中每次信号触发带来的大量DBus同步开销与死锁隐患;TrashMonitor采用GLib原生文件监控替代轮询,性能表现优秀
建议:无

  • 4.代码安全(存在0个安全漏洞)✓

存在 0 个安全漏洞
漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码通过QProcess::start分离参数启动外部进程,有效避免了命令注入风险;环境变量处理仅限字符串分割与拼接,未直接传入Shell执行;GLib C API内存管理严谨,无越界或泄露风险
建议:无

■ 【改进建议代码示例】

// applets/dde-apps/amappitem.h 增加成员变量缓存
// ...
private:
    QString m_cachedName;
    QString m_cachedGenericName;
    QString m_cachedVendor;
// ...

// applets/dde-apps/amappitem.cpp 构造函数中初始化缓存
AMAppItem::AMAppItem(const QDBusObjectPath &path, const ObjectInterfaceMap &source, QObject *parent)
    : Application(AM_DBUS_SERVICE, path.path(), QDBusConnection::sessionBus(), parent)
    , AppItem(DUtil::unescapeFromObjectPath(path.path().split('/').last()), AppItemModel::AppItemType)
{
    // ... 原有初始化代码 ...
    m_cachedName = name;
    m_cachedGenericName = genericName;
    m_cachedVendor = xDeepinVendor;
    // ...
}

// applets/dde-apps/amappitem.cpp onPropertyChanged中消除同步调用
void AMAppItem::onPropertyChanged(const QDBusMessage &msg)
{
    const QList<QVariant> arguments = msg.arguments();
    if (arguments.count() != 3)
        return;

    if (arguments.at(0).toString() != AM_APPLICATION_INTERFACE)
        return;

    QVariantMap changedProperties = qdbus_cast<QVariantMap>(arguments.at(1));

    const auto value = [&changedProperties](QLatin1StringView name) {
        return changedProperties.value(name);
    };
    const auto contains = [&changedProperties](QLatin1StringView name) {
        return changedProperties.contains(name);
    };

    if (contains(QLatin1String("Name")) || contains(QLatin1String("GenericName"))
        || contains(QLatin1String("X_Deepin_Vendor"))) {
        if (contains(QLatin1String("Name")))
            m_cachedName = getLocaleOrDefaultValue(qdbus_cast<QStringMap>(value(QLatin1String("Name"))), locale, DEFAULT_KEY);
        if (contains(QLatin1String("GenericName")))
            m_cachedGenericName = getLocaleOrDefaultValue(qdbus_cast<QStringMap>(value(QLatin1String("GenericName"))), locale, DEFAULT_KEY);
        if (contains(QLatin1String("X_Deepin_Vendor")))
            m_cachedVendor = value(QLatin1String("X_Deepin_Vendor")).toString();

        AppItem::setGenericName(m_cachedGenericName);
        AppItem::setVendor(m_cachedVendor);
        AppItem::setAppName(m_cachedVendor == QLatin1String("deepin") && !m_cachedGenericName.isEmpty() ? m_cachedGenericName : m_cachedName);
    }
    // ... 其他属性按需更新,同样避免使用基类的同步获取方法 ...
}


auto reply = item->SendToDesktop();
auto *watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, watcher, desktopId]() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这异步的,返回true为结果,是不是不合适

return item;
}

bool AppsApplet::launchApp(const QString &desktopId, const QString &activationToken)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这种启动应用,跟其它的am封装的接口不太一样吧,它也放在appsApplet进行提供么,

bool appModelReady() const;
QVariantMap ddeCategories() const;

Q_INVOKABLE bool launchApp(const QString &desktopId, const QString &activationToken = {});

@18202781743 18202781743 Aug 6, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这些Q_INVOKABLE的接口看能不能删掉,这里只保留一些只读的属性,尽量不提供操作接口,担心后续维护问题,


namespace apps
{
TrashMonitor::TrashMonitor(QObject *parent)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这次先不加这个吧,分个提交,这种实现感觉有点儿怪,看之后怎么处理吧,

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