mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-09-11 22:02:21 +08:00
chore:异步更新
This commit is contained in:
parent
b5e0b709cc
commit
b68029f5db
@ -9,8 +9,8 @@ set(CMAKE_AUTORCC ON)
|
|||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network)
|
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network Concurrent)
|
||||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network)
|
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Network Concurrent)
|
||||||
|
|
||||||
set(PROJECT_SOURCES
|
set(PROJECT_SOURCES
|
||||||
main.cpp
|
main.cpp
|
||||||
@ -47,7 +47,7 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(Spark-Update-Tool PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network)
|
target_link_libraries(Spark-Update-Tool PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Concurrent)
|
||||||
|
|
||||||
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
|
||||||
# If you are developing for iOS or macOS you should consider setting an
|
# If you are developing for iOS or macOS you should consider setting an
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
#include "./ui_mainwindow.h"
|
#include "./ui_mainwindow.h"
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QProgressDialog>
|
||||||
|
#include <QtConcurrent> // 新增
|
||||||
|
#include <QFutureWatcher> // 新增
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
@ -9,40 +12,57 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
, m_model(new AppListModel(this))
|
, m_model(new AppListModel(this))
|
||||||
, m_delegate(new AppDelegate(this))
|
, m_delegate(new AppDelegate(this))
|
||||||
{
|
{
|
||||||
runAptssUpgrade();
|
QProgressDialog *progressDialog = new QProgressDialog("正在与服务器通信,获取更新信息中...", QString(), 0, 0, this);
|
||||||
|
progressDialog->setWindowModality(Qt::ApplicationModal);
|
||||||
|
progressDialog->setCancelButton(nullptr);
|
||||||
|
progressDialog->setWindowTitle("请稍候");
|
||||||
|
progressDialog->setMinimumDuration(0);
|
||||||
|
progressDialog->setWindowFlags(progressDialog->windowFlags() & ~Qt::WindowCloseButtonHint); // 禁用关闭按钮
|
||||||
|
progressDialog->show();
|
||||||
|
//异步执行runAptssUpgrade
|
||||||
|
QFutureWatcher<void> *watcher = new QFutureWatcher<void>(this);
|
||||||
|
connect(watcher, &QFutureWatcher<void>::finished, this, [=]() {
|
||||||
|
progressDialog->close();
|
||||||
|
progressDialog->deleteLater();
|
||||||
|
watcher->deleteLater();
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
ui->setupUi(this);
|
// 创建 QListView 并设置父控件为 ui->appWidget
|
||||||
|
listView = new QListView(ui->appWidget);
|
||||||
|
listView->setModel(m_model);
|
||||||
|
listView->setItemDelegate(m_delegate);
|
||||||
|
|
||||||
// 创建 QListView 并设置父控件为 ui->appWidget
|
// 新增:确保 delegate 拥有 model 指针
|
||||||
listView = new QListView(ui->appWidget);
|
m_delegate->setModel(m_model);
|
||||||
listView->setModel(m_model);
|
|
||||||
listView->setItemDelegate(m_delegate);
|
|
||||||
|
|
||||||
// 新增:确保 delegate 拥有 model 指针
|
// 设置 QListView 填充 ui->appWidget
|
||||||
m_delegate->setModel(m_model);
|
QVBoxLayout *layout = new QVBoxLayout(ui->appWidget);
|
||||||
|
layout->addWidget(listView);
|
||||||
// 设置 QListView 填充 ui->appWidget
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
QVBoxLayout *layout = new QVBoxLayout(ui->appWidget);
|
connect(m_delegate, &AppDelegate::updateDisplay, this, [=](const QString &packageName) {
|
||||||
layout->addWidget(listView);
|
for (int i = 0; i < m_model->rowCount(); ++i) {
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
QModelIndex index = m_model->index(i);
|
||||||
connect(m_delegate, &AppDelegate::updateDisplay, this, [=](const QString &packageName) {
|
if (index.data(Qt::UserRole + 1).toString() == packageName) {
|
||||||
for (int i = 0; i < m_model->rowCount(); ++i) {
|
m_model->dataChanged(index, index); // 刷新该行
|
||||||
QModelIndex index = m_model->index(i);
|
break;
|
||||||
if (index.data(Qt::UserRole + 1).toString() == packageName) {
|
}
|
||||||
m_model->dataChanged(index, index); // 刷新该行
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
|
// 新增:点击“更新全部”按钮批量下载
|
||||||
|
connect(ui->updatePushButton, &QPushButton::clicked, this, [=](){
|
||||||
|
qDebug()<<"更新全部按钮被点击";
|
||||||
|
m_delegate->startDownloadForAll();
|
||||||
|
});
|
||||||
|
|
||||||
|
checkUpdates();
|
||||||
|
initStyle();
|
||||||
});
|
});
|
||||||
|
|
||||||
// 新增:点击“更新全部”按钮批量下载
|
// 启动异步任务
|
||||||
connect(ui->updatePushButton, &QPushButton::clicked, this, [=](){
|
watcher->setFuture(QtConcurrent::run([this](){
|
||||||
qDebug()<<"更新全部按钮被点击";
|
runAptssUpgrade();
|
||||||
m_delegate->startDownloadForAll();
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
checkUpdates();
|
|
||||||
initStyle();
|
|
||||||
}
|
}
|
||||||
//初始化控件样式
|
//初始化控件样式
|
||||||
void MainWindow::initStyle()
|
void MainWindow::initStyle()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user