mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-09-11 13:52: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_REQUIRED ON)
|
||||
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Network)
|
||||
find_package(Qt${QT_VERSION_MAJOR} 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 Concurrent)
|
||||
|
||||
set(PROJECT_SOURCES
|
||||
main.cpp
|
||||
@ -47,7 +47,7 @@ else()
|
||||
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.
|
||||
# If you are developing for iOS or macOS you should consider setting an
|
||||
|
@ -2,6 +2,9 @@
|
||||
#include "./ui_mainwindow.h"
|
||||
#include <QProcess>
|
||||
#include <QMessageBox>
|
||||
#include <QProgressDialog>
|
||||
#include <QtConcurrent> // 新增
|
||||
#include <QFutureWatcher> // 新增
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
@ -9,40 +12,57 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
, m_model(new AppListModel(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
|
||||
listView = new QListView(ui->appWidget);
|
||||
listView->setModel(m_model);
|
||||
listView->setItemDelegate(m_delegate);
|
||||
// 新增:确保 delegate 拥有 model 指针
|
||||
m_delegate->setModel(m_model);
|
||||
|
||||
// 新增:确保 delegate 拥有 model 指针
|
||||
m_delegate->setModel(m_model);
|
||||
|
||||
// 设置 QListView 填充 ui->appWidget
|
||||
QVBoxLayout *layout = new QVBoxLayout(ui->appWidget);
|
||||
layout->addWidget(listView);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
connect(m_delegate, &AppDelegate::updateDisplay, this, [=](const QString &packageName) {
|
||||
for (int i = 0; i < m_model->rowCount(); ++i) {
|
||||
QModelIndex index = m_model->index(i);
|
||||
if (index.data(Qt::UserRole + 1).toString() == packageName) {
|
||||
m_model->dataChanged(index, index); // 刷新该行
|
||||
break;
|
||||
// 设置 QListView 填充 ui->appWidget
|
||||
QVBoxLayout *layout = new QVBoxLayout(ui->appWidget);
|
||||
layout->addWidget(listView);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
connect(m_delegate, &AppDelegate::updateDisplay, this, [=](const QString &packageName) {
|
||||
for (int i = 0; i < m_model->rowCount(); ++i) {
|
||||
QModelIndex index = m_model->index(i);
|
||||
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, [=](){
|
||||
qDebug()<<"更新全部按钮被点击";
|
||||
m_delegate->startDownloadForAll();
|
||||
});
|
||||
|
||||
checkUpdates();
|
||||
initStyle();
|
||||
// 启动异步任务
|
||||
watcher->setFuture(QtConcurrent::run([this](){
|
||||
runAptssUpgrade();
|
||||
}));
|
||||
}
|
||||
//初始化控件样式
|
||||
void MainWindow::initStyle()
|
||||
|
Loading…
x
Reference in New Issue
Block a user