Skip to content

feat: complete launchpad logging integration#753

Open
Ivy233 wants to merge 1 commit intolinuxdeepin:masterfrom
Ivy233:feat/event-logger-integration
Open

feat: complete launchpad logging integration#753
Ivy233 wants to merge 1 commit intolinuxdeepin:masterfrom
Ivy233:feat/event-logger-integration

Conversation

@Ivy233
Copy link
Copy Markdown
Contributor

@Ivy233 Ivy233 commented Apr 26, 2026

Add optional dde-api detection and Debian build dependency updates, and finish launchpad-side logging support in the shared launcher controller. Keep the launchpad build configuration and packaging aligned with the new logging integration.

feat: 完善启动器日志集成

增加可选 dde-api 检测与 Debian 构建依赖更新,并在共享启动器控制器中补全启动器侧日志支持。 同步更新启动器的构建配置与打包依赖,使新的日志集成能够正确构建和交付。

PMS: TASK-388657

Summary by Sourcery

Integrate optional dde-api based event logging for launchpad mode and wire it into the shared launcher controller while updating build configuration accordingly.

New Features:

  • Add launchpad mode event logging via dde-api EventLogger on startup and when the frame mode changes.

Enhancements:

  • Update launcher controller copyright years to cover 2023–2026.

Build:

  • Detect optional dde-api eventlogger headers in CMake and conditionally enable related compilation flags for the launchpad common library.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 26, 2026

Reviewer's Guide

Integrates optional dde-api based event logging into the launchpad shared launcher controller, conditionally wiring it via CMake detection of dde-api headers and aligning Debian build metadata with the new logging capability.

Sequence diagram for launchpad startup logging in LauncherController constructor

sequenceDiagram
    participant CMake as CMake_build
    participant LC as LauncherController
    participant Settings as QSettings
    participant Log as QLoggingCategory_logController
    participant EventLogger as DDE_EventLogger_EventLogger

    CMake->>CMake: detect dde-api/eventlogger.hpp
    alt eventlogger header found
        CMake->>LC: define HAVE_DDE_API_EVENTLOGGER
    else not found
        CMake-->>LC: HAVE_DDE_API_EVENTLOGGER not defined
    end

    LC->>Settings: value("current_frame", "WindowedFrame")
    Settings-->>LC: m_currentFrame
    LC->>Log: qCInfo logController << "Current frame mode:" << m_currentFrame

    alt HAVE_DDE_API_EVENTLOGGER defined
        LC->>EventLogger: instance().init("org.deepin.dde.launchpad", false)
        LC->>EventLogger: instance().writeEventLog(EventLoggerData(EVENT_LOGGER_LAUNCHPAD_MODE, "launchpad_config", {"launchpad_mode", m_currentFrame}))
        LC->>Log: qCInfo logController << "EventLogger: launchpad mode on startup:" << m_currentFrame
    else event logging disabled
        LC-->>LC: skip event logging
    end
Loading

Sequence diagram for logging on frame mode change via setCurrentFrame

sequenceDiagram
    actor User
    participant UI as Launchpad_UI
    participant LC as LauncherController
    participant Log as QLoggingCategory_logController
    participant EventLogger as DDE_EventLogger_EventLogger

    User->>UI: change launchpad frame mode
    UI->>LC: setCurrentFrame(newFrame)

    LC->>LC: m_currentFrame = newFrame
    LC->>Log: qDebug << "set current frame:" << m_currentFrame

    alt HAVE_DDE_API_EVENTLOGGER defined
        LC->>EventLogger: instance().writeEventLog(EventLoggerData(EVENT_LOGGER_LAUNCHPAD_MODE, "launchpad_config", {"launchpad_mode", m_currentFrame}))
        LC->>Log: qCInfo logController << "EventLogger: launchpad mode changed to:" << m_currentFrame
    else event logging disabled
        LC-->>LC: no event log emitted
    end

    LC->>LC: m_pendingHide = false
    LC->>LC: m_timer.start()
    LC-->>UI: emit currentFrameChanged()
Loading

Class diagram for optional EventLogger integration in LauncherController

