Skip to content

fix: change close dialog default to exit and ignore close event only on minimise - #834

Open
pppanghu77 wants to merge 1 commit into
linuxdeepin:release/v20from
pppanghu77:agent/agent/65c75bd30995
Open

pppanghu77 wants to merge 1 commit into
linuxdeepin:release/v20from
pppanghu77:agent/agent/65c75bd30995

Conversation

@pppanghu77

@pppanghu77 pppanghu77 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Root Cause Analysis

When the user closes the dde-cooperation main window, MainWindow::closeEvent unconditionally calls event->ignore() after showCloseDialog(), preventing Qt from closing the window and exiting the process. The close dialog defaults to "Minimise to system tray", so the process stays alive in the background. Even when the user cancels the dialog, event->ignore() still prevents the window from closing.

Key evidence: mainwindow.cpp:182 — showCloseDialog(); event->ignore(); runs unconditionally; showCloseDialog() at line 201 has op1->setChecked(true) defaulting to "Minimise".

Fix Approach

Two-part fix (combo A+B as approved by root cause review):

  1. Change the default checkbox from "Minimise to system tray" to "Exit" (op2->setChecked(true))
  2. Change showCloseDialog() to return bool (true = minimise path, false = exit/cancel), and only call event->ignore() when it returns true — allowing Qt to handle the close event normally on exit or cancel

Change Safety Assessment

Code Safety

  • Risk Level: Medium
  • showCloseDialog() signature changed from void to bool, but only 1 caller (closeEvent at mainwindow.cpp:182) which is updated accordingly
  • The "minimise to tray" feature introduced by commit a976c756 (PMS 250143) is preserved as a user-selectable option; this change does not revert any historical fix
  • Related PMS bugs (282501, 250143, 228067) checked — no regression risk

Business Impact Scope

Affected module: dde-cooperation main window close behaviour. Users closing the window will now default to exiting the process. The minimise-to-tray option remains available. Existing users with saved "Minimise" preference are unaffected.

Verification Suggestion

Test all three close paths: select "Exit" (process exits), select "Minimise to system tray" (process stays in tray), cancel dialog (window closes, process exits). Also test "don't ask again" with both options.


根因分析

用户关闭 dde-cooperation 主窗口时,MainWindow::closeEvent 在 showCloseDialog() 后无条件调用 event->ignore(),阻止 Qt 关闭窗口和退出进程。关闭对话框默认勾选"最小化到系统托盘",导致进程驻留后台。即使用户取消对话框,event->ignore() 仍然阻止窗口关闭。

关键证据:mainwindow.cpp:182 — showCloseDialog(); event->ignore(); 无条件执行;showCloseDialog() 第 201 行 op1->setChecked(true) 默认勾选"最小化"。

修复方案

组合方案 A+B(经根因复核结论采纳):

  1. 将默认勾选项从"最小化到系统托盘"改为"退出"(op2->setChecked(true))
  2. 将 showCloseDialog() 改为返回 bool(true=最小化路径,false=退出/取消),仅在返回 true 时调用 event->ignore()——退出或取消时允许 Qt 正常处理关闭事件

改动安全评估

代码安全评估

  • 风险等级: 中风险
  • showCloseDialog() 签名从 void 改为 bool,但仅有 1 处调用者(mainwindow.cpp:182 的 closeEvent)已同步修改
  • commit a976c756(PMS 250143)引入的"最小化到托盘"功能保留为用户可选项,本次改动不撤销任何历史修复
  • 关联 PMS bug(282501、250143、228067)已检查,无回归风险

业务影响范围

受影响模块:dde-cooperation 主窗口关闭行为。用户关闭窗口时默认退出进程。最小化到托盘选项仍可用。已保存"最小化"选项的老用户不受影响。

验证建议

测试关闭窗口的三种路径:选择"退出"(进程退出)、选择"最小化到系统托盘"(进程保留在托盘)、取消对话框(窗口关闭且进程退出)。同时测试"不再询问"两种选项的保存行为。

PMS: BUG-274633

Summary by Sourcery

Ensure closing the cooperation main window exits by default while retaining the option to minimise it to the system tray.

Bug Fixes:

  • Fix main-window close handling so choosing Exit or cancelling the close dialog allows the application to close normally.
  • Make Exit the default close-dialog option while preserving minimisation to the system tray as an explicit choice.

Chores:

  • Update copyright years for the affected main-window source files.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, we are unable to review this pull request

The GitHub API does not allow us to fetch diffs exceeding 20000 lines

@github-actions

Copy link
Copy Markdown

TAG Bot

TAG: 0.8.9
EXISTED: no
DISTRIBUTION: unstable

…on minimise

1. Root cause: closeEvent unconditionally called event->ignore() after
   showCloseDialog(), preventing Qt from closing the window and exiting
   the process regardless of user choice; default option was "Minimise"
   which kept the process alive in background
2. Fix: change showCloseDialog() to return bool (true=minimise path,
   false=exit/cancel), only call event->ignore() when it returns true;
   change default checkbox from "Minimise to system tray" to "Exit"
3. Impact: closing window now defaults to exit; cancelling the dialog
   allows normal window close; minimise-to-tray remains available as
   user-selected option; existing users with saved "Minimise" unaffected

Log: close window now defaults to exit instead of minimise to tray

Influence:
1. Test closing window with default "Exit" option - process should exit
2. Test selecting "Minimise to system tray" - process stays in tray
3. Test cancelling dialog - window closes and process exits
4. Test "don't ask again" with both options - saved behaviour persists
5. Verify existing users with saved "Minimise" still get minimise behaviour

fix: 关闭对话框默认选项改为退出且仅在最小化时忽略关闭事件

1. 根因:closeEvent 在 showCloseDialog() 后无条件调用 event->ignore(),
   阻止 Qt 关闭窗口和退出进程;默认选项为"最小化"导致进程驻留后台
2. 方案:将 showCloseDialog() 改为返回 bool(true=最小化路径,
   false=退出/取消),仅在返回 true 时调用 event->ignore();
   将默认勾选项从"最小化到系统托盘"改为"退出"
3. 影响:关闭窗口默认退出进程;取消对话框时窗口正常关闭;
   最小化到托盘仍作为用户可选选项保留;已保存"最小化"的用户不受影响

Log: 关闭窗口默认改为退出而非最小化到托盘

Influence:
1. 测试默认"退出"选项关闭窗口 - 进程应退出
2. 测试选择"最小化到系统托盘" - 进程保留在托盘
3. 测试取消对话框 - 窗口关闭且进程退出
4. 测试"不再询问"两种选项 - 保存的行为持续生效
5. 验证已保存"最小化"的用户仍保持最小化行为

Bug: #274633
@pppanghu77
pppanghu77 changed the base branch from master to release/v20 October 28, 2026 19:00
@pppanghu77
pppanghu77 force-pushed the agent/agent/65c75bd30995 branch from 7bdf73a to d0840d6 Compare October 28, 2026 19:08
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pppanghu77

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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次变更将 showCloseDialog() 返回值改为 bool,使 closeEvent 仅在最小化时忽略关闭事件,逻辑清晰且与 commit 目的一致。四维度均无问题,无安全漏洞,代码质量良好。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['建议将 if (isExit) 的大括号移至同一行,即 if (isExit) {,与 else 块风格保持一致']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例

// 建议统一大括号风格为 K&R 风格 if (isExit) {
    QApplication::quit();
    return false;
} else {
    minimizedAPP();
    return true;
}

本报告由 AI 代码审查工具自动生成

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.

2 participants