Skip to content

fix: Add delay before application exit to ensure config is saved#679

Merged
lzwind merged 1 commit intolinuxdeepin:masterfrom
re2zero:bugfix
Sep 17, 2025
Merged

fix: Add delay before application exit to ensure config is saved#679
lzwind merged 1 commit intolinuxdeepin:masterfrom
re2zero:bugfix

Conversation

@re2zero
Copy link
Copy Markdown
Contributor

@re2zero re2zero commented Sep 16, 2025

Implement a delay of 1000ms before quitting the application to allow asynchronous configuration saving to complete. This change enhances the reliability of the application exit process.

Log: Add delay before application exit to ensure config is saved.
Bug: https://pms.uniontech.com/bug-view-333889.html

Summary by Sourcery

Delay application exit by 1000ms when saving configuration to ensure the async write completes before quitting.

Bug Fixes:

  • Ensure configuration is saved to disk by waiting 1 second before calling QApplication::quit()

Enhancements:

  • Use QTimer::singleShot to schedule the application quit
  • Hide the main window immediately after scheduling the delayed exit

Implement a delay of 1000ms before quitting the application to allow asynchronous configuration saving to complete. This change enhances the reliability of the application exit process.

Log: Add delay before application exit to ensure config is saved.
Bug: https://pms.uniontech.com/bug-view-333889.html
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Sep 16, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Implemented a 1000ms exit delay using QTimer to ensure asynchronous config saving completes before quitting, replacing the direct quit call and updating related logging and window handling.

Sequence diagram for delayed application exit after config save

sequenceDiagram
    participant User
    participant MainWindow
    participant CooperationUtil
    participant QTimer
    participant QApplication
    User->>MainWindow: Initiate close dialog
    MainWindow->>User: Show close dialog
    User->>MainWindow: Accept dialog
    MainWindow->>CooperationUtil: saveOption(isExit)
    Note right of CooperationUtil: Asynchronous config save
    MainWindow->>QTimer: singleShot(1000ms, quit)
    QTimer->>QApplication: quit()
    MainWindow->>MainWindow: hide()
Loading

Class diagram for updated MainWindow exit logic

classDiagram
    class MainWindow {
        +showCloseDialog()
        -int delay
    }
    class CooperationUtil {
        +saveOption(isExit)
    }
    MainWindow --> CooperationUtil : uses
    MainWindow --> QTimer : uses
    MainWindow --> QApplication : uses
Loading

File-Level Changes

Change Details Files
Introduce exit delay to allow asynchronous config persistence
  • Add QTimer include
  • Declare and initialize delay variable when saving options
  • Use QTimer::singleShot to schedule QApplication::quit() with the delay
  • Update exit log to include delay value
  • Hide the main window after scheduling exit
src/lib/cooperation/core/gui/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

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码的审查意见如下:

  1. 代码逻辑和功能:
  • 代码实现了关闭对话框的功能,包括保存选项、退出或最小化应用程序
  • 使用了QTimer来实现延迟退出,确保配置写入完成
  • 整体逻辑清晰,功能完整
  1. 语法和格式:
  • 代码格式规范,缩进正确
  • 包含了必要的头文件
  • 使用了lambda表达式,符合现代C++风格
  1. 代码质量改进建议:
  • 建议将延迟时间(1000ms)定义为常量或配置项,而不是硬编码在代码中
  • lambda表达式中的逻辑应该提取为单独的函数,提高可读性和可维护性
  • 建议添加注释说明为什么需要延迟退出,因为当前注释可能不足以解释异步写入配置的背景
  1. 性能考虑:
  • 使用QTimer::singleShot是合理的,不会阻塞主线程
  • 延迟时间固定为1秒,可能需要根据实际写入性能进行调整
  1. 代码安全性:
  • 代码中没有明显的安全问题
  • 使用了Qt的信号槽机制,是线程安全的
  1. 具体改进建议:
// 建议将延迟时间定义为常量
static const int CONFIG_WRITE_DELAY_MS = 1000;

// 建议将lambda表达式提取为单独的函数
void MainWindow::performExit() {
    QApplication::quit();
}

// 在showCloseDialog中使用
if (isExit) {
    DLOG << "Exiting application with delay:" << delay;
    QTimer::singleShot(delay, this, &MainWindow::performExit);
}
  1. 其他建议:
  • 考虑添加异常处理,以防配置写入失败
  • 可以考虑添加用户反馈,告知用户正在保存配置并即将退出

总体来说,这段代码实现了一个合理的功能,但可以通过一些改进来提高可维护性和可读性。

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 there - 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.

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, re2zero

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 0cbedde into linuxdeepin:master Sep 17, 2025
15 of 17 checks passed
@re2zero re2zero deleted the bugfix branch September 17, 2025 09:32
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