classDiagram
    class LauncherController {
        - QString m_currentFrame
        - bool m_pendingHide
        + LauncherController(QObject *parent)
        + void setCurrentFrame(QString frame)
    }

    class DDE_EventLogger_EventLogger {
        + static DDE_EventLogger_EventLogger instance()
        + void init(QString appId, bool enableDebug)
        + void writeEventLog(DDE_EventLogger_EventLoggerData data)
    }

    class DDE_EventLogger_EventLoggerData {
        + DDE_EventLogger_EventLoggerData(qint64 eventId, QString category, std::map<QString, QString> payload)
        + qint64 eventId
        + QString category
        + std::map<QString, QString> payload
    }

    class BuildConfig {
        + bool HAVE_DDE_API_EVENTLOGGER
        + qint64 EVENT_LOGGER_LAUNCHPAD_MODE
    }

    LauncherController ..> DDE_EventLogger_EventLogger : uses when
    LauncherController ..> DDE_EventLogger_EventLoggerData : creates when
    BuildConfig <.. LauncherController : compile_time_flag
    BuildConfig <.. DDE_EventLogger_EventLogger : event_id_constant
Loading

Flow diagram for CMake-based optional dde-api EventLogger wiring

flowchart TD
    A[CMake_configuration_start] --> B[unset DDE_API_EVENTLOGGER_INCLUDE_DIR CACHE]
    B --> C[find_path for dde-api/eventlogger.hpp in /usr/include]

    C -->|found| D[set HAVE_DDE_API_EVENTLOGGER ON]
    C -->|not_found| E[HAVE_DDE_API_EVENTLOGGER is OFF]

    D --> F[message: Found dde-api eventlogger.hpp]
    E --> G[message: event logging will be disabled]

    D --> H[add compile_definition HAVE_DDE_API_EVENTLOGGER to target launchpadcommon]
    E --> I[no compile_definition added]

    H --> J[LauncherController compiled with EventLogger calls enabled]
    I --> K[LauncherController compiled without EventLogger calls]

    J --> L[runtime: launchpad emits dde-api event logs]
    K --> M[runtime: only standard logging used]
Loading

File-Level Changes

Change Details Files
Add optional dde-api EventLogger-based logging of launchpad frame mode on startup and when it changes.
  • Include dde-api/eventlogger.hpp behind a compile-time feature macro and define a constant event ID for launchpad mode logging.
  • Initialize the dde-api EventLogger singleton in the launcher controller constructor when available.
  • Emit structured event logs containing the current launchpad mode on startup and every time the frame mode changes, alongside existing qCInfo debug output.
launchercontroller.cpp
Add build-time detection and wiring for dde-api eventlogger support and align packaging dependencies.
  • Use CMake find_path to detect the presence of dde-api/eventlogger.hpp and set a HAVE_DDE_API_EVENTLOGGER option accordingly, with status messages for both success and failure cases.
  • Propagate the HAVE_DDE_API_EVENTLOGGER definition to the launchpadcommon target so code can be conditionally compiled.
  • Update Debian packaging control to declare dde-api (or related) as a build dependency matching the new optional logging integration.
  • Update SPDX copyright years in the launcher controller source file.
CMakeLists.txt
debian/control
launchercontroller.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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

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, and left some high level feedback:

  • The CMake detection for dde-api/eventlogger.hpp is hardcoded to /usr/include; consider using standard include search paths (e.g., relying on CMAKE_INCLUDE_PATH/CMAKE_PREFIX_PATH or a pkg-config module) instead of a fixed path to make the build more portable.
  • The event logging calls for startup and frame changes duplicate the construction of EventLoggerData; extracting a small helper method (e.g., logLaunchpadMode(const QString &mode)) would reduce repetition and keep the logging logic consistent in one place.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The CMake detection for `dde-api/eventlogger.hpp` is hardcoded to `/usr/include`; consider using standard include search paths (e.g., relying on `CMAKE_INCLUDE_PATH`/`CMAKE_PREFIX_PATH` or a pkg-config module) instead of a fixed path to make the build more portable.
- The event logging calls for startup and frame changes duplicate the construction of `EventLoggerData`; extracting a small helper method (e.g., `logLaunchpadMode(const QString &mode)`) would reduce repetition and keep the logging logic consistent in one place.

## Individual Comments

### Comment 1
<location path="launchercontroller.cpp" line_range="50-55" />
<code_context>
     qCInfo(logController) << "Current frame mode:" << m_currentFrame;

+#ifdef HAVE_DDE_API_EVENTLOGGER
+    DDE_EventLogger::EventLogger::instance().init("org.deepin.dde.launchpad", false);
+    DDE_EventLogger::EventLogger::instance().writeEventLog(
+        DDE_EventLogger::EventLoggerData(EVENT_LOGGER_LAUNCHPAD_MODE, "launchpad_config", {
+            {"launchpad_mode", m_currentFrame}
+        }));
+    qCInfo(logController) << "EventLogger: launchpad mode on startup:" << m_currentFrame;
+#endif
+
</code_context>
<issue_to_address>
**suggestion:** Consider wrapping the event logging logic in a small helper to avoid duplication and keep constructor/setter in sync.

