Skip to content

Conversation

@fly602
Copy link
Contributor

@fly602 fly602 commented Oct 30, 2025

  1. Removed the PowerManager D-Bus interface dependency from the shutdown plugin
  2. Replaced PowerManager with SessionManager for power-related operations
  3. Deleted the auto-generated DBusPowerManager files (cpp and header)
  4. Added new SessionManager D-Bus interface XML definition and generated implementation files
  5. Updated shutdown plugin to use SessionManager for CanSuspend() and CanHibernate() checks
  6. Changed D-Bus connection from systemBus to sessionBus for SessionManager

This change simplifies the dependency chain by using SessionManager which provides the same power management functionality that was previously handled by PowerManager. The SessionManager interface is more comprehensive and better integrated with the desktop session management.

Log: Power management operations now use SessionManager instead of PowerManager

Influence:

  1. Test suspend functionality to ensure CanSuspend() works correctly
  2. Test hibernate functionality to verify CanHibernate() returns correct values
  3. Verify shutdown menu displays correct options based on system capabilities
  4. Test power operations (suspend/hibernate) actually work when selected
  5. Verify D-Bus connection to SessionManager is established properly
  6. Test error handling when SessionManager is unavailable

重构:移除 PowerManager 依赖并使用 SessionManager

  1. 从关机插件中移除了 PowerManager D-Bus 接口依赖
  2. 使用 SessionManager 替代 PowerManager 进行电源相关操作
  3. 删除了自动生成的 DBusPowerManager 文件(cpp 和头文件)
  4. 添加了新的 SessionManager D-Bus 接口 XML 定义和生成的实现文件
  5. 更新关机插件使用 SessionManager 进行 CanSuspend() 和 CanHibernate() 检查
  6. 将 D-Bus 连接从 systemBus 改为 sessionBus 以连接 SessionManager

此更改通过使用 SessionManager 简化了依赖链,SessionManager 提供了与之前 PowerManager 处理的相同电源管理功能。SessionManager 接口更全面,能更好地 与桌面会话管理集成。

Log: 电源管理操作现在使用 SessionManager 而不是 PowerManager

Influence:

  1. 测试挂起功能确保 CanSuspend() 正常工作
  2. 测试休眠功能验证 CanHibernate() 返回正确值
  3. 验证关机菜单根据系统功能显示正确选项
  4. 测试选择的电源操作(挂起/休眠)实际可用
  5. 验证与 SessionManager 的 D-Bus 连接正确建立
  6. 测试 SessionManager 不可用时错误处理

Summary by Sourcery

Refactor the shutdown plugin to replace the PowerManager D-Bus interface with the SessionManager interface for power operations, removing the old DBusPowerManager files and updating the plugin to use sessionBus connections.

Enhancements:

  • Remove DBusPowerManager dependency and generated files from the shutdown plugin
  • Add SessionManager D-Bus XML definition and generated proxy implementation
  • Update shutdown plugin to use SessionManager's CanSuspend() and CanHibernate() methods
  • Switch D-Bus connection from systemBus to sessionBus for session-based power management

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 30, 2025

Reviewer's Guide

This PR refactors the shutdown plugin to replace the PowerManager D-Bus interface with the SessionManager interface for all power operations. The change removes the old DBusPowerManager code, updates shutdown logic to use SessionManager over the sessionBus, and introduces new XML definitions and generated proxy files for SessionManager.

Sequence diagram for shutdown plugin power operation checks using SessionManager

sequenceDiagram
    participant ShutdownPlugin
    participant SessionManager
    ShutdownPlugin->>SessionManager: CanSuspend()
    SessionManager-->>ShutdownPlugin: bool (can suspend)
    ShutdownPlugin->>SessionManager: CanHibernate()
    SessionManager-->>ShutdownPlugin: bool (can hibernate)
Loading

Entity relationship diagram for SessionManager D-Bus interface methods and properties

erDiagram
    SESSIONMANAGER {
        bool CanSuspend
        bool CanHibernate
        bool CanLogout
        bool CanReboot
        bool CanShutdown
        void ForceLogout
        void ForceReboot
        void ForceShutdown
        void Logout
        void PowerOffChoose
        void Reboot
        bool Register
        void RequestHibernate
        void RequestLock
        void RequestLogout
        void RequestReboot
        void RequestShutdown
        void RequestSuspend
        void SetLocked
        void Shutdown
        void ToggleDebug
        bool Locked
        string CurrentUid
        int Stage
        object CurrentSessionPath
    }
    %% All methods and properties are part of the SessionManager entity
