Sync: Spark Update Tool

This commit is contained in:
2026-01-17 10:23:11 +08:00
parent 5d4ee291d5
commit 3623850f63
13 changed files with 234 additions and 159 deletions
+27
View File
@@ -12,6 +12,7 @@
AppDelegate::AppDelegate(QObject *parent)
: QStyledItemDelegate(parent), m_downloadManager(new DownloadManager(this)), m_installProcess(nullptr) {
connect(m_downloadManager, &DownloadManager::downloadFinished, this,
[this](const QString &packageName, bool success) {
if (m_downloads.contains(packageName)) {
m_downloads[packageName].isDownloading = false;
@@ -39,6 +40,17 @@ AppDelegate::AppDelegate(QObject *parent)
connect(&m_spinnerUpdateTimer, &QTimer::timeout, this, &AppDelegate::updateSpinner);
}
AppDelegate::~AppDelegate()
{
// 终止并清理安装进程
if (m_installProcess && m_installProcess->state() != QProcess::NotRunning) {
m_installProcess->kill();
m_installProcess->waitForFinished(3000);
m_installProcess->deleteLater();
m_installProcess = nullptr;
}
}
void AppDelegate::setModel(QAbstractItemModel *model) {
m_model = model;
}
@@ -311,6 +323,14 @@ void AppDelegate::startDownloadForAll() {
if (!m_model) return;
for (int row = 0; row < m_model->rowCount(); ++row) {
QModelIndex index = m_model->index(row, 0);
// 检查应用是否被忽略
bool isIgnored = index.data(Qt::UserRole + 8).toBool();
if (isIgnored) {
qDebug() << "跳过被忽略的应用:" << index.data(Qt::UserRole + 1).toString();
continue;
}
QString packageName = index.data(Qt::UserRole + 1).toString();
if (m_downloads.contains(packageName) && (m_downloads[packageName].isDownloading || m_downloads[packageName].isInstalled))
continue;
@@ -474,6 +494,13 @@ void AppDelegate::startDownloadForSelected() {
QModelIndex index = m_model->index(row, 0);
QString packageName = index.data(Qt::UserRole + 1).toString();
// 检查应用是否被忽略
bool isIgnored = index.data(Qt::UserRole + 8).toBool();
if (isIgnored) {
qDebug() << "跳过被忽略的应用:" << packageName;
continue;
}
// 只下载选中的应用
if (m_selectedPackages.contains(packageName)) {
if (m_downloads.contains(packageName) && (m_downloads[packageName].isDownloading || m_downloads[packageName].isInstalled))
+1
View File
@@ -21,6 +21,7 @@ class AppDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
explicit AppDelegate(QObject *parent = nullptr);
~AppDelegate();
void setModel(QAbstractItemModel *model);
+15 -1
View File
@@ -10,6 +10,20 @@ DownloadManager::DownloadManager(QObject *parent) : QObject(parent)
cleanupTempFiles();
}
DownloadManager::~DownloadManager()
{
// 终止并清理所有正在运行的下载进程
for (auto it = m_processes.begin(); it != m_processes.end(); ) {
QProcess *process = it.value();
if (process->state() != QProcess::NotRunning) {
process->kill(); // 立即终止进程
process->waitForFinished(3000); // 最多等待3秒
}
process->deleteLater();
it = m_processes.erase(it);
}
}
void DownloadManager::startDownload(const QString &packageName, const QString &url, const QString &outputPath)
{
if (m_processes.contains(packageName)) {
@@ -114,4 +128,4 @@ void DownloadManager::cleanupTempFiles()
for (const QString &f : leftovers) {
tempDir.remove(f);
}
}
}
+2 -1
View File
@@ -10,6 +10,7 @@ class DownloadManager : public QObject
Q_OBJECT
public:
explicit DownloadManager(QObject *parent = nullptr);
~DownloadManager();
void startDownload(const QString &packageName, const QString &url, const QString &outputPath);
void cancelDownload(const QString &packageName);
bool isDownloading(const QString &packageName) const;
@@ -25,4 +26,4 @@ private:
QMap<QString, QProcess*> m_processes;
};
#endif // DOWNLOADMANAGER_H
#endif // DOWNLOADMANAGER_H