Skip to content

Conversation

@Mars-cb
Copy link
Contributor

@Mars-cb Mars-cb commented Sep 10, 2025

部分机器x未初始化完成导致设置的geometry未生效,增加容错时间检查geometry并重新设置

Log:
Bug: https://pms.uniontech.com/bug-view-332651.html
Influence: 登录界面位置
Change-Id: I9315076978ade341c56fc410868ef31d1940e50d

deepin-ci-robot added a commit to linuxdeepin/dde-session-shell-snipe that referenced this pull request Sep 10, 2025
Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#36
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Mars-cb, waterlovemelon

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

部分机器x未初始化完成导致设置的geometry未生效,增加容错时间检查geometry并重新设置

Log:
Bug: https://pms.uniontech.com/bug-view-332651.html
Influence: 登录界面位置
Change-Id: I9315076978ade341c56fc410868ef31d1940e50d
deepin-ci-robot added a commit to linuxdeepin/dde-session-shell-snipe that referenced this pull request Sep 10, 2025
Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#36
@deepin-ci-robot
Copy link

deepin pr auto review

我来分析这段代码的变更,并提供一些改进建议:

代码变更分析:

  1. resetGeometryTimer 的超时处理函数中增加了几何形状比较逻辑,避免不必要的 setGeometry 调用
  2. 增加了更详细的调试日志输出
  3. setddeGeometry 函数中的超时时间从 2005 增加到 4005

改进建议:

  1. 性能优化

    • 增加几何形状比较是个好改进,但可以考虑使用 QRect::operator!= 进行更明确的比较
    • 可以考虑将 m_geometryRect 和当前几何形状的比较放在 setddeGeometry 函数中,避免不必要的定时器启动
  2. 代码质量

    • 调试日志中使用了 qCDebug,建议在正式版本中考虑使用条件编译或日志级别控制
    • 建议将超时时间定义为命名常量,如 const int GEOMETRY_RESET_TIMEOUT = 400;,提高代码可读性
  3. 代码逻辑

    • 定时器的启动和停止逻辑可以封装成一个独立函数,提高代码复用性
    • 考虑添加错误处理,例如当定时器对象为空时的处理
  4. 代码安全

    • 确保在对象析构时停止定时器,避免潜在的内存问题
    • 考虑使用 QPointer 来管理定时器对象,防止在对象被删除后仍然访问

建议的改进代码:

// 在头文件中定义常量
static const int GEOMETRY_RESET_TIMEOUT = 400;
static const int GEOMETRY_RESET_DELAY = 200;

// 构造函数中
connect(m_resetGeometryTimer, &QTimer::timeout, this, [this]() {
    const auto currentGeometry = geometry();
    if (currentGeometry != m_geometryRect) {
        qCDebug(DCE_SHELL) << "Geometry mismatch. Current:" << currentGeometry 
                          << "Expected:" << m_geometryRect;
        setGeometry(m_geometryRect);
    }
});

// 改进后的 setddeGeometry 函数
void FullScreenBackground::setddeGeometry(const QRect &rect)
{
    if (rect == geometry()) {
        return; // 无需更新
    }
    
    setGeometry(rect);
    m_geometryRect = rect;
    
    if (!m_resetGeometryTimer) {
        qCWarning(DCE_SHELL) << "Reset geometry timer is not initialized";
        return;
    }
    
    m_resetGeometryTimer->start(GEOMETRY_RESET_DELAY);
    QTimer::singleShot(GEOMETRY_RESET_TIMEOUT * 5, m_resetGeometryTimer, &QTimer::stop);
}

// 析构函数中
FullScreenBackground::~FullScreenBackground()
{
    if (m_resetGeometryTimer) {
        m_resetGeometryTimer->stop();
    }
}

这些改进可以提高代码的可维护性、性能和安全性,同时保持原有功能不变。

@Mars-cb
Copy link
Contributor Author

Mars-cb commented Sep 10, 2025

/meger

@Mars-cb
Copy link
Contributor Author

Mars-cb commented Sep 10, 2025

/merge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Sep 10, 2025

This pr cannot be merged! (status: unstable)

@waterlovemelon waterlovemelon merged commit 1eae767 into linuxdeepin:master Sep 10, 2025
14 of 15 checks passed
yixinshark pushed a commit to linuxdeepin/dde-session-shell-snipe that referenced this pull request Sep 12, 2025
Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#36
yixinshark pushed a commit to linuxdeepin/dde-session-shell-snipe that referenced this pull request Sep 12, 2025
Synchronize source files from linuxdeepin/dde-session-shell.

Source-pull-request: linuxdeepin/dde-session-shell#36
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