Skip to content

Conversation

@BLumia
Copy link
Member

@BLumia BLumia commented Apr 9, 2025

Summary by Sourcery

Refactor and improve the unescapeExec method in the ApplicationService class, enhancing the handling of desktop entry launch commands and field codes

New Features:

  • Added unescapeEens method to process environment variables
  • Introduced autoRemoveFromDesktop method to handle desktop file cleanup

Enhancements:

  • Reimplemented unescapeExec method with more robust handling of field codes and command parsing
  • Improved error handling and logging for different field code scenarios
  • Added more comprehensive processing of special field codes like %f, %u, %F, %U, %i, and %c

Chores:

  • Updated method signatures to improve const-correctness and parameter handling

ComixHe and others added 2 commits April 9, 2025 18:23
adjusted patch from master branch (originally 2f0f34a)

Signed-off-by: ComixHe <heyuming@deepin.org>
@BLumia BLumia requested review from ComixHe and Zeno-sole April 9, 2025 10:35
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 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
Copy link
Member Author

BLumia commented Apr 9, 2025

/integrate

@deepin-ci-robot
Copy link

deepin pr auto review

关键摘要:

  • ApplicationService::Launch函数中,break语句被移除,可能导致逻辑错误。
  • ApplicationService::unescapeExec函数中,fields参数被修改为非const引用,可能会影响调用者传入的原始数据。
  • ApplicationService::unescapeExec函数中,exclusiveField变量在处理多个字段时没有正确重置,可能导致逻辑错误。
  • ApplicationService::unescapeEens函数中,wordexp函数的使用没有错误处理,可能会导致程序崩溃。
  • ApplicationService::autoRemoveFromDesktop函数中,QFile::remove没有检查返回值,可能会导致文件删除失败时程序继续执行。

是否建议立即修改:

@sourcery-ai
Copy link

sourcery-ai bot commented Apr 9, 2025

Reviewer's Guide by Sourcery

This pull request refactors the unescapeExec method in ApplicationService to improve handling of field codes and resource processing. It also implements environment variable expansion in unescapeEens and automatic removal of desktop files.

Sequence diagram for unescapeExec with resource processing

sequenceDiagram
  participant AS as ApplicationService
  participant UE as unescapeExec
  participant PU as processUrl
  participant QProcess as QProcess

  AS->UE: unescapeExec(str, fields)
  UE->UE: Parse str for field codes (%f, %u, %F, %U)
  alt Field code found
    UE->PU: processUrl(field)
    PU->PU: Check if URL is valid and local
    alt URL is valid and local
      PU-->UE: Return local file path
    else URL is invalid or remote
      PU-->UE: Return original URL
    end
    UE->UE: Append processed resource to command
  end
  UE-->AS: Return LaunchTask
  AS->QProcess: start(LaunchBin, command)
  QProcess-->AS: Exit code
  AS-->AS: Handle exit code
Loading

Updated class diagram for ApplicationService

classDiagram
  class ApplicationService {
    -m_applicationPath: QDBusObjectPath
    -m_desktopSource: DesktopSource
    -m_launcher: QString
    +Launch(action: QString, fields: QStringList, res: QVariant) : QVariant
    +unescapeExec(str: QString, fields: QStringList) : LaunchTask
    +unescapeExecArgs(str: QString) : std::optional<QStringList>
    +unescapeEens(options: QVariantMap) : void
    +autoRemoveFromDesktop() : void
    +findEntryValue(group: QString, valueKey: QString, type: EntryValueType, locale: QLocale) : QVariant
  }
  class LaunchTask {
    +LaunchBin: QString
    +command: QStringList
    +Resources: QStringList
  }
  ApplicationService -- LaunchTask : returns
Loading

File-Level Changes

Change Details Files
Refactor the unescapeExec method to improve handling of field codes and resource processing.
  • Improved logic for handling %f, %F, %u, and %U field codes, including URL validation and local file conversion.
  • Added support for the %i field code to include application icons.
  • Added support for the %c field code to include the application name.
  • Deprecated field codes %d, %D, %n, %N, %v, and %m are now ignored.
  • The method now uses QStringList instead of QString for resource handling.
  • Added logging for debugging and error reporting.
  • The method now splits the arguments into a list of commands.
  • The method now supports multiple arguments with field codes.
src/dbus/applicationservice.cpp
src/dbus/applicationservice.h
Implement environment variable expansion in unescapeEens.
  • The method now expands environment variables in the env option using wordexp.
  • The expanded variables are added to the env option.
src/dbus/applicationservice.cpp
src/dbus/applicationservice.h
Implement automatic removal of desktop files.
  • The method now removes the desktop file if it is a symbolic link.
  • The method logs a warning if the desktop file cannot be removed.
src/dbus/applicationservice.cpp
src/dbus/applicationservice.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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

@github-actions
Copy link

github-actions bot commented Apr 9, 2025

AutoIntegrationPr Bot
auto integrate with pr url: deepin-community/Repository-Integration#2740
PrNumber: 2740
PrBranch: auto-integration-14355044249

@github-actions
Copy link

github-actions bot commented Apr 9, 2025

TAG Bot

TAG: 1.2.16.1
EXISTED: no
DISTRIBUTION: unstable

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

Overall Comments:

  • The changes to unescapeExec are quite large; could you add some more comments to explain the logic, especially around the field code handling?
  • Consider using QStringView instead of QString for parsing in unescapeExec to avoid unnecessary string copies.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

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.

m_applicationPath.path(),
[this, binary = std::move(bin), commands = std::move(cmds)](const QVariant &variantValue) -> QVariant {
auto resourceFile = variantValue.toString();
[this, binary = std::move(bin), commands = std::move(cmds)](const QVariant &value) -> QVariant {
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider extracting resource replacement and command adjustment logic into helper functions to improve the lambda's readability and maintainability, and refactor nested loops or string operations into dedicated functions to keep the lambda concise while maintaining functionality .

Consider extracting the embedded resource-replacement and command‐adjustment logic into small helper functions so that the lambda stays focused. For example, you might create a helper like this:

QStringList processResourceInsertion(QStringList cmds, const QString &resource) {
    auto it = std::find_if(cmds.begin(), cmds.end(), [](const QString &cmd) {
        return cmd.contains("%f") || cmd.contains("%F");
    });
    if (it != cmds.end()) {
        auto index = (it->contains("%f") ? it->indexOf("%f") : it->indexOf("%F"));
        // Replace the placeholder with resource (adjust length accordingly)
        it->replace(index, 2, resource);
    } else {
        qCritical() << "internal logic error, can't find %f or %F in exec command, abort.";
    }
    return cmds;
}

Then, in your lambda, simply call this helper:

// Existing setup of newCommands and determination of resource
newCommands = processResourceInsertion(newCommands, resourceFile);

Similarly, consider refactoring any nested loops or string operations (for handling %f/%F/%u types) into dedicated functions. This keeps the lambda concise while maintaining all functionality.

@BLumia
Copy link
Member Author

BLumia commented Apr 10, 2025

backport 不足够修复遇到的问题,决定使用主干并在主干修复。见:#264

@BLumia BLumia closed this Apr 10, 2025
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