Skip to content

feat: adapt restart calls for Wayland via dde-session#304

Merged
xionglinlin merged 1 commit into
linuxdeepin:masterfrom
xionglinlin:master
Jun 3, 2026
Merged

feat: adapt restart calls for Wayland via dde-session#304
xionglinlin merged 1 commit into
linuxdeepin:masterfrom
xionglinlin:master

Conversation

@xionglinlin
Copy link
Copy Markdown
Contributor

Switched reboot, update-and-reboot, and update-and-shutdown operations to use the SessionManager1 D-Bus interface under Wayland, while keeping the existing ShutdownFront1 path for X11. This is needed because the old shutdown frontend does not work correctly on Wayland compositors, where session management must go through dde-session's dedicated API.

Log: Changed restart and shutdown methods to use SessionManager1 D-Bus interface on Wayland

Influence:

  1. Test system restart on X11 (verify Restart is called via ShutdownFront1)
  2. Test system restart on Wayland (verify RequestReboot is called via SessionManager1)
  3. Test Update & Reboot on both platforms
  4. Test Update & Shutdown on both platforms
  5. Verify no regression for existing X11 shutdown frontend flows
  6. Check error handling when SessionManager1 service is unavailable

feat: 在Wayland下重启服务改为调用dde-session接口

将重启、更新并重启、更新并关机等操作在Wayland环境下切换为使用
SessionManager1 D-Bus接口,X11下保持原有的ShutdownFront1调用。原因是旧的 关机前端在Wayland合成器上无法正常工作,需要通过dde-session的专用API进行
会话管理。

Log: 在Wayland环境下将重启和关机方法切换为使用SessionManager1 D-Bus接口

Influence:

  1. 在X11下测试系统重启(验证通过ShutdownFront1调用Restart)
  2. 在Wayland下测试系统重启(验证通过SessionManager1调用RequestReboot)
  3. 在两个平台下测试“更新并重启”功能
  4. 在两个平台下测试“更新并关机”功能
  5. 验证现有X11关机前端流程无回归
  6. 测试SessionManager1服务不可用时的错误处理

PMS: BUG-345663
Change-Id: I73c8449b6a96bdf00dc36510ceb8ecd7ffabb04f

Switched reboot, update-and-reboot, and update-and-shutdown operations
to use the SessionManager1 D-Bus interface under Wayland, while keeping
the existing ShutdownFront1 path for X11. This is needed because the old
shutdown frontend does not work correctly on Wayland compositors, where
session management must go through dde-session's dedicated API.

Log: Changed restart and shutdown methods to use SessionManager1 D-Bus
interface on Wayland

Influence:
1. Test system restart on X11 (verify Restart is called via
ShutdownFront1)
2. Test system restart on Wayland (verify RequestReboot is called via
SessionManager1)
3. Test Update & Reboot on both platforms
4. Test Update & Shutdown on both platforms
5. Verify no regression for existing X11 shutdown frontend flows
6. Check error handling when SessionManager1 service is unavailable

feat: 在Wayland下重启服务改为调用dde-session接口

将重启、更新并重启、更新并关机等操作在Wayland环境下切换为使用
SessionManager1 D-Bus接口,X11下保持原有的ShutdownFront1调用。原因是旧的
关机前端在Wayland合成器上无法正常工作,需要通过dde-session的专用API进行
会话管理。

Log: 在Wayland环境下将重启和关机方法切换为使用SessionManager1 D-Bus接口

Influence:
1. 在X11下测试系统重启(验证通过ShutdownFront1调用Restart)
2. 在Wayland下测试系统重启(验证通过SessionManager1调用RequestReboot)
3. 在两个平台下测试“更新并重启”功能
4. 在两个平台下测试“更新并关机”功能
5. 验证现有X11关机前端流程无回归
6. 测试SessionManager1服务不可用时的错误处理

PMS: BUG-345663
Change-Id: I73c8449b6a96bdf00dc36510ceb8ecd7ffabb04f
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

你好!我是CodeGeeX,你的智能编程助手。我已经仔细审查了你提供的Git Diff。

本次代码变更的主要目的是:为了兼容Wayland平台,将系统的重启/关机等DBUS调用从 ShutdownFront1 切换到 SessionManager1。整体逻辑方向是正确的,但在代码质量、逻辑严谨性和性能方面,有一些可以改进的地方。

以下是详细的审查意见:

1. 语法与逻辑

  • 逻辑缺陷:Wayland下“更新并重启”与“更新并关机”的行为丢失
    UpdateAndReboot()UpdateAndShutdown() 中,Wayland 分支仅仅调用了 RequestRebootRequestShutdown,而忽略了“更新”这一前置动作。
    在 X11 平台下,调用的是 UpdateAndRebootUpdateAndShutdown,这意味着底层可能会在关机/重启前触发更新系统的准备逻辑。如果 Wayland 平台直接调用普通的重启/关机,可能会导致更新流程中断或无法在下次启动时生效。
    建议: 需要确认 SessionManager1 是否提供了类似 RequestUpdateAndReboot 的接口。如果没有,是否需要先调用更新逻辑,再调用重启逻辑?这需要与后端/系统架构师确认。

