Skip to content

fix: 修复窗口位置显示不正确的问题#24

Merged
lzwind merged 1 commit intolinuxdeepin:masterfrom
lzwind:master
Jan 4, 2026
Merged

fix: 修复窗口位置显示不正确的问题#24
lzwind merged 1 commit intolinuxdeepin:masterfrom
lzwind:master

Conversation

@lzwind
Copy link
Contributor

@lzwind lzwind commented Jan 4, 2026

将 move() 调用移到 show() 之前,避免窗口先显示在错误位置再移动导致的闪烁,
同时确保在 setJsonData() 完成布局计算后再获取窗口尺寸。

Log: 修复窗口位置显示不正确的问题
Bug: https://pms.uniontech.com/bug-view-325485.html

将 move() 调用移到 show() 之前,避免窗口先显示在错误位置再移动导致的闪烁,
同时确保在 setJsonData() 完成布局计算后再获取窗口尺寸。

Log: 修复窗口位置显示不正确的问题
Bug: https://pms.uniontech.com/bug-view-325485.html
@github-actions
Copy link

github-actions bot commented Jan 4, 2026

TAG Bot

TAG: 5.5.5
EXISTED: no
DISTRIBUTION: unstable

@deepin-ci-robot
Copy link

deepin pr auto review

我来对这个 Git diff 进行详细审查:

  1. 代码语法逻辑审查:
  • 代码语法正确,没有明显的语法错误
  • 逻辑流程清晰,修改合理
  1. 代码质量改进建议:

a) 在 newClientProcess 函数中:

localSocket->waitForBytesWritten(1000);

建议:

  • 将超时时间定义为常量,提高代码可维护性
  • 检查 waitForBytesWritten 的返回值,确保数据写入成功

b) 在 processArgs 函数中:

w->hide();
QApplication::processEvents();
w->adjustSize();

建议:

  • processEvents() 可能导致重入问题,建议使用更安全的方式
  • 可以考虑使用 QTimer::singleShot(0, ...) 来异步处理这些操作
  1. 代码性能优化建议:

a) 在 readData 函数中:

for (const QByteArray &data : message.split('\0')) {
    QString str = QString::fromLocal8Bit(data);
    if (!str.isEmpty()) {
        list << str;
    }
}

建议:

  • 可以使用 reserve() 预分配 list 的空间
  • 考虑使用 QString::fromUtf8() 替代 fromLocal8Bit(),以获得更好的国际化支持
  1. 代码安全建议:

a) 在 newClientProcess 函数中:

localSocket->deleteLater();

建议:

  • 添加错误处理,确保 socket 正确关闭
  • 在写入失败时进行适当的错误处理

b) 在 processArgs 函数中:

w->move(pos);
w->show();

建议:

  • 添加边界检查,确保窗口不会移动到屏幕外
  • 考虑多显示器环境的情况
  1. 其他改进建议:

a) 版本号管理:

  • changelog 中的版本号从 5.5.4 直接跳到 5.5.5,建议遵循语义化版本控制规范

b) 注释优化:

  • 可以添加更详细的函数说明注释
  • 在关键操作处添加注释说明原因

具体修改建议示例:

// 定义常量
static const int SOCKET_WRITE_TIMEOUT = 1000;

void SingleApplication::newClientProcess(const QString &key, const QByteArray &message)
{
    QLocalSocket *localSocket = new QLocalSocket();
    localSocket->connectToServer(userServerName(key));
    
    if (localSocket->waitForConnected(1000)) {
        if (localSocket->state() == QLocalSocket::ConnectedState) {
            qDebug() << "Connected to existing instance, sending message";
            localSocket->write(message);
            localSocket->flush();
            
            // 检查写入是否成功
            if (!localSocket->waitForBytesWritten(SOCKET_WRITE_TIMEOUT)) {
                qWarning() << "Failed to write message:" << localSocket->errorString();
            }
        }
    } else {
        qWarning() << "Failed to connect to existing instance:" << localSocket->errorString();
    }
    
    // 确保资源正确释放
    localSocket->disconnectFromServer();
    localSocket->deleteLater();
}
void SingleApplication::processArgs(const QStringList &list)
{
    // ... 其他代码 ...
    
    // 使用更安全的方式处理窗口显示
    w->hide();
    w->setJsonData(jsonData);
    
    if (cmdManager.enableBypassWindowManagerHint()) {
        w->setWindowFlags(w->windowFlags() | Qt::BypassWindowManagerHint);
    }
    
    // 使用单次定时器确保安全的异步处理
    QTimer::singleShot(0, [this, w, pos]() {
        w->adjustSize();
        
        // 确保窗口位置在屏幕范围内
        QRect screenGeometry = QApplication::desktop()->screenGeometry();
        pos = QPoint(
            qBound(0, pos.x(), screenGeometry.width() - w->width()),
            qBound(0, pos.y(), screenGeometry.height() - w->height())
        );
        
        w->move(pos);
        w->show();
    });
}

这些修改将提高代码的健壮性、可维护性和安全性。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Johnson-zs, lzwind

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

@lzwind lzwind merged commit 2dcb329 into linuxdeepin:master Jan 4, 2026
4 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