From 77dde49653a2b200109ec207e32fd21adca9c318 Mon Sep 17 00:00:00 2001 From: momen Date: Sat, 2 Aug 2025 17:09:57 +0800 Subject: [PATCH] =?UTF-8?q?chore:=E6=9B=B4=E6=96=B0=E6=8C=89=E9=92=AE14?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mainwindow-dtk.cpp | 96 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 86 insertions(+), 10 deletions(-) diff --git a/src/mainwindow-dtk.cpp b/src/mainwindow-dtk.cpp index 45bc6e2..fb85dce 100755 --- a/src/mainwindow-dtk.cpp +++ b/src/mainwindow-dtk.cpp @@ -531,8 +531,8 @@ void MainWindow::on_pushButton_14_clicked() if (false) { qDebug() << "UOS Developer Mode has not been enabled!"; - QtConcurrent::run([=] - { + (void)QtConcurrent::run([=] + { auto upgradeP = new QProcess(); upgradeP->startDetached("zenity", QStringList() << "--info" << "--text" @@ -544,20 +544,96 @@ void MainWindow::on_pushButton_14_clicked() ); upgradeP->waitForStarted(); upgradeP->waitForFinished(30); - upgradeP->deleteLater(); }); + upgradeP->deleteLater(); + }); + }else +{ + QFile upgradeStatus("/tmp/spark-store/upgradeStatus.txt"); + if (!upgradeStatus.exists()) + { + QString appPath; + // 判断路径:开发环境 vs 安装后 +#ifdef QT_DEBUG + appPath = QCoreApplication::applicationDirPath() + + "/spark-update-tool/spark-update-tool"; +#else + appPath = QStandardPaths::findExecutable("spark-update-tool"); +#endif + + if (appPath.isEmpty()) { + qWarning() << "spark-update-tool not found!"; + return; + } + + QProcess *process = new QProcess(this); + +#ifdef QT_DEBUG + // 开发模式:直接运行本地构建的更新器 + process->start(appPath, {"--silent"}); +#else + // 安装模式:使用 pkexec 提权运行系统路径下的 spark-update-tool + QString program = "pkexec"; + QStringList arguments; + arguments << appPath << "--silent"; + process->start(program, arguments); +#endif + + QObject::connect(process, &QProcess::finished, + [process](int exitCode, QProcess::ExitStatus) { + if (exitCode == 0) { + qDebug() << "Update check successful"; + } else { + qWarning() << "Update check failed with exit code:" << exitCode; + } + process->deleteLater(); + }); } +} +// ...existing code... else { QFile upgradeStatus("/tmp/spark-store/upgradeStatus.txt"); if (!upgradeStatus.exists()) { - QtConcurrent::run([=] - { - auto upgradeP = new QProcess(); - upgradeP->startDetached("/opt/durapps/spark-store/bin/update-upgrade/ss-do-upgrade.sh", QStringList()); - upgradeP->waitForStarted(); - upgradeP->waitForFinished(-1); - upgradeP->deleteLater(); }); + QString appPath; + + // 判断路径:开发环境 vs 安装后 + #ifdef QT_DEBUG + appPath = QCoreApplication::applicationDirPath() + + "/spark-update-tool/spark-update-tool"; + #else + appPath = QStandardPaths::findExecutable("spark-update-tool"); + #endif + + if (appPath.isEmpty()) { + qWarning() << "spark-update-tool not found!"; + return; + } + + QProcess *process = new QProcess(this); + + #ifdef QT_DEBUG + // 开发模式:直接运行本地构建的更新器 + process->start(appPath, {"--silent"}); + #else + // 安装模式:使用 pkexec 提权运行系统路径下的 spark-update-tool + QString program = "pkexec"; + QStringList arguments; + arguments << appPath << "--silent"; + process->start(program, arguments); + #endif + + QObject::connect(process, QOverload::of(&QProcess::finished), + [process](int exitCode) { + if (exitCode == 0) { + qDebug() << "Update check successful"; + } else { + qWarning() << "Update check failed with exit code:" << exitCode; + } + process->deleteLater(); + }); + } + } } } }