Skip to content

feat: add DesktopSourcePath property to Application DBus interface#338

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
mhduiy:privacy
Mar 5, 2026
Merged

feat: add DesktopSourcePath property to Application DBus interface#338
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
mhduiy:privacy

Conversation

@mhduiy
Copy link
Contributor

@mhduiy mhduiy commented Mar 5, 2026

  1. Added new DBus property "DesktopSourcePath" to expose the source path of desktop files
  2. Extended the ApplicationService class with getter method and change signal
  3. Updated DBus XML interface definition to include the new property
  4. The property provides read-only access to the desktop file source path for external applications

feat: 为应用DBus接口添加DesktopSourcePath属性

  1. 新增DBus属性"DesktopSourcePath"以暴露桌面文件的源路径
  2. 扩展ApplicationService类,添加获取方法和变更信号
  3. 更新DBus XML接口定义以包含新属性
  4. 该属性为外部应用提供对桌面文件源路径的只读访问

PMS: BUG-351621

Summary by Sourcery

Expose the desktop file source path via the application DBus interface.

New Features:

  • Add a read-only DesktopSourcePath property to the Application DBus interface and corresponding getter on ApplicationService.

Enhancements:

  • Emit a desktopSourcePathChanged signal when the application desktop entry is reset.
  • Extend the DBus XML interface definition to declare the new DesktopSourcePath property.

1. Added new DBus property "DesktopSourcePath" to expose the source path
of desktop files
2. Extended the ApplicationService class with getter method and change
signal
3. Updated DBus XML interface definition to include the new property
4. The property provides read-only access to the desktop file source
path for external applications

feat: 为应用DBus接口添加DesktopSourcePath属性

1. 新增DBus属性"DesktopSourcePath"以暴露桌面文件的源路径
2. 扩展ApplicationService类,添加获取方法和变更信号
3. 更新DBus XML接口定义以包含新属性
4. 该属性为外部应用提供对桌面文件源路径的只读访问

PMS: BUG-351621
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 5, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a new read-only DBus property DesktopSourcePath to the Application DBus interface, wiring it through ApplicationService, emitting a change signal on desktop entry reset, and exposing it in the DBus XML interface.

Sequence diagram for reading DesktopSourcePath via DBus

sequenceDiagram
    actor ExternalApplication
    participant DbusClientProxy
    participant ApplicationService
    participant DesktopSource

    ExternalApplication->>DbusClientProxy: getProperty DesktopSourcePath
    DbusClientProxy->>ApplicationService: desktopSourcePath()
    ApplicationService->>DesktopSource: sourcePath()
    DesktopSource-->>ApplicationService: path : QString
    ApplicationService-->>DbusClientProxy: path : QString
    DbusClientProxy-->>ExternalApplication: path : QString
Loading

Sequence diagram for DesktopSourcePath change notification

sequenceDiagram
    participant ApplicationManager1Service
    participant ApplicationService
    participant DesktopSource
    actor ExternalApplication

    ApplicationManager1Service->>ApplicationService: resetEntry(newEntry)
    ApplicationService->>DesktopSource: updateFromEntry(newEntry)
    ApplicationService->>ApplicationService: emit desktopSourcePathChanged()
    ApplicationService-->>ExternalApplication: DBus signal desktopSourcePathChanged
Loading

Updated class diagram for ApplicationService with DesktopSourcePath

classDiagram
    class ApplicationService {
        +QString X_CreatedBy()
        +QString desktopSourcePath()
        +QDBusObjectPath findInstance(QString instanceId)
        +const QString & getLauncher()
        +void xDeepinCreatedByChanged()
        +void execsChanged()
        +void xCreatedByChanged()
        +void desktopSourcePathChanged()
    }

    class DesktopSource {
        +QString sourcePath()
        +void updateFromEntry(DesktopEntry newEntry)
    }

    class DesktopEntry {
    }

    ApplicationService --> DesktopSource : m_desktopSource
    DesktopSource --> DesktopEntry : uses
Loading

File-Level Changes

Change Details Files
Expose desktop file source path via ApplicationService as a new read-only DBus property with change notifications.
  • Add desktopSourcePath() const getter that returns m_desktopSource.sourcePath()
  • Register DesktopSourcePath as a Q_PROPERTY bound to desktopSourcePath() with a NOTIFY signal
  • Declare and emit desktopSourcePathChanged() when the desktop entry is reset so DBus clients can observe updates
src/dbus/applicationservice.cpp
src/dbus/applicationservice.h
Update the DBus XML interface to include the new DesktopSourcePath property.
  • Add DesktopSourcePath string property with read access in org.desktopspec.ApplicationManager1.Application DBus XML definition