Loading

Class diagram for replacement of PowerManager with SessionManager

classDiagram
    class ShutdownPlugin {
        - bool m_pluginLoaded
        - QScopedPointer<CommonIconButton> m_dockIcon
        - QScopedPointer<Dock::TipsWidget> m_tipsLabel
        - SessionManager* m_sessionManagerInter
        - QSharedPointer<DConfig> m_dconfig
        - DConfig *m_lastoreDConfig
        + itemContextMenu(itemKey: QString): QString
    }
    class SessionManager {
        + AllowSessionDaemonRun(): QDBusPendingReply<bool>
        + CanHibernate(): QDBusPendingReply<bool>
        + CanLogout(): QDBusPendingReply<bool>
        + CanReboot(): QDBusPendingReply<bool>
        + CanShutdown(): QDBusPendingReply<bool>
        + CanSuspend(): QDBusPendingReply<bool>
        + ForceLogout(): QDBusPendingReply<>
        + ForceReboot(): QDBusPendingReply<>
        + ForceShutdown(): QDBusPendingReply<>
        + Logout(): QDBusPendingReply<>
        + PowerOffChoose(): QDBusPendingReply<>
        + Reboot(): QDBusPendingReply<>
        + Register(in0: QString): QDBusPendingReply<bool>
        + RequestHibernate(): QDBusPendingReply<>
        + RequestLock(): QDBusPendingReply<>
        + RequestLogout(): QDBusPendingReply<>
        + RequestReboot(): QDBusPendingReply<>
        + RequestShutdown(): QDBusPendingReply<>
        + RequestSuspend(): QDBusPendingReply<>
        + SetLocked(in0: bool): QDBusPendingReply<>
        + Shutdown(): QDBusPendingReply<>
        + ToggleDebug(): QDBusPendingReply<>
        + ~SessionManager()
        + currentSessionPath: QDBusObjectPath
        + currentUid: QString
        + locked: bool
        + stage: int
    }
    ShutdownPlugin --> SessionManager : uses
    %% DBusPowerManager class removed
Loading

File-Level Changes

Change Details Files
Migrate shutdown plugin from PowerManager to SessionManager for power operations
  • Replaced DBusPowerManager include and member with SessionManager
  • Updated CanSuspend() and CanHibernate() calls to use SessionManager
  • Switched D-Bus connection from systemBus to sessionBus
plugins/dde-dock/shutdown/shutdownplugin.cpp
plugins/dde-dock/shutdown/shutdownplugin.h
Remove old DBusPowerManager proxy and add SessionManager interface definitions
  • Deleted auto-generated DBusPowerManager header and source
  • Added SessionManager XML interface definition
  • Generated SessionManager proxy header and implementation
plugins/dde-dock/shutdown/dbus/dbuspowermanager.h
plugins/dde-dock/shutdown/dbus/dbuspowermanager.cpp
plugins/dde-dock/dbus/xml/org.deepin.dde.SessionManager.xml
plugins/dde-dock/shutdown/dbus/org_deepin_dde_sessionmanager.h
plugins/dde-dock/shutdown/dbus/org_deepin_dde_sessionmanager.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

@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 there - I've reviewed your changes - here's some feedback:

  • The new SessionManager::CanSuspend/CanHibernate methods return QDBusPendingReply, so you should synchronously wait for the reply or switch to a QDBusReply to extract the actual boolean value before using it in your conditions.
  • Add explicit error handling or fallback logic for when the SessionManager D-Bus interface is unavailable or returns an error, so the shutdown plugin can still gracefully handle missing session services.
  • Since you switched to sessionBus for power operations, verify coverage on environments where the session bus might not expose power methods and consider reverting to systemBus or providing a fallback mechanism in those cases.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new SessionManager::CanSuspend/CanHibernate methods return QDBusPendingReply<bool>, so you should synchronously wait for the reply or switch to a QDBusReply to extract the actual boolean value before using it in your conditions.
- Add explicit error handling or fallback logic for when the SessionManager D-Bus interface is unavailable or returns an error, so the shutdown plugin can still gracefully handle missing session services.
- Since you switched to sessionBus for power operations, verify coverage on environments where the session bus might not expose power methods and consider reverting to systemBus or providing a fallback mechanism in those cases.

## Individual Comments

