diff --git a/CMakeLists.txt b/CMakeLists.txt index dacab38..e58fa05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/apps/app-launch-helper/src/CMakeLists.txt b/apps/app-launch-helper/src/CMakeLists.txt index cb069a0..158bad6 100644 --- a/apps/app-launch-helper/src/CMakeLists.txt +++ b/apps/app-launch-helper/src/CMakeLists.txt @@ -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}) diff --git a/apps/app-update-notifier/src/CMakeLists.txt b/apps/app-update-notifier/src/CMakeLists.txt index 969abce..c0a5687 100644 --- a/apps/app-update-notifier/src/CMakeLists.txt +++ b/apps/app-update-notifier/src/CMakeLists.txt @@ -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}) diff --git a/debian/dde-application-manager.install b/debian/dde-application-manager.install index 5b88b0f..2a6496c 100644 --- a/debian/dde-application-manager.install +++ b/debian/dde-application-manager.install @@ -4,4 +4,4 @@ usr/lib/* usr/libexec/* usr/share/dbus-1/* usr/share/dsg/* - +usr/share/deepin/dde-application-manager/hooks.d/* diff --git a/docs/applicationHooks.md b/docs/applicationHooks.md index 203b58b..260ee35 100644 --- a/docs/applicationHooks.md +++ b/docs/applicationHooks.md @@ -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`结尾。 diff --git a/misc/CMakeLists.txt b/misc/CMakeLists.txt index db95ffc..98a85c0 100644 --- a/misc/CMakeLists.txt +++ b/misc/CMakeLists.txt @@ -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 diff --git a/misc/hooks.d/1-dockEnv.json.in b/misc/hooks.d/1-dockEnv.json.in new file mode 100644 index 0000000..5df4da4 --- /dev/null +++ b/misc/hooks.d/1-dockEnv.json.in @@ -0,0 +1,4 @@ +{ + "Exec": "@CMAKE_INSTALL_PREFIX@/@AM_LIBEXEC_DIR@/dockEnv.sh", + "Args":[] +} diff --git a/misc/hooks.d/dockEnv.sh b/misc/hooks.d/dockEnv.sh new file mode 100644 index 0000000..0ef5331 --- /dev/null +++ b/misc/hooks.d/dockEnv.sh @@ -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 "$@" diff --git a/src/dbus/applicationservice.cpp b/src/dbus/applicationservice.cpp index 0f29058..a7671cb 100644 --- a/src/dbus/applicationservice.cpp +++ b/src/dbus/applicationservice.cpp @@ -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(); } @@ -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()) { diff --git a/src/dbus/applicationservice.h b/src/dbus/applicationservice.h index 97ac604..807daf8 100644 --- a/src/dbus/applicationservice.h +++ b/src/dbus/applicationservice.h @@ -190,6 +190,7 @@ private: static bool shouldBeShown(const std::unique_ptr &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(QObject::parent()); } [[nodiscard]] const ApplicationManager1Service *parent() const {