Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/dde-session/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ int main(int argc, char *argv[])
DLogManager::registerConsoleAppender();
DLogManager::registerFileAppender();

// XDG_CURRENT_DESKTOP=DDE is also injected early by
// dde-session-environment.service (Before=graphical-session-pre.target)
// to prevent a race where xdg-desktop-portal starts before this call.
// EnvironmentsManager::init() still runs here to set the full set of
// environment variables (QT_QPA_PLATFORM, scale factors, etc.) and to
// call qputenv() for the current process.
EnvironmentsManager().init();

QString dmService = "dde-session.target";
Expand Down
15 changes: 15 additions & 0 deletions systemd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ configure_file(dde-session-shutdown.service.in
configure_file(dde-keyring.service.in
dde-keyring.service
@ONLY)
configure_file(dde-session-environment.service.in
dde-session-environment.service
@ONLY)
configure_file(dde-session-environment.sh.in
dde-session-environment.sh
@ONLY)


set(SERVICES
Expand All @@ -20,11 +26,20 @@ set(SERVICES
${CMAKE_CURRENT_BINARY_DIR}/dde-session-exit-task.service
${CMAKE_CURRENT_BINARY_DIR}/dde-session-shutdown.service
${CMAKE_CURRENT_BINARY_DIR}/dde-keyring.service
${CMAKE_CURRENT_BINARY_DIR}/dde-session-environment.service
dde-session-shutdown.target
dde-session.target
)
install(FILES ${SERVICES} DESTINATION lib/systemd/user/)

# Install the early environment setup script
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/dde-session-environment.sh
DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/deepin)

# graphical-session-pre.target.wants - early environment injection
install(DIRECTORY DESTINATION lib/systemd/user/graphical-session-pre.target.wants/)
install_symlink(dde-session-environment.service graphical-session-pre.target.wants)

install(DIRECTORY DESTINATION lib/systemd/user/dde-session-pre.target.wants/)
set(DDE_SESSION_PRE_WANTS
dde-session-pre.target.wants/dde-session@x11.service
Expand Down
12 changes: 12 additions & 0 deletions systemd/dde-session-environment.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Set DDE session environment variables early
RefuseManualStart=yes
RefuseManualStop=yes
CollectMode=inactive-or-failed

Before=graphical-session-pre.target

[Service]
Type=oneshot
ExecStart=@CMAKE_INSTALL_FULL_LIBEXECDIR@/deepin/dde-session-environment.sh
Slice=session.slice
17 changes: 17 additions & 0 deletions systemd/dde-session-environment.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
# SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

# Set XDG_CURRENT_DESKTOP=DDE early in the systemd user manager and D-Bus
# activation environments, before graphical-session-pre.target is reached.
#
# This ensures that xdg-desktop-portal (the front-end) can discover the DDE
# portal backend even if it starts before dde-session's full
# EnvironmentsManager::init() has run, preventing a race where FileChooser
# and other portal interfaces are missing on cold boot.

rc=0
systemctl --user set-environment XDG_CURRENT_DESKTOP=DDE || rc=1
dbus-update-activation-environment XDG_CURRENT_DESKTOP=DDE || rc=1
exit $rc
Loading