mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-06-22 06:03:49 +08:00
Sync: Spark Update Tool
This commit is contained in:
@@ -9,7 +9,8 @@ set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt5 REQUIRED COMPONENTS Widgets Network Concurrent)
|
||||
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
|
||||
src/main.cpp
|
||||
@@ -29,22 +30,39 @@ set(PROJECT_SOURCES
|
||||
src/ignoreconfig.cpp
|
||||
)
|
||||
|
||||
if(ANDROID)
|
||||
add_library(spark-update-tool SHARED
|
||||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
|
||||
qt_add_executable(spark-update-tool
|
||||
MANUAL_FINALIZATION
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
# Define target properties for Android with Qt 6 as:
|
||||
# set_property(TARGET spark-update-tool APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
|
||||
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
|
||||
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
|
||||
else()
|
||||
if(ANDROID)
|
||||
add_library(spark-update-tool SHARED
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
# Define properties for Android with Qt 5 after find_package() calls as:
|
||||
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
|
||||
else()
|
||||
add_executable(spark-update-tool
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
else()
|
||||
add_executable(spark-update-tool
|
||||
${PROJECT_SOURCES}
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_link_libraries(spark-update-tool PRIVATE Qt5::Widgets Qt5::Network Qt5::Concurrent)
|
||||
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
|
||||
# explicit, fixed bundle identifier manually though.
|
||||
if(${QT_VERSION} VERSION_LESS 6.1.0)
|
||||
set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.spark-update-tool)
|
||||
endif()
|
||||
set_target_properties(spark-update-tool PROPERTIES
|
||||
MACOSX_BUNDLE_GUI_IDENTIFIER com.example.spark-update-tool
|
||||
${BUNDLE_ID_OPTION}
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||
MACOSX_BUNDLE TRUE
|
||||
@@ -56,4 +74,8 @@ install(TARGETS spark-update-tool
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
)
|
||||
|
||||
if(QT_VERSION_MAJOR EQUAL 6)
|
||||
qt_finalize_executable(spark-update-tool)
|
||||
endif()
|
||||
@@ -1,3 +1,7 @@
|
||||
spark-update-tool (1.0.4) unstable; urgency=low
|
||||
|
||||
* 修复点击更新全部按钮后,会更新被忽略应用的问题。
|
||||
|
||||
spark-update-tool (1.0.3) unstable; urgency=low
|
||||
|
||||
* 修复默认图标加载失败的问题
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -21,6 +21,7 @@ class AppDelegate : public QStyledItemDelegate {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AppDelegate(QObject *parent = nullptr);
|
||||
~AppDelegate();
|
||||
|
||||
void setModel(QAbstractItemModel *model);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user