Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

feat: support singleton application declaration via DConfig and desktop file - #394

Open
deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:agent/bot/55ce2d3f2233
Open

deepin-wm wants to merge 1 commit into
linuxdeepin:masterfrom
deepin-wm:agent/bot/55ce2d3f2233

Conversation

@deepin-wm

@deepin-wm deepin-wm commented Oct 30, 2026 •

Copy link
Copy Markdown

Summary

新增 DConfig appSingleton 配置项供三方应用声明单例;自研应用通过 desktop 文件 X-Deepin-Singleton 字段声明;两种方式 OR 合并用于 splash 抑制(不拦截重复启动);惰性判定 + DConfig 查询结果缓存。

Changes

  • DConfig Schema (misc/dsg/configs/dde-application-manager/org.deepin.dde.application-manager.json): 新增 appSingleton 配置项(bool, 默认 false, readwrite, public),per-app subpath /<appId>,与 appExtraEnvironments 一致
  • 常量定义 (src/constant.h): 新增 AppSingleton = u"appSingleton" 常量
  • 成员变量 (src/dbus/applicationservice.h): 新增 std::optional<bool> m_dconfigSingleton 用于缓存 DConfig 查询结果
  • Splash 抑制逻辑 (src/dbus/applicationservice.cpp — Launch() 方法):
    • 使用 IIFE 惰性计算 singletonWithInstance:
      • m_Instances 为空(首启)→ 直接 false,零开销
      • desktop 文件 X-Deepin-Singleton 为 true → 直接 true,跳过 DConfig 查询
      • 否则查询 DConfig appSingleton(per-app subpath),结果缓存到 m_dconfigSingleton,后续调用复用
    • singletonWithInstance 为 true 时跳过 prelaunch splash(不拦截启动,应用正常启动)

Behavior

DConfig appSingleton Desktop X-Deepin-Singleton m_Instances Splash
false (default) false (default) 任意 正常显示
true false 非空(已有实例) 抑制
false true 非空(已有实例) 抑制
true true 非空(已有实例) 抑制
任意 任意 空(首启) 正常显示

Notes

  • AM 不拦截单例应用的重复启动,X-Deepin-Singleton 是声明性元数据,去重是应用自己的责任
  • 本 PR 仅将单例声明用于 splash 抑制:当单例应用已有实例运行时,跳过启动闪屏
  • DConfig 读取使用 std::optional<bool> 缓存,同一 ApplicationService 实例生命周期内只查询一次
  • DConfig 创建失败时 m_dconfigSingleton 保持未初始化,查询结果为 false,不影响 desktop 文件声明的单例判断

Multica Issue: DDE-470

@deepin-ci-robot

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-wm

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

This comment was marked as off-topic.

@deepin-wm
deepin-wm force-pushed the agent/bot/55ce2d3f2233 branch 2 times, most recently from cb1d44c to 072da37 Compare October 30, 2026 08:37
@wineee

This comment was marked as resolved.

@wineee
wineee marked this pull request as ready for review October 30, 2026 08:59

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 98 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为 dde-application-manager 新增通过 DConfig 声明应用单例的功能,并优化了 DConfig 的创建以避免重复阻塞性 D-Bus 调用。代码逻辑正确,空指针处理安全,性能优化合理。存在1处代码质量 改进建议(DConfig 描述不够精确),无安全漏洞。总体代码质量优秀。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 无


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 建议将 appSingleton 的 description 修改为更完整的描述,例如:"When set to true, Application Manager will treat the application as singleton: if an instance is already running, the launch splash will be suppressed. The value must be written under the subpath /. Intended for third-party applications that cannot modify their desktop files to add the X-Deepin-Singleton field."


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 无


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: 无


💡 改进建议代码示例

// 建议修改 DConfig 描述,使其更完整地反映单例语义 // 文件: misc/dsg/configs/dde-application-manager/org.deepin.dde.application-manager.json "appSingleton": {
    "value": false,
    "serial": 0,
    "flags": [],
    "name": "Declare application as singleton",
    "name[zh_CN]": "声明应用为单例",
    "description": "When set to true, Application Manager will treat the application as singleton: if an instance is already running, the launch splash will be suppressed. The value must be written under the subpath /<desktop-id> (the application desktop file ID). Intended for third-party applications that cannot modify their desktop files to add the X-Deepin-Singleton field.",
    "permissions": "readwrite",
    "visibility": "public"
}

