Skip to content

fix: show loading page before delayed archive loading on Wayland#406

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
LiHua000:release/eagle
May 8, 2026
Merged

fix: show loading page before delayed archive loading on Wayland#406
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
LiHua000:release/eagle

Conversation

@LiHua000
Copy link
Copy Markdown
Contributor

@LiHua000 LiHua000 commented May 8, 2026

On Wayland, loadArchive is deferred by 200ms via QTimer but the page ID was not set to PI_Loading beforehand, causing the home page to flash briefly before the loading animation appeared.

Bug: https://pms.uniontech.com/bug-view-359077.html

Summary by Sourcery

Bug Fixes:

  • Set the loading page state before the deferred archive load on Wayland so the home page does not appear briefly before the loading animation.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 8, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

On Wayland, ensure the loading page is shown immediately when opening an archive whose actual load is delayed by a QTimer, preventing a brief flash of the home page before the loading animation.

Sequence diagram for delayed archive loading with immediate loading page on Wayland

sequenceDiagram
    actor User
    participant MainWindow
    participant UiTools
    participant QTimer
    participant UI
    participant ArchiveLoader

    User->>MainWindow: handleArguments_Open(listParam)
    MainWindow->>UiTools: isWayland()
    UiTools-->>MainWindow: true
    MainWindow->>MainWindow: firstLoad check and set false
    MainWindow->>MainWindow: path = listParam[0]
    MainWindow->>MainWindow: m_ePageID = PI_Loading
    MainWindow->>UI: refreshPage()
    MainWindow->>QTimer: singleShot(200ms, callback)

    QTimer-->>MainWindow: callback after 200ms
    MainWindow->>ArchiveLoader: loadArchive(path)
    ArchiveLoader-->>UI: display archive contents
Loading

Class diagram for MainWindow loading state handling on Wayland

classDiagram
    class MainWindow {
        - PageID m_ePageID
        - bool firstLoad
        + bool handleArguments_Open(QStringList listParam)
        + void refreshPage()
        + void loadArchive(QString path)
    }

    class UiTools {
        + static bool isWayland()
    }

    class QTimer {
        + static void singleShot(int msec, Callable callback)
    }

    MainWindow ..> UiTools : uses
    MainWindow ..> QTimer : schedules_delay
    MainWindow ..> MainWindow : updates_m_ePageID_and_refreshPage
Loading

File-Level Changes

Change Details Files
Show the loading page immediately before the delayed archive loading on Wayland to avoid flashing the home page.
  • When handling open arguments on Wayland for the first load, set the current page ID to the loading page state before starting the delayed archive load.
  • Trigger a page refresh right after setting the page ID so the loading UI appears during the 200ms delay before loadArchive is called.
  • Leave the existing 200ms QTimer-based deferred call to loadArchive(path) unchanged.
src/source/mainwindow.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 reviewed your changes and they look great!


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.

On Wayland, the window position is set by the compositor for
non-first instances. Previously the archive loading was delayed
unconditionally on Wayland, causing the home page to flash.
Now only non-first instances delay loading, and show the loading
animation before the delay to avoid flashing.

Bug: https://pms.uniontech.com/bug-view-359077.html
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码的修改主要针对 Wayland 环境下的多实例弹窗显示问题,通过引入延迟加载机制来解决窗口位置设置的问题。以下是对这段代码的审查意见:

1. 语法逻辑审查

优点:

  • 逻辑清晰,在 Wayland 环境下通过设置 m_bDelayQueryDialog 标志位来控制延迟加载。
  • 使用 QTimer::singleShot 实现了异步延迟加载,避免了阻塞主线程。

问题与建议:

  1. 变量初始化位置m_bDelayQueryDialog 在头文件中直接初始化为 false,虽然 C++11 允许这样做,但为了保持代码风格统一,建议在构造函数初始化列表中进行初始化。

    // mainwindow.h
    bool m_bDelayQueryDialog; // 移除默认初始化
    
    // mainwindow.cpp 构造函数中
    MainWindow::MainWindow(QWidget *parent) 
        : m_bDelayQueryDialog(false) // 在初始化列表中初始化
    {
    }
  2. 条件判断优化:在 main.cpp 中,if(!orderObject)else 分支中都有相同的 Wayland 判断逻辑,可以考虑提取公共逻辑:

    auto setupWaylandDelay = [&]() {
        if (UiTools::isWayland()) {
            w.setDelayQueryDialog(true);
        }
    };
    
    if(!orderObject) {
        if (dbus.registerService("com.deepin.compressor")) {
            Dtk::Widget::moveToCenter(&w);
        } else {
            setupWaylandDelay();
        }
    } else {
        // ... 类似处理
    }

2. 代码质量审查

优点:

  • 注释清晰,说明了 Wayland 下需要延迟的原因。
  • 使用了 RAII 风格的 lambda 捕获 thispath,避免了内存泄漏风险。

问题与建议:

  1. 魔法数字QTimer::singleShot(200, ...) 中的 200 毫秒是硬编码的,建议定义为常量:

    // 在类定义中或头文件中定义
    static constexpr int WAYLAND_DELAY_MS = 200;
    
    // 使用时
    QTimer::singleShot(WAYLAND_DELAY_MS, [this, path]() {
        loadArchive(path);
    });
  2. 变量命名m_bDelayQueryDialog 采用了匈牙利命名法(m_b 前缀表示布尔类型),这不符合现代 C++ 的命名规范。建议改为 delayQueryDialog_m_delayQueryDialog

3. 代码性能审查

优点:

  • 使用静态变量 firstLoad 改为成员变量 m_bDelayQueryDialog 是合理的,因为静态变量在多实例场景下会有问题。

问题与建议:

  1. 延迟时间:200ms 的延迟时间可能不够稳定,建议根据实际测试结果调整,或者考虑监听窗口管理器的信号来确定窗口位置已设置完成。

4. 代码安全审查

问题与建议:

  1. lambda 捕获 this:在 QTimer::singleShot 的 lambda 中捕获 this 指针,如果 MainWindow 在延迟期间被销毁,会导致悬空指针。建议使用 QPointer 进行保护:

    QTimer::singleShot(WAYLAND_DELAY_MS, this, [this, path]() {
        if (this) { // 检查对象是否仍然存在
            loadArchive(path);
        }
    });
  2. 边界检查auto path = listParam[0] 没有检查 listParam 是否为空,如果传入空列表会导致未定义行为。建议添加边界检查:

    if (listParam.isEmpty()) {
        qWarning() << "Empty file list provided";
        return false;
    }
    auto path = listParam[0];

综合改进建议

  1. 将魔法数字定义为常量
  2. 使用更安全的 lambda 捕获方式
  3. 添加参数边界检查
  4. 统一变量初始化位置
  5. 提取重复的 Wayland 处理逻辑
  6. 考虑使用更现代的命名规范

这些改进将使代码更健壮、更易维护,同时保持原有功能不变。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: LiHua000, max-lvs

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

@LiHua000
Copy link
Copy Markdown
Contributor Author

LiHua000 commented May 8, 2026

/merge

@deepin-bot deepin-bot Bot merged commit 62a3f5d into linuxdeepin:release/eagle May 8, 2026
16 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