feat: add GIO_LAUNCHED_DESKTOP_FILE to runtime envs

add hooks for dde-dock

Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
ComixHe 2024-03-06 17:41:26 +08:00 committed by Comix
parent 3b2674023c
commit 1b4fb5551d
10 changed files with 47 additions and 10 deletions

View File

@ -27,6 +27,7 @@ find_package(Threads REQUIRED)
set(APP_LAUNCH_HELPER_BIN app-launch-helper)
set(APP_UPDATE_NOTIFIER_BIN app-update-notifier)
set(AM_LIBEXEC_DIR ${CMAKE_INSTALL_LIBEXECDIR}/deepin/application-manager)
if(DDE_AM_USE_DEBUG_DBUS_NAME)
add_compile_definitions(-DDDE_AM_USE_DEBUG_DBUS_NAME)

View File

@ -14,4 +14,4 @@ target_include_directories(${APP_LAUNCH_HELPER_BIN} PRIVATE
)
include(GNUInstallDirs)
install(TARGETS ${APP_LAUNCH_HELPER_BIN} DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/deepin/application-manager/)
install(TARGETS ${APP_LAUNCH_HELPER_BIN} DESTINATION ${AM_LIBEXEC_DIR})

View File

@ -11,4 +11,4 @@ target_include_directories(${APP_UPDATE_NOTIFIER_BIN} PRIVATE
)
include(GNUInstallDirs)
install(TARGETS ${APP_UPDATE_NOTIFIER_BIN} DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/deepin/application-manager/)
install(TARGETS ${APP_UPDATE_NOTIFIER_BIN} DESTINATION ${AM_LIBEXEC_DIR})

View File

@ -4,4 +4,4 @@ usr/lib/*
usr/libexec/*
usr/share/dbus-1/*
usr/share/dsg/*
usr/share/deepin/dde-application-manager/hooks.d/*

View File

@ -8,7 +8,7 @@ hook 允许系统组件在应用启动前对应用的运行时环境做出配置
## 配置文件
hook 的配置文件需要放在'/usr/share/deepin/dde-application-manager/hook.d/'下,文件名必须符合以下规范:
hook 的配置文件需要放在'/usr/share/deepin/dde-application-manager/hooks.d/'下,文件名必须符合以下规范:
- 以数字开头作为hook的顺序标识。
- 以`-`分割顺序和hook名。
- 文件格式需要是`json`,文件扩展名同样以`json`结尾。

View File

@ -46,6 +46,24 @@ install(FILES ${DBUS_APPLICATION_MANAGER_SERVICE_FILE}
install(FILES ${CMAKE_CURRENT_LIST_DIR}/dpkg/dpkg.cfg.d/am-update-hook
DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/dpkg/dpkg.cfg.d)
# configure and install dde-dock hooks
set(HOOKS_DEST_DIR ${CMAKE_INSTALL_DATADIR}/deepin/dde-application-manager/hooks.d)
configure_file(
hooks.d/1-dockEnv.json.in
hooks.d/1-dockEnv.json
@ONLY
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/hooks.d/1-dockEnv.json
DESTINATION ${HOOKS_DEST_DIR})
install(FILES ${CMAKE_CURRENT_LIST_DIR}/hooks.d/dockEnv.sh
DESTINATION ${AM_LIBEXEC_DIR}
PERMISSIONS
OWNER_READ OWNER_EXECUTE OWNER_WRITE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)
# FIXME: move to other project
set(DCONFIG_FILES
${CMAKE_CURRENT_LIST_DIR}/dsg/configs/dde-application-manager/com.deepin.dde.launcher.json

View File

@ -0,0 +1,4 @@
{
"Exec": "@CMAKE_INSTALL_PREFIX@/@AM_LIBEXEC_DIR@/dockEnv.sh",
"Args":[]
}

11
misc/hooks.d/dockEnv.sh Normal file
View File

@ -0,0 +1,11 @@
#!/bin/sh
# SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: LGPL-3.0-or-later
# This hook is required by dde-dock that detect identity of Application.
# May be remove on later.
export GIO_LAUNCHED_DESKTOP_FILE_PID=$$
exec "$@"

View File

@ -49,12 +49,12 @@ double getScaleFactor() noexcept
return scale;
}
void appendRuntimeScaleFactor(const ApplicationService &app, QVariantMap &runtimeOptions) noexcept
void ApplicationService::appendExtraEnvironments(QVariantMap &runtimeOptions) const noexcept
{
static QStringList scaleEnvs{"DEEPIN_WINE_SCALE=%1;", "GDK_DPI_SCALE=%1;", "QT_SCALE_FACTOR=%1;", "GDK_SCALE=%1;"};
QString oldEnv;
auto factor = app.scaleFactor();
// scale factor
static QStringList scaleEnvs{"DEEPIN_WINE_SCALE=%1;", "GDK_DPI_SCALE=%1;", "QT_SCALE_FACTOR=%1;", "GDK_SCALE=%1;"};
auto factor = scaleFactor();
if (auto it = runtimeOptions.find("env"); it != runtimeOptions.cend()) {
oldEnv = it->value<QString>();
}
@ -63,6 +63,9 @@ void appendRuntimeScaleFactor(const ApplicationService &app, QVariantMap &runtim
oldEnv.append(env.arg(factor));
}
// GIO
oldEnv.append(QString{"GIO_LAUNCHED_DESKTOP_FILE=%1;"}.arg(m_desktopSource.sourcePath()));
runtimeOptions.insert("env", oldEnv);
}
@ -232,8 +235,7 @@ ApplicationService::Launch(const QString &action, const QStringList &fields, con
QString execStr{};
const auto &supportedActions = actions();
auto optionsMap = options;
appendRuntimeScaleFactor(*this, optionsMap);
appendExtraEnvironments(optionsMap);
if (!realExec.isNull()) { // we want to replace exec of this applications.
if (realExec.isEmpty()) {

View File

@ -190,6 +190,7 @@ private:
static bool shouldBeShown(const std::unique_ptr<DesktopEntry> &entry) noexcept;
[[nodiscard]] bool autostartCheck(const QString &filePath) const noexcept;
void setAutostartSource(AutostartSource &&source) noexcept;
void appendExtraEnvironments(QVariantMap &runtimeOptions) const noexcept;
[[nodiscard]] ApplicationManager1Service *parent() { return dynamic_cast<ApplicationManager1Service *>(QObject::parent()); }
[[nodiscard]] const ApplicationManager1Service *parent() const
{