The `writeEventLog` call with `EVENT_LOGGER_LAUNCHPAD_MODE` and identical payload appears both here and in `setCurrentFrame`. Extracting this into a small private helper (e.g. `logLaunchpadMode(const QString &mode, const QString &reason)`) would remove duplication and ensure both call sites stay consistent when the event format or ID changes.

Suggested implementation:

```cpp
#include <private/qguiapplication_p.h>

```

```cpp
#include <QDBusConnection>
#include <QLoggingCategory>

#ifdef HAVE_DDE_API_EVENTLOGGER
#include <dde-api/eventlogger.hpp>

// Event ID for launchpad mode (10-digit number)
constexpr qint64 EVENT_LOGGER_LAUNCHPAD_MODE = 1000600016;

namespace {
    void logLaunchpadMode(const QString &mode, const QString &reason)
    {
        auto &logger = DDE_EventLogger::EventLogger::instance();
        logger.init(QStringLiteral("org.deepin.dde.launchpad"), false);
        logger.writeEventLog(DDE_EventLogger::EventLoggerData(
            EVENT_LOGGER_LAUNCHPAD_MODE,
            reason,
            {
                { QStringLiteral("launchpad_mode"), mode }
            }));
        qCInfo(logController) << "EventLogger: launchpad mode" << reason << ":" << mode;
    }
}
#endif

```

```cpp
    m_currentFrame = settings.value("current_frame", "WindowedFrame").toString();
    qCInfo(logController) << "Current frame mode:" << m_currentFrame;

#ifdef HAVE_DDE_API_EVENTLOGGER
    logLaunchpadMode(m_currentFrame, QStringLiteral("launchpad_config"));
#endif

```

I only see the constructor snippet. To fully apply the refactoring and avoid duplication, you should also:
1. Locate the `setCurrentFrame(...)` implementation in `launchercontroller.cpp` and replace its duplicated `DDE_EventLogger::EventLogger::instance().init(...)` / `writeEventLog(...)` block (and related `qCInfo` line) with:
   ```cpp
   #ifdef HAVE_DDE_API_EVENTLOGGER
       logLaunchpadMode(m_currentFrame, QStringLiteral("launchpad_config"));
   #endif
   ```
2. Ensure there is no remaining direct use of `EVENT_LOGGER_LAUNCHPAD_MODE` outside `logLaunchpadMode` (unless intentionally needed elsewhere), so future changes only need to touch the helper.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread launchercontroller.cpp Outdated
@Ivy233 Ivy233 force-pushed the feat/event-logger-integration branch from 0271567 to 35baf43 Compare April 26, 2026 13:41
BLumia
BLumia previously approved these changes Apr 27, 2026
Comment thread CMakeLists.txt Outdated
Comment thread CMakeLists.txt Outdated
@Ivy233 Ivy233 force-pushed the feat/event-logger-integration branch 3 times, most recently from b9e343c to 36d9123 Compare April 29, 2026 08:59
使用多字段事件日志记录器并迁移到 cmake find_package

- Migrate from find_path to find_package(DDEAPI)
- Link DDEAPI::EventLogger to dde-control-center
- Fix pt_BR translation for control center name

PMS: TASK-388657
@Ivy233 Ivy233 force-pushed the feat/event-logger-integration branch from 36d9123 to 33fbf9a Compare April 29, 2026 10:11
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码的主要目的是为启动器添加事件日志记录功能,通过集成 dde-api 中的 EventLogger 来记录启动器模式的切换。以下是对该代码的审查意见,包括语法逻辑、代码质量、代码性能和代码安全方面的改进建议。

1. 语法逻辑

  • CMakeLists.txt:
    • 逻辑清晰,使用 find_packageif/else 块来检测依赖项是正确的。
    • target_link_libraries 中使用了 PRIVATE 关键字,这是正确的,因为 EventLogger 的使用被封装在 launchercontroller.cpp 中,不需要暴露给依赖 launchpadcommon 的其他库。
  • debian/control:
    • 添加了 dde-api-dev 构建依赖,逻辑正确。
  • launchercontroller.cpp:
    • 使用了 #ifdef HAVE_DDE_API_EVENTLOGGER 进行条件编译,逻辑正确,确保在没有该库时也能正常编译。
    • logLaunchpadMode 函数的实现逻辑清晰,构造了日志数据并调用 API。