### Comment 1
<location> `plugins/dde-dock/shutdown/dbus/org_deepin_dde_sessionmanager.h:1` </location>
<code_context>
-//
-// SPDX-License-Identifier: LGPL-3.0-or-later
-
-/*
- * This file was generated by qdbusxml2cpp version 0.8
- * Command line was: qdbusxml2cpp -c PowerManager -p com_deepin_daemon_powermanager com.deepin.daemon.PowerManager.xml
</code_context>

<issue_to_address>
**issue (complexity):** Consider avoiding checking in large generated boilerplate by either hand-writing only needed D-Bus methods or generating proxies at build-time.

Here are two ways to avoid checking in that 200-line generated boilerplate while keeping the exact same D-Bus calls:

1) Use QDBusInterface (or wrap it) and only hand-write the few methods you actually call:  
```cpp
// SessionManager.h
#include <QtDBus/QtDBus>

class SessionManager : QObject {
    Q_OBJECT
    QDBusInterface iface_;
public:
    explicit SessionManager(QObject* parent = nullptr)
      : QObject(parent)
      , iface_("org.deepin.dde.SessionManager1",
               "/org/deepin/dde/SessionManager1",
               "org.deepin.dde.SessionManager1",
               QDBusConnection::sessionBus(), this)
    {}

    // helper to reduce repetition
    template<typename... Args>
    auto call(const char* method, Args&&... args) {
        return iface_.asyncCall(method, std::forward<Args>(args)...);
    }

    // only implement what you use:
    QDBusPendingReply<bool> CanHibernate()  { return call("CanHibernate"); }
    QDBusPendingReply<bool> CanReboot()     { return call("CanReboot"); }
    QDBusPendingReply<>        Logout()     { return call("Logout"); }
    // …etc.
};
```
This removes all the 30+ identical inline stubs and cuts boilerplate.

2) Or keep using qdbusxml2cpp but generate the proxy at build-time instead of checking it into git:  
```cmake
add_custom_command(
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/SessionManager.h
         ${CMAKE_CURRENT_BINARY_DIR}/SessionManager.cpp
  COMMAND qdbusxml2cpp
          -p SessionManager
          ${CMAKE_CURRENT_SOURCE_DIR}/org.deepin.dde.SessionManager.xml
  DEPENDS org.deepin.dde.SessionManager.xml
)

target_include_directories(your_target PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_sources(your_target PRIVATE
  ${CMAKE_CURRENT_BINARY_DIR}/SessionManager.cpp
)
```
This way you get the full proxy without inflating your repo or manually editing generated code.
</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.

@@ -0,0 +1,200 @@
/*
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider avoiding checking in large generated boilerplate by either hand-writing only needed D-Bus methods or generating proxies at build-time.

Here are two ways to avoid checking in that 200-line generated boilerplate while keeping the exact same D-Bus calls:

  1. Use QDBusInterface (or wrap it) and only hand-write the few methods you actually call:
// SessionManager.h
#include <QtDBus/QtDBus>

class SessionManager : QObject {
    Q_OBJECT
    QDBusInterface iface_;
public:
    explicit SessionManager(QObject* parent = nullptr)
      : QObject(parent)
      , iface_("org.deepin.dde.SessionManager1",
               "/org/deepin/dde/SessionManager1",
               "org.deepin.dde.SessionManager1",
               QDBusConnection::sessionBus(), this)
    {}

    // helper to reduce repetition
    template<typename... Args>
    auto call(const char* method, Args&&... args) {
        return iface_.asyncCall(method, std::forward<Args>(args)...);
    }

    // only implement what you use:
    QDBusPendingReply<bool> CanHibernate()  { return call("CanHibernate"); }
    QDBusPendingReply<bool> CanReboot()     { return call("CanReboot"); }
    QDBusPendingReply<>        Logout()     { return call("Logout"); }
    // …etc.
};

This removes all the 30+ identical inline stubs and cuts boilerplate.

  1. Or keep using qdbusxml2cpp but generate the proxy at build-time instead of checking it into git:
add_custom_command(
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/SessionManager.h
         ${CMAKE_CURRENT_BINARY_DIR}/SessionManager.cpp
  COMMAND qdbusxml2cpp
          -p SessionManager
          ${CMAKE_CURRENT_SOURCE_DIR}/org.deepin.dde.SessionManager.xml
  DEPENDS org.deepin.dde.SessionManager.xml
)

target_include_directories(your_target PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_sources(your_target PRIVATE
  ${CMAKE_CURRENT_BINARY_DIR}/SessionManager.cpp
)

This way you get the full proxy without inflating your repo or manually editing generated code.

18202781743
18202781743 previously approved these changes Oct 30, 2025
1. Removed the PowerManager D-Bus interface dependency from the shutdown
plugin
2. Replaced PowerManager with SessionManager for power-related
operations
3. Deleted the auto-generated DBusPowerManager files (cpp and header)
4. Added new SessionManager D-Bus interface XML definition and generated
implementation files
5. Updated shutdown plugin to use SessionManager for CanSuspend() and
CanHibernate() checks
6. Changed D-Bus connection from systemBus to sessionBus for
SessionManager

This change simplifies the dependency chain by using SessionManager
which provides the same power management functionality that was
previously handled by PowerManager. The SessionManager interface is more
comprehensive and better integrated with the desktop session management.

Log: Power management operations now use SessionManager instead of
PowerManager

Influence:
1. Test suspend functionality to ensure CanSuspend() works correctly
2. Test hibernate functionality to verify CanHibernate() returns correct
values
3. Verify shutdown menu displays correct options based on system
capabilities
4. Test power operations (suspend/hibernate) actually work when selected
5. Verify D-Bus connection to SessionManager is established properly
6. Test error handling when SessionManager is unavailable

重构:移除 PowerManager 依赖并使用 SessionManager

1. 从关机插件中移除了 PowerManager D-Bus 接口依赖
2. 使用 SessionManager 替代 PowerManager 进行电源相关操作
3. 删除了自动生成的 DBusPowerManager 文件(cpp 和头文件)
4. 添加了新的 SessionManager D-Bus 接口 XML 定义和生成的实现文件
5. 更新关机插件使用 SessionManager 进行 CanSuspend() 和 CanHibernate()
检查
6. 将 D-Bus 连接从 systemBus 改为 sessionBus 以连接 SessionManager

此更改通过使用 SessionManager 简化了依赖链,SessionManager 提供了与之前
PowerManager 处理的相同电源管理功能。SessionManager 接口更全面,能更好地
与桌面会话管理集成。

Log: 电源管理操作现在使用 SessionManager 而不是 PowerManager

Influence:
1. 测试挂起功能确保 CanSuspend() 正常工作
2. 测试休眠功能验证 CanHibernate() 返回正确值
3. 验证关机菜单根据系统功能显示正确选项
4. 测试选择的电源操作(挂起/休眠)实际可用
5. 验证与 SessionManager 的 D-Bus 连接正确建立
6. 测试 SessionManager 不可用时错误处理
@deepin-ci-robot
Copy link

deepin pr auto review

我来对这个diff进行代码审查:

  1. 语法逻辑:
  • 代码语法正确,XML格式规范,符合D-Bus接口定义标准
  • 类的声明和实现符合Qt的编码规范
  • 文件包含和命名空间使用正确
  1. 代码质量:
  • 优点:

    • 代码结构清晰,接口定义完整
    • 使用了Qt的D-Bus框架,符合项目架构
    • 文件头包含完整的版权信息
    • 使用了Q_PROPERTY宏正确地定义了属性
    • 方法命名规范,遵循驼峰命名法
  • 可改进之处:

    • 新的SessionManager类应该添加错误处理机制
    • 建议为异步调用添加超时处理
    • 可以考虑添加接口调用的日志记录
  1. 代码性能:
  • 使用了QDBusPendingReply进行异步调用,性能良好
  • 属性访问使用了内联函数,减少函数调用开销
  • 建议对频繁调用的接口考虑添加本地缓存机制
  1. 代码安全:
  • 接口权限控制:
    • 系统级操作(如关机、重启)需要适当的权限验证
    • 建议添加用户身份验证机制
  • 参数验证:
    • Register方法的字符串参数需要长度限制
    • 建议对输入参数进行合法性检查
  1. 其他建议:
  • 考虑添加接口版本控制,便于后续升级
  • 建议添加接口文档,说明各方法的具体用途和参数要求
  • 可以考虑添加接口调用状态回调机制
  • 建议对关键操作添加确认机制,防止误操作

总体来说,这次改动主要是将PowerManager接口替换为SessionManager接口,代码质量良好,但建议在安全性方面进行加强。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@fly602
Copy link
Contributor Author

fly602 commented Oct 30, 2025

/forcemerge

@deepin-bot
Copy link

deepin-bot bot commented Oct 30, 2025

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit 125ef98 into linuxdeepin:master Oct 30, 2025
8 of 10 checks passed
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.

3 participants