fix:修复关闭提示弹窗时机问题

This commit is contained in:
2025-10-11 16:57:39 +08:00
parent 89fb73ae0c
commit 8f240db798
3 changed files with 34 additions and 2 deletions

View File

@@ -448,4 +448,9 @@ QSet<QString> AppDelegate::getSelectedPackages() const {
void AppDelegate::clearSelection() {
m_selectedPackages.clear();
}
// 实现获取下载状态信息的方法
const QHash<QString, DownloadInfo>& AppDelegate::getDownloads() const {
return m_downloads;
}

View File

@@ -35,6 +35,10 @@ public:
void setSelectedPackages(const QSet<QString> &selected);
QSet<QString> getSelectedPackages() const;
void clearSelection();
// 获取下载状态信息
const QHash<QString, DownloadInfo>& getDownloads() const;
signals:
void updateDisplay(const QString &packageName);

View File

@@ -344,8 +344,31 @@ void MainWindow::runAptssUpgrade()
}
void MainWindow::closeEvent(QCloseEvent *event)
{
QMessageBox::StandardButton reply = QMessageBox::question(this, "确认关闭", "正在更新,是否确认关闭窗口?", QMessageBox::Yes | QMessageBox::No);
// 检查是否正在进行更新
bool isUpdating = false;
// 通过AppDelegate检查是否有正在下载或安装的应用
const QHash<QString, DownloadInfo>& downloads = m_delegate->getDownloads();
for (auto it = downloads.constBegin(); it != downloads.constEnd(); ++it) {
if (it.value().isDownloading || it.value().isInstalling) {
isUpdating = true;
break;
}
}
// 如果正在更新,才显示确认对话框
if (isUpdating) {
QMessageBox::StandardButton reply = QMessageBox::question(this, "确认关闭", "正在更新,是否确认关闭窗口?", QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes) {
event->accept();
} else {
event->ignore();
}
} else {
// 如果没有更新,直接关闭窗口
event->accept();
}
}
void MainWindow::handleUpdateFinished(bool success)
{