本报告由 AI 代码审查工具自动生成

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/dbus/applicationservice.cpp" line_range="500-501" />
<code_context>
-        findEntryValue(fromStaticRaw(DesktopFileEntryKey), fromStaticRaw(DesktopEntryXDeepinSingleton), EntryValueType::Boolean)
-            .toBool();
+    bool dconfigSingleton = false;
+    if (sharedDConfig && sharedDConfig->isValid()) {
+        dconfigSingleton = sharedDConfig->value(fromStaticRaw(AppSingleton)).toBool();
+    }
+
</code_context>
<issue_to_address>
**Singleton splash suppression is lost**

When DConfig is unavailable while a third-party app relies only on `appSingleton`, `sharedDConfig` is invalid, so `dconfigSingleton` remains false and the launch proceeds to show a splash for an app whose only singleton declaration is in DConfig.

Log a warning when the DConfig is invalid so operators can detect that the singleton declaration is not being applied.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/dbus/applicationservice.cpp Resolved
@wineee

This comment was marked as outdated.

@deepin-wm
deepin-wm force-pushed the agent/bot/55ce2d3f2233 branch from 072da37 to 888153e Compare October 30, 2026 09:14
…op file

Add DConfig 'appSingleton' configuration item for third-party applications
to declare singleton behavior, and use existing desktop file 'X-Deepin-Singleton'
field for self-developed applications. Both sources are OR-combined: if either
is true and an instance is already running, Application Manager suppresses the
launch splash for the duplicate launch. This extends singleton-aware splash
suppression to third-party apps via DConfig.

The singleton declaration (X-Deepin-Singleton / appSingleton) is metadata only;
single-instance deduplication remains the application's own responsibility (DTK
single-instance framework). Application Manager does not intercept or block
duplicate launches — it only suppresses the splash screen to avoid a flash for
apps that will immediately exit after activating the existing instance.

The singleton check in Launch() uses a lazy IIFE: on first launch (the common
hot path) m_Instances is empty so singletonWithInstance is always false and
no DConfig query or findEntryValue call is made. Only when an instance already
exists does the check proceed — first consulting the desktop file
X-Deepin-Singleton (short-circuiting DConfig if true), then falling back to
a DConfig appSingleton query. appendExtraEnvironments retains its original
signature and creates its own DConfig internally.

Changes:
- misc/dsg/configs/dde-application-manager/org.deepin.dde.application-manager.json:
  add 'appSingleton' config item (bool, default false, readwrite, public) with
  description noting the value must be written under subpath /<desktop-id>
- src/constant.h: add AppSingleton constant
- src/dbus/applicationservice.cpp: lazy singletonWithInstance evaluation via
  IIFE in Launch(); fix nullptr safety in appendExtraEnvironments
  (config && config->isValid())

Copilot AI 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.

🟡 Changes recommended

A temporary DConfig failure is cached as false, preventing retries and causing splash-screen suppression to remain disabled for the service’s lifetime even after configuration recovers.

1 open issue
What changed in this PR

Adds per-application DConfig singleton declarations alongside the existing desktop-file declaration to suppress splash screens when an instance is already running, without blocking repeat launches.

Changes:

  • Adds the public, writable appSingleton setting and its constant.
  • Combines desktop and DConfig declarations with lazy lookup and a per-service cache.
  • Adds a null check when loading extra environment settings.
File Description
src/​dbus/​applicationservice.h Adds optional storage for the cached singleton setting.
src/​dbus/​applicationservice.cpp Implements lazy singleton lookup and guards environment-config access.
src/​constant.h Defines the AppSingleton configuration key.
misc/​dsg/​configs/​dde-application-manager/​org.deepin.dde.application-manager.json Declares and documents the per-app singleton setting.

Review effort: Balanced

Comment on lines +494 to +495
m_dconfigSingleton = config && config->isValid()
&& config->value(fromStaticRaw(AppSingleton)).toBool();
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.

4 participants