Skip to content

feat: update dde-am tool#280

Merged
xzl01 merged 1 commit intolinuxdeepin:masterfrom
xzl01:master
Jul 7, 2025
Merged

feat: update dde-am tool#280
xzl01 merged 1 commit intolinuxdeepin:masterfrom
xzl01:master

Conversation

@xzl01
Copy link
Collaborator

@xzl01 xzl01 commented Jul 3, 2025

Add am-open tool for launching applications via command line

Log:

Summary by Sourcery

Add a new command-line tool 'am-open' for launching desktop applications via the ApplicationManager D-Bus interface.

New Features:

  • Introduce 'am-open' Python CLI to launch applications by app ID, .desktop path, or file URI
  • Allow specifying environment variables for the launched application
  • Provide built-in usage examples and on-demand help

Enhancements:

  • Derive application IDs automatically from standard XDG application directories or fallback to filename
  • Log operations and errors with timestamps to /tmp/am-open.log

Build:

  • Install the 'am-open' script via CMake into the binary install directory

sourcery-ai[bot]

This comment was marked as outdated.

Copy link
Member

@BLumia BLumia left a comment

Choose a reason for hiding this comment

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

为啥不直接改 dde-am 这个工具?看上去性质上差不多。

@xzl01 xzl01 changed the title feat: add am-open tool feat: update dde-am tool Jul 3, 2025
@linuxdeepin linuxdeepin deleted a comment from sourcery-ai bot Jul 3, 2025
@xzl01 xzl01 requested a review from Copilot July 3, 2025 06:54

This comment was marked as outdated.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds enhanced command-line functionality to dde-am for launching applications using app IDs, desktop file paths, or URIs, with support for environment variables and improved logging.

  • Introduces new CLI options (-d/--desktop-path, -u/--uri, -e/--env)
  • Implements getAppIdFromURI helper and fallback logic
  • Extends Launcher to accept and forward environment variables

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
docs/dde-am-usage.md Updates usage guide to include new options and examples
apps/dde-am/src/main.cpp Adds URI/desktop-path handling, env option parsing, and getAppIdFromURI
apps/dde-am/src/launcher.h Declares setEnvironmentVariables
apps/dde-am/src/launcher.cpp Passes environment variables into D-Bus call options
Comments suppressed due to low confidence (2)

apps/dde-am/src/main.cpp:18

  • New function getAppIdFromURI lacks unit tests; adding tests for valid URIs, non-file URIs, and missing files will ensure correct behavior.
QString getAppIdFromURI(const QString &uri)

apps/dde-am/src/launcher.h:19

  • [nitpick] Public method setEnvironmentVariables lacks a docstring; adding a brief description will improve API documentation and clarify expected input format.
    void setEnvironmentVariables(const QStringList &envVars);

Comment on lines +104 to +105
if (appId.isEmpty() && parser.value(desktopPathOption).endsWith(".desktop")) {
QFileInfo fileInfo(parser.value(desktopPathOption));
appId = fileInfo.baseName(); // Use filename without .desktop suffix
Copy link

Copilot AI Jul 3, 2025

Choose a reason for hiding this comment

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

[nitpick] Duplicate fallback logic for deriving app IDs from .desktop paths appears in multiple branches; consider extracting this into a shared helper function to reduce duplication.

Suggested change
if (appId.isEmpty() && parser.value(desktopPathOption).endsWith(".desktop")) {
QFileInfo fileInfo(parser.value(desktopPathOption));
appId = fileInfo.baseName(); // Use filename without .desktop suffix
if (appId.isEmpty()) {
appId = getAppIdFromDesktopPathFallback(parser.value(desktopPathOption));

Copilot uses AI. Check for mistakes.
@deepin-ci-robot
Copy link

deepin pr auto review

代码审查意见:

  1. 代码重复

    • getAppIdFromURI 函数中,对于 .desktop 文件的路径处理逻辑与 main 函数中相同,可以考虑将这部分逻辑提取到一个公共函数中,以减少代码重复。
  2. 错误处理

    • getAppIdFromURI 函数中,当 uri 不以 file:// 开头时,应该返回一个错误信息或者抛出异常,而不是返回空字符串。这有助于调用者了解发生了什么错误。
  3. 环境变量处理

    • main 函数中,环境变量的处理逻辑较为复杂,建议添加注释说明每个步骤的目的和逻辑,以便于理解和维护。
  4. 命令行参数解析

    • main 函数中对于命令行参数的处理较为繁琐,可以考虑使用 QCommandLineParservalue() 方法来简化参数的获取和处理。
  5. 代码风格

    • 代码中存在一些不一致的地方,例如变量命名风格(m_pathm_action 使用驼峰式,而 appIdaction 使用下划线分隔),建议统一风格以提高代码的可读性。
  6. 安全性

    • 在处理文件路径和 URI 时,应该对输入进行验证和清理,以防止路径遍历攻击等安全问题。
  7. 文档和注释

    • 新增的 getAppIdFromURI 函数缺少注释说明其功能和参数含义,建议添加详细的注释以提高代码的可维护性。
  8. 性能

    • 如果 getAppIdFromURI 函数在处理大量 URI 时性能不佳,可以考虑优化算法或使用缓存机制。
  9. 测试

    • 新增的功能应该有相应的单元测试来验证其正确性和稳定性。
  10. 国际化

    • 在错误信息输出时,建议使用国际化字符串,以便于支持多语言环境。

综上所述,代码在功能实现上基本正确,但在代码质量、安全性和可维护性方面还有改进的空间。

mhduiy
mhduiy previously approved these changes Jul 3, 2025
@deepin-bot
Copy link

deepin-bot bot commented Jul 3, 2025

TAG Bot

New tag: 1.2.32
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #281

}

// Handle legacy environment variable as third argument
if (!arguments.isEmpty() && !parser.isSet(envOption)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

这个地方的arguments是位置参数,不是选项参数,应该不需要判断arguments.isEmpty(),envVars也不是从这里获取的,

18202781743
18202781743 previously approved these changes Jul 4, 2025
Copy link
Member

@BLumia BLumia left a comment

Choose a reason for hiding this comment

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

还是兼容一下之前以第二个位置参数作为 action 的场景吧。两三行的事

BLumia
BLumia previously approved these changes Jul 7, 2025
dde-am support env now!

Log:
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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
Copy link
Member

BLumia commented Jul 7, 2025

备注一下私下沟通的关于后续潜在支持传递参数给程序的需求的结论:

根据惯用做法,使用 -- 作为分隔符,分割参数是传递给 dde-am 的还是要执行的目标应用的。例如:

$ dde-am deepin-editor -e LANG=zh_CN -- file:///path/to/textfile1.txt file:///path/to/textfile2.txt
$ dde-am firefox -- https://www.bing.com

@xzl01 xzl01 merged commit 43e7dd9 into linuxdeepin:master Jul 7, 2025
15 of 16 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.

6 participants