Skip to content

fix: 提前注入 XDG_CURRENT_DESKTOP 环境变量,修复门户前端启动竞态 - #245

Draft
mhduiy wants to merge 1 commit into
masterfrom
agent/developer/483032d9b4fb
Draft

mhduiy wants to merge 1 commit into
masterfrom
agent/developer/483032d9b4fb

Conversation

@mhduiy

@mhduiy mhduiy commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

修复说明

开机后 XDG_CURRENT_DESKTOP 环境变量注入晚于门户前端(xdg-desktop-portal)启动,导致 FileChooser 接口缺失,Electron 应用选择文件夹时整窗闪退。

变更内容

  • 新增 dde-session-environment.service(oneshot),在 graphical-session-pre.target 之前执行,提前将 XDG_CURRENT_DESKTOP=DDE 注入 systemd user manager 和 D-Bus activation environment
  • 新增 dde-session-environment.sh 脚本,通过 systemctl --user set-environment 和 dbus-update-activation-environment 设置环境变量
  • 在 main.cpp 中添加注释说明环境变量的双重注入策略

关联

Summary by Sourcery

Inject XDG_CURRENT_DESKTOP=DDE earlier in the user session to prevent xdg-desktop-portal startup races.

Bug Fixes:

  • Prevent portal startup races by injecting XDG_CURRENT_DESKTOP=DDE before the graphical session begins, restoring FileChooser availability for Electron applications.

Enhancements:

  • Preserve the existing session environment initialization for the remaining desktop and display environment variables.

Build:

  • Install and enable the new early session environment service and its setup script as part of the systemd user-session configuration.

- Add dde-session-environment.service (oneshot, Before=graphical-session-pre.target)
  to inject XDG_CURRENT_DESKTOP=DDE into systemd user manager and D-Bus activation
  environment early, preventing a race where xdg-desktop-portal starts before
  EnvironmentsManager::init() runs and FileChooser interface is missing.
- Add dde-session-environment.sh script with error handling (both commands run,
  exit code reports failure if either fails).
- Add RefuseManualStart/RefuseManualStop/CollectMode for consistency with
  existing services.
- Install service into graphical-session-pre.target.wants/ for auto-pull.
- Add comment in main.cpp explaining the relationship between the early service
  and EnvironmentsManager::init().

PMS: https://pms.uniontech.com/bug-view-382063.html
Log: 在 graphical-session-pre.target 之前注入 XDG_CURRENT_DESKTOP=DDE,修复门户前端启动竞态
Influence: 修复冷启动后 Electron 应用选择文件夹闪退问题
@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: 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

@sourcery-ai

sourcery-ai Bot commented Nov 2, 2026

Copy link
Copy Markdown

Reviewer's Guide

通过新增并提前启动 systemd user oneshot 服务,将 XDG_CURRENT_DESKTOP=DDE 同时注入 user manager 与 D-Bus activation 环境,从启动时序上避免 xdg-desktop-portal 竞态;原有会话初始化继续负责完整环境变量配置及当前进程的 qputenv。

Sequence diagram for early desktop environment injection

sequenceDiagram
    participant Session as dde-session
    participant Systemd as systemd_user_manager
    participant EnvService as dde-session-environment.service
    participant Script as dde-session-environment.sh
    participant DBus as D-Bus_activation_environment
    participant Portal as xdg-desktop-portal
    participant EnvManager as EnvironmentsManager

    EnvService->>Script: execute
    Script->>Systemd: set-environment XDG_CURRENT_DESKTOP=DDE
    Script->>DBus: dbus-update-activation-environment XDG_CURRENT_DESKTOP=DDE
    EnvService-->>Systemd: complete before graphical-session-pre.target
    Systemd->>Portal: activate with XDG_CURRENT_DESKTOP=DDE
    Session->>EnvManager: init()
    EnvManager->>Session: set full environment and qputenv()
Loading

File-Level Changes

Change Details Files
在图形会话早期阶段通过 systemd user service 提前注入 XDG_CURRENT_DESKTOP,避免门户前端启动竞态。
  • 新增 oneshot 服务并挂接到 graphical-session-pre.target,调用环境设置脚本。
  • 同时更新 systemd user manager 和 D-Bus activation environment,确保后续服务继承变量。
  • 在构建和安装流程中生成、安装服务、脚本及 target wants 链接。
systemd/dde-session-environment.service.in
systemd/dde-session-environment.sh.in
systemd/CMakeLists.txt
保留会话进程内的完整环境初始化,并明确其与早期注入的职责边界。
  • 为 EnvironmentsManager::init() 增加注释,说明 XDG_CURRENT_DESKTOP 的提前注入及当前进程环境设置仍不可省略。
src/dde-session/main.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

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.

2 participants