api/dbus/org.desktopspec.ApplicationManager1.Application.xml

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:

  • If m_desktopSource can ever be null or otherwise invalid, desktopSourcePath() being noexcept while directly dereferencing it could hide failures; consider guarding access or dropping noexcept to avoid undefined behavior.
  • You only emit desktopSourcePathChanged() from resetEntry; if m_desktopSource can change through other code paths, you may want to emit the signal there as well to keep the DBus property in sync.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- If `m_desktopSource` can ever be null or otherwise invalid, `desktopSourcePath()` being `noexcept` while directly dereferencing it could hide failures; consider guarding access or dropping `noexcept` to avoid undefined behavior.
- You only emit `desktopSourcePathChanged()` from `resetEntry`; if `m_desktopSource` can change through other code paths, you may want to emit the signal there as well to keep the DBus property in sync.

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

这段代码主要是在 D-Bus 接口中添加了一个名为 DesktopSourcePath 的只读属性,用于暴露应用程序的 desktop 文件源路径。以下是对这段代码的详细审查和改进建议:

1. 语法逻辑审查

代码语法正确,符合 C++ 和 Qt 的规范。

  • 增加的属性 DesktopSourcePath 在 XML、头文件和实现文件中保持一致。
  • 使用了 noexcept 标记,符合现有代码风格。
  • 正确使用了 Qt 的属性系统(Q_PROPERTY)和信号机制(NOTIFY)。

潜在逻辑问题

  • 信号触发时机:在 resetEntry 方法中无条件触发了 desktopSourcePathChanged() 信号。如果 m_desktopSource.sourcePath() 在新旧 entry 中没有变化,这会导致不必要的信号触发和 D-Bus 通信开销。建议在触发信号前检查值是否确实发生了变化。

2. 代码质量审查

代码整体质量良好,但有以下改进空间:

  • 命名一致性:现有属性 X_CreatedBy 使用了 X_ 前缀(表示非标准扩展属性),而新属性 DesktopSourcePath 没有前缀。如果这是标准属性,则无需修改;如果是扩展属性,建议保持命名一致性(如 X_DesktopSourcePath)。
  • 注释缺失:新增的 desktopSourcePath() 方法缺少注释,建议添加说明其用途和返回值含义。

3. 代码性能审查

  • 信号优化:如前所述,避免不必要的信号触发可以减少 D-Bus 通信开销。
  • 字符串拷贝desktopSourcePath() 返回 QString,可能涉及拷贝。如果性能敏感,可以考虑返回 const QString&(需确保 m_desktopSource.sourcePath() 返回的引用生命周期足够长)。

4. 代码安全审查

  • 路径暴露DesktopSourcePath 暴露了文件系统路径,可能存在信息泄露风险。需确认:
    • 路径是否包含敏感信息(如用户特定路径)。
    • 是否需要权限控制(当前是 read 访问)。
  • 空值处理:未明确 m_desktopSource.sourcePath() 是否可能返回空字符串或无效路径。建议:
    • 添加文档说明可能的返回值。
    • 如果路径无效,返回空字符串或特定错误码。

改进建议代码

以下是针对上述问题的改进版本:

XML 文件

<property name="DesktopSourcePath" type="s" access="read"/>

头文件

/**
 * @brief 获取 desktop 文件的源路径
 * @return 返回 desktop 文件的绝对路径,如果无效则返回空字符串
 */
Q_PROPERTY(QString DesktopSourcePath READ desktopSourcePath NOTIFY desktopSourcePathChanged)
[[nodiscard]] QString desktopSourcePath() const noexcept;

实现文件

QString ApplicationService::desktopSourcePath() const noexcept
{
    // 假设 m_desktopSource.sourcePath() 已确保返回有效路径或空字符串
    return m_desktopSource.sourcePath();
}

void ApplicationService::resetEntry(DesktopEntry *newEntry) noexcept
{
    // ... 其他代码 ...
    
    const QString newPath = m_desktopSource.sourcePath();
    if (m_oldPath != newPath) {  // 假设 m_oldPath 是成员变量,用于缓存旧值
        m_oldPath = newPath;
        emit desktopSourcePathChanged();
    }
}

其他建议

  1. 测试覆盖:确保添加单元测试验证:
    • 路径正确返回。
    • 路径变化时信号正确触发。
    • 路径不变时信号不触发。
  2. 文档更新:更新 D-Bus 接口文档,说明新属性的用途和行为。

总结

代码整体实现正确,但建议优化信号触发逻辑、添加注释,并考虑安全性和性能细节。改进后的代码可以减少不必要的开销并提高可维护性。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: BLumia, 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

@mhduiy
Copy link
Contributor Author

mhduiy commented Mar 5, 2026

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Mar 5, 2026

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit aaed2e0 into linuxdeepin:master Mar 5, 2026
16 of 18 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