2. 代码质量

  • 魔法数字:
    • launchercontroller.cpp 中定义了 constexpr qint64 EVENT_LOGGER_LAUNCHPAD_MODE = 1000610012;。这是一个"魔法数字"(Magic Number)。虽然使用了 constexpr 和有意义的变量名,但建议添加注释说明这个 ID 的来源或含义,或者确认是否应该从某个公共头文件中引用。
  • 硬编码字符串:
    • QStringLiteral("launchpad_config")QStringLiteral("launchpad_mode") 被硬编码在代码中。建议将这些键名定义为常量,以便于维护和避免拼写错误。
    • 例如:
      namespace Constants {
          constexpr const char* EVENT_SOURCE = "launchpad_config";
          constexpr const char* EVENT_KEY_MODE = "launchpad_mode";
      }
  • 日志一致性:
    • logLaunchpadMode 函数中,无论是否定义了 HAVE_DDE_API_EVENTLOGGER,都会执行 qCInfo 输出日志。这很好,保证了调试信息的一致性。

3. 代码性能

  • 字符串构造:
    • DDE_EventLogger::EventLoggerData 的构造涉及 QStringQMap(或类似容器)的初始化。由于这是在 UI 响应路径(设置当前帧)上执行的,虽然开销不大,但值得注意。目前的实现是可接受的。
  • 条件编译:
    • 使用 #ifdef 宏在编译期移除了未使用依赖时的代码,这是最佳实践,不会对运行时性能产生负面影响。

4. 代码安全

  • 输入验证:
    • logLaunchpadMode 接收 const QString &mode 作为参数,但没有对 mode 的内容进行验证。如果 mode 包含恶意构造的字符串或异常长的数据,可能会对日志系统造成压力(虽然 EventLogger 内部可能有处理机制,但防御性编程更好)。
    • 建议: 检查 mode 是否为空或长度是否合理,或者确保 EventLogger 能够安全处理任意字符串。
  • 依赖版本:
    • debian/control 中指定了 dde-api-dev (>> 6.0.39)。这是一个好的做法,确保了构建环境中有包含 EventLogger 的正确版本。

综合改进建议代码示例

针对 launchercontroller.cpp 的改进建议:

// ... 头文件包含 ...

namespace {
Q_LOGGING_CATEGORY(logController, "org.deepin.dde.launchpad.controller")

// 定义常量,避免魔法数字和硬编码字符串
namespace EventLogConstants {
    constexpr qint64 EVENT_ID_LAUNCHPAD_MODE = 1000610012; // TODO: 添加该ID来源的注释
    constexpr const char* EVENT_SOURCE = "launchpad_config";
    constexpr const char* KEY_MODE = "launchpad_mode";
    constexpr int MAX_MODE_LENGTH = 64; // 假设模式名称不应超过64个字符
}

void logLaunchpadMode(const QString &mode, const char *description)
{
    // 安全性改进:输入验证
    if (mode.isEmpty()) {
        qCWarning(logController) << "Attempted to log an empty launchpad mode";
        return;
    }
    
    // 可选:防止过长的字符串
    if (mode.length() > EventLogConstants::MAX_MODE_LENGTH) {
        qCWarning(logController) << "Launchpad mode exceeds maximum length";
        return;
    }

#ifdef HAVE_DDE_API_EVENTLOGGER
    // 使用定义的常量
    DDE_EventLogger::EventLogger::instance().writeEventLog(
        DDE_EventLogger::EventLoggerData(EventLogConstants::EVENT_ID_LAUNCHPAD_MODE, 
                                         QLatin1String(EventLogConstants::EVENT_SOURCE), 
        {
            {QLatin1String(EventLogConstants::KEY_MODE), mode}
        }));
#endif
    // 使用 QLatin1String 或 QStringLiteral 提高字符串字面量处理效率
    qCInfo(logController) << "EventLogger: launchpad mode" << description << ":" << mode;
}
// ...

总结

这段代码整体质量良好,逻辑清晰,正确使用了 CMake 的特性来处理可选依赖。主要的改进点在于:

  1. 消除魔法数字和硬编码字符串,使用常量定义。
  2. 在日志记录函数中增加基本的输入验证,提高鲁棒性。
  3. 添加必要的注释说明关键常量的含义。

这些改进将有助于代码的长期维护和可读性。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, Ivy233

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

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.

5 participants