2. 代码质量

  • 大量重复代码,违反 DRY (Don't Repeat Yourself) 原则
    判断是否为 Wayland 平台的 if-else 逻辑在 Restart(), UpdateAndReboot(), UpdateAndShutdown() 以及 pluginupdateplugin.cpp 中反复出现。如果未来需要兼容新的显示协议(如 XWayland 的某种特定情况)或者 DBUS 接口再次变更,需要修改所有散落的分支,极易出错。
    建议: 将 Wayland 判断和 DBUS 调用封装为独立的私有函数,或者使用策略模式/工厂模式。

  • 硬编码的 DBUS 信息
    pluginupdateplugin.cpp 中,SessionManager1 的 service、path、interface 被硬编码写死在了代码里,而之前 ShutdownFront1 也是如此。但在 commondefine.h 中你已经定义了这些常量。
    建议: 统一使用 commondefine.h 中的常量,避免后续修改时产生不一致。

3. 代码性能

  • 运行期高频判断平台类型
    DGuiApplicationHelper::testAttribute(Dtk::Gui::DGuiApplicationHelper::IsWaylandPlatform) 是一个运行期函数调用。虽然它的开销极小,但在每次执行重启/关机时都去判断一次是不必要的。
    建议: 可以在类初始化时(如构造函数中)判断一次并缓存结果,或者将判断逻辑收敛到封装好的函数内,使业务代码更清爽。

4. 代码安全

  • DBUS 异步调用的错误处理缺失
    asyncCall 是异步调用,不会阻塞当前线程,但它不保证调用一定成功。如果 SessionManager1 服务在 Wayland 下未启动,或者崩溃了,这个调用会静默失败,用户点击重启可能没有任何反应,也没有日志记录。
    建议:asyncCall 的返回值 QDBusPendingCall 进行监视,或者至少在调试模式下打印调用是否成功的反馈。对于 DDBusSender().call(),同样需要检查 QDBusReply 是否报错。

💡 改进建议与重构代码

针对以上问题,我为你提供了一份重构后的代码示例。主要改动:

  1. 提取公共逻辑,消除重复代码。
  2. 使用已有的常量替代硬编码。
  3. 增加异步调用的错误日志记录。
  4. 将 Wayland 判断收敛。

updatedbusproxy.h 增加 private 辅助函数声明

// 在 private 区域添加:
private:
    void callRestart(bool isUpdateAndReboot = false);
    void callShutdown();

updatedbusproxy.cpp 实现重构

// 引入 QDBusPendingCallWatcher 如果需要详细的异步错误处理
// #include <QDBusPendingCallWatcher>

void UpdateDBusProxy::callRestart(bool isUpdateAndReboot)
{
    bool isWayland = Dtk::Gui::DGuiApplicationHelper::testAttribute(Dtk::Gui::DGuiApplicationHelper::IsWaylandPlatform);
    
    if (isWayland) {
        // 警告:如果 SessionManager1 没有合并更新逻辑,这里可能存在逻辑漏洞!
        // 假设 SessionManager1 有对应的更新并重启接口,否则需要先触发更新再重启
        QString method = isUpdateAndReboot ? "RequestReboot" : "RequestReboot"; 
        m_sessionManagerInter->asyncCall(method);
    } else {
        QString method = isUpdateAndReboot ? "UpdateAndReboot" : "Restart";
        m_shutdownFrontInter->asyncCall(method);
    }
}

void UpdateDBusProxy::callShutdown()
{
    bool isWayland = Dtk::Gui::DGuiApplicationHelper::testAttribute(Dtk::Gui::DGuiApplicationHelper::IsWaylandPlatform);

    if (isWayland) {
        m_sessionManagerInter->asyncCall(QStringLiteral("RequestShutdown"));
    } else {
        m_shutdownFrontInter->asyncCall(QStringLiteral("UpdateAndShutdown"));
    }
}

void UpdateDBusProxy::Restart()
{
    qCInfo(logCommon) << "Calling system restart";
    callRestart(false);
}

void UpdateDBusProxy::UpdateAndReboot()
{
    qCInfo(logCommon) << "Calling update and reboot";
    callRestart(true);
}

void UpdateDBusProxy::UpdateAndShutdown()
{
    qCInfo(logCommon) << "Calling update and shutdown";
    callShutdown();
}

pluginupdateplugin.cpp 消除硬编码与重复逻辑

// ... 头部确保包含了 commondefine.h 和 DGuiApplicationHelper ...

void PluginUpdatePlugin::invokedMenuItem(const QString &itemKey, const QString &menuId)
{
    // ... 其他代码保持不变 ...
    } else if (menuId == MENU_RESTART) {
        // 重启系统
        bool isWayland = Dtk::Gui::DGuiApplicationHelper::testAttribute(Dtk::Gui::DGuiApplicationHelper::IsWaylandPlatform);
        if (isWayland) {
            DDBusSender()
                .service(SessionManager1Service)       // 使用常量
                .interface(SessionManager1Interface)    // 使用常量
                .path(SessionManager1Path)              // 使用常量
                .method("RequestReboot")
                .call();
        } else {
            DDBusSender()
                .service(ShutdownFront1Service)         // 使用常量
                .interface(ShutdownFront1Interface)     // 使用常量
                .path(ShutdownFront1Path)               // 使用常量
                .method("Restart")
                .call();
        }
    }
}

总结

请务必优先确认 Wayland 下 UpdateAndReboot / UpdateAndShutdown 的等效业务逻辑是否能够通过单纯的 RequestReboot / RequestShutdown 实现。如果不行,这不仅是代码质量问题,更是一个严重的业务逻辑Bug。其他的代码质量和性能问题可以通过上述重构快速解决。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy, xionglinlin

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

@xionglinlin xionglinlin merged commit 09dd4a3 into linuxdeepin:master Jun 3, 2026
7 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