Skip to content

feat: sessionFieldOverrides for override Exec key in a given session - #379

Open
BLumia wants to merge 1 commit into
linuxdeepin:masterfrom
BLumia:feat-session-overrides
Open

feat: sessionFieldOverrides for override Exec key in a given session#379
BLumia wants to merge 1 commit into
linuxdeepin:masterfrom
BLumia:feat-session-overrides

Conversation

@BLumia

@BLumia BLumia commented Aug 6, 2026

Copy link
Copy Markdown
Member

新增 DConfig 配置项,允许为指定会话(例如wayland)覆盖指定desktop文件中
的Exec/TryExec字段的值.

配置格式大致为

/usr/share/dsg/configs/overrides/org.deepin.dde.application-manager/org.deepin.dde.am.appoverride/x11/example.app-id/90-override.json

{
    "magic": "dsg.config.override",
    "version": "1.0",
    "contents": {
        "Exec": {
            "value": "notify-send 'test am override'"
        }
    }
}

配置好后使用这个命令验证配置项是否正确:dde-dconfig get -a org.deepin.dde.application-manager -r org.deepin.dde.am.appoverride -s /x11/example.app-id -k Exec

实际场景为解决部分应用程序默认Exec字段的参数会无法在treeland下表现良
好的问题.

Log:

Summary by Sourcery

Introduce session-aware configuration to override desktop file Exec/TryExec and environment fields per session and integrate it into application filtering and autostart handling.

Enhancements:

  • Add SessionOverrideConfig and SessionType utilities wired into ApplicationManager to load DConfig-based sessionFieldOverrides and trigger application list reloads on config changes.
  • Apply session-specific Exec and environment overrides when processing compatibility for application launches, including support for action-specific groups and placeholder substitution in Exec values.
  • Extend application visibility and autostart checks to consider session-level TryExec overrides, including a force-show behavior for empty overrides.

Tests:

  • Add unit tests covering session override config parsing, value/env lookup, Exec placeholder resolution, TryExec override behavior, and session type detection.

@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 @BLumia, 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: 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 requested a review from ComixHe August 6, 2026 12:34
@sourcery-ai

sourcery-ai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a DConfig-driven, session-specific override mechanism for desktop file Exec/TryExec and environment variables, wires it through application creation/autostart checks, and introduces supporting SessionOverrideConfig and SessionType helpers with unit tests.

Sequence diagram for Exec and Env resolution with session overrides

sequenceDiagram
    participant AMS as ApplicationManager1Service
    participant AS as ApplicationService
    participant CM as CompatibilityManager
    participant SOC as SessionOverrideConfig

    AMS->>AS: createApplicationService(...)
    AMS->>AMS: getSessionOverrideConfig()
    AMS->>AS: shouldBeShown(entry, desktopId, sessionConfig)

    AS->>CM: getCompatibilityManager()
    AS->>AS: processCompatibility(action, options, execStr)
    Note over AS: originalExec = execStr
    AS->>CM: getExec(desktopId)
    AS->>AS: apply compatibility Exec/env

    AS->>AMS: parent().getSessionOverrideConfig()
    AS->>SOC: getValue(desktopId, groupKey, DesktopEntryExec)
    alt Exec override exists
        AS->>SOC: resolveExecValue(overrideExec, originalExec)
        AS->>AS: execStr = resolvedExec
    end

    AS->>SOC: getEnv(desktopId, groupKey)
    alt Env overrides not empty
        AS->>AS: merge Env into options[EnvKey]
    end
Loading

File-Level Changes

Change Details Files
Introduce SessionOverrideConfig and SessionType utilities to load and represent per-session overrides from DConfig.
  • Add SessionOverrideConfig class that reads org.deepin.dde.application-manager.sessionFieldOverrides via DConfig, parses JSON into per-desktop override maps, exposes getValue/getEnv/hasOverride helpers, and emits configChanged when updated.
  • Implement parseSessionConfig to select the block matching the current session (wayland/x11) and build a QHash of desktopId -> QJsonObject, logging and skipping invalid data.
  • Implement resolveExecValue helper to substitute the !AM_FULL! placeholder with the original Exec string.
  • Add SessionType enum and currentSessionType() helper that infers Wayland/X11/Unknown from process environment variables.
src/sessionoverrideconfig.h
src/sessionoverrideconfig.cpp
src/sessiontype.h
src/sessiontype.cpp
Apply session-specific Exec and environment overrides when launching applications.
  • Capture the original Exec string before compatibility processing so it can be used for !AM_FULL! substitution.
  • Fetch the SessionOverrideConfig from ApplicationManager1Service and, if present, apply per-session Exec overrides for the relevant Desktop Entry or Desktop Action group, resolving !AM_FULL! against the original Exec.
  • Merge session-level Env overrides into the existing options env list, appending to any existing Env entries.
  • Log applied session overrides for Exec and Env for debugging.
src/dbus/applicationservice.cpp
src/dbus/applicationservice.h
Apply session-specific TryExec overrides consistently in visibility/autostart checks.
  • Extend ApplicationFilter::tryExecCheck to accept desktopId and an optional SessionOverrideConfig pointer, and first check for a TryExec override in DConfig.
  • Treat an empty overridden TryExec as force-show; for non-empty values, resolve absolute paths via QFileInfo and relative names via QStandardPaths::findExecutable to decide visibility.
  • Propagate the new tryExecCheck signature through ApplicationService::shouldBeShown, the autostart helper parseAutostartDesktopFile, ApplicationManager1Service::updateAutostartStatus, and dde-autostart main, always passing desktopId and sessionConfig where available.
