From 8f240db798ebb6a94f888b355aed484a8480b280 Mon Sep 17 00:00:00 2001 From: momen Date: Sat, 11 Oct 2025 16:57:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E5=BC=B9=E7=AA=97=E6=97=B6=E6=9C=BA=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/appdelegate.cpp | 5 +++++ src/appdelegate.h | 4 ++++ src/mainwindow.cpp | 27 +++++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/appdelegate.cpp b/src/appdelegate.cpp index e51bff8..c9e4540 100644 --- a/src/appdelegate.cpp +++ b/src/appdelegate.cpp @@ -448,4 +448,9 @@ QSet AppDelegate::getSelectedPackages() const { void AppDelegate::clearSelection() { m_selectedPackages.clear(); +} + +// 实现获取下载状态信息的方法 +const QHash& AppDelegate::getDownloads() const { + return m_downloads; } \ No newline at end of file diff --git a/src/appdelegate.h b/src/appdelegate.h index bedd645..25ea337 100644 --- a/src/appdelegate.h +++ b/src/appdelegate.h @@ -35,6 +35,10 @@ public: void setSelectedPackages(const QSet &selected); QSet getSelectedPackages() const; void clearSelection(); + + // 获取下载状态信息 + const QHash& getDownloads() const; + signals: void updateDisplay(const QString &packageName); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4e76371..c93f09a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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& 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) {