src/applicationchecker.h
src/applicationchecker.cpp
src/dbus/applicationservice.cpp
src/dbus/applicationservice.h
src/dbus/applicationmanager1service.cpp
src/dbus/applicationmanager1service.h
apps/dde-autostart/src/main.cpp
Wire SessionOverrideConfig into ApplicationManager1Service lifecycle and configuration constants.
  • Instantiate SessionOverrideConfig in ApplicationManager1Service::initService, store it as a unique_ptr member, and expose it via getSessionOverrideConfig().
  • Connect the SessionOverrideConfig::configChanged signal to trigger doReloadApplications so overrides take effect without restart.
  • Introduce the SessionFieldOverrides DConfig key constant and register it in the org.deepin.dde.application-manager DConfig schema JSON.
src/dbus/applicationmanager1service.cpp
src/dbus/applicationmanager1service.h
src/constant.h
misc/dsg/configs/dde-application-manager/org.deepin.dde.application-manager.json
Add unit tests covering session override parsing, lookup, and TryExec integration.
  • Create tests that verify parseSessionConfig selects the correct session block, ignores empty/invalid JSON, and skips invalid desktop entries.
  • Test getValue, getEnv, and hasOverride for existing/missing apps, groups, and fields, including Env array handling.
  • Validate resolveExecValue behavior for multiple !AM_FULL! placements and cases without placeholders.
  • Exercise ApplicationFilter::tryExecCheck with overrides for valid, invalid, and empty TryExec values, plus fallback behavior when no override is present, and basic currentSessionType detection.
tests/ut_sessionoverrideconfig.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

@BLumia
BLumia force-pushed the feat-session-overrides branch from c0c75c0 to ea88ef1 Compare August 11, 2026 11:47
"name": "Session-specific Exec override",
"name[zh_CN]": "会话感知的 Exec 覆盖",
"description": "Overrides the Exec field. Supports !AM_FULL! placeholder.",
"permissions": "readwrite",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

不是read吗

"name": "Session-specific TryExec override",
"name[zh_CN]": "会话感知的 TryExec 覆盖",
"description": "Overrides the TryExec field. Empty string forces the app to be shown.",
"permissions": "readwrite",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

同上

"visibility": "public"
}
}
} No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

另外少了Icon字段

Comment thread src/sessionoverrideconfig.cpp Outdated
return it->second.get();

const auto subpath = m_subpathPrefix % u"/"_s % desktopId;
auto *config = DConfig::create(fromStaticRaw(ApplicationServiceID),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

用dconfig提供的cmake来生成代码,不要直接用dconfig类。

@BLumia
BLumia force-pushed the feat-session-overrides branch from ea88ef1 to d189844 Compare August 11, 2026 13:02
新增 DConfig 配置项,允许为指定会话(例如wayland)覆盖指定desktop文件中
的Exec/TryExec字段的值.

实际场景为解决部分应用程序默认Exec字段的参数会无法在treeland下表现良
好的问题.

Log:
@BLumia
BLumia force-pushed the feat-session-overrides branch from d189844 to f7468cd Compare August 11, 2026 13:11
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:80分

■ 【总体评价】

代码实现了基于会话类型的应用配置覆盖功能,但存在致命的逻辑缺陷导致功能完全失效
逻辑错误导致配置初始值无法加载,且存在const正确性问题,但因无安全漏洞保留较高分数

■ 【详细分析】

  • 1.语法逻辑(存在致命错误)✕

SessionOverrideConfig::ensureLoaded 函数中,调用了 configFor(desktopId) 但该方法仅创建 ApplicationOverrideConfig 对象并连接 valueChanged 信号,并未主动触发 updateOverride 来读取初始配置值。这导致 m_overrides 哈希表在首次加载时始终为空,getValue 函数永远返回 std::nullopt,使得整个会话覆盖功能完全失效。
潜在问题:配置覆盖功能在应用启动时无法生效,仅在运行时配置发生改变后才能生效;SessionOverrideConfig::configFor 中使用了 const_cast<SessionOverrideConfig*>(this) 破坏了常量正确性
建议:在 configFor 函数中创建配置对象后立即调用 updateOverride(desktopId) 以加载初始值;重构代码避免使用 const_cast,将需要修改的成员变量声明为 mutable 或调整函数的常量性

  • 2.代码质量(良好)✓

代码整体结构清晰,命名规范符合要求,新增了完整的单元测试覆盖核心逻辑。配置管理使用了智能指针防止内存泄漏,日志输出详尽。
潜在问题:部分文件末尾缺少换行符(如 sessionoverrideconfig.cpp
建议:在文件末尾添加换行符以符合 POSIX 标准

  • 3.代码性能(无性能问题)✓

currentSessionType 使用静态局部变量缓存会话类型检测结果,避免重复读取环境变量。配置对象使用 std::mapQHash 进行缓存,查找效率高。
建议:无需修改

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码未引入命令注入、路径遍历等安全风险。TryExec 仅用于检查可执行文件是否存在,不涉及命令执行。Exec 覆盖值来源于系统级只读 DConfig,风险可控。

  • 建议:无需修改

■ 【改进建议代码示例】

diff --git a/src/sessionoverrideconfig.cpp b/src/sessionoverrideconfig.cpp
index 37e88239..00000000
--- a/src/sessionoverrideconfig.cpp
+++ b/src/sessionoverrideconfig.cpp
@@ -89,6 +89,9 @@ ApplicationOverrideConfig *SessionOverrideConfig::configFor(const QString &deskto
     });
 
     m_configs[desktopId] = std::unique_ptr<ApplicationOverrideConfig>(config);
+    
+    // Load initial values immediately after creation
+    updateOverride(desktopId);
+    
     return config;
 }

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