chore:使用pkexec调用更新器

This commit is contained in:
momen 2025-07-15 00:45:42 +08:00
parent 1f6e68ca3f
commit 30acad7516
1 changed files with 25 additions and 16 deletions

View File

@ -345,7 +345,7 @@ void MainWindow::refreshTheme(bool isDarkMode)
ui->applistpage->setTheme(isDarkMode);
ui->applistpage_1->setTheme(isDarkMode);
ui->appintopage->setTheme(isDarkMode);
ui->settingspage->setTheme(isDarkMode);
ui->settingspage->setTheme(isDarkMode);
}
void MainWindow::initConnections()
@ -551,16 +551,15 @@ void MainWindow::on_pushButton_14_clicked()
QFile upgradeStatus("/tmp/spark-store/upgradeStatus.txt");
if (!upgradeStatus.exists())
{
QString appPath;
QString appPath;
// 开发环境路径(构建目录)
#ifdef QT_DEBUG
appPath = QCoreApplication::applicationDirPath() +
"/spark-update-tool/spark-update-tool";
#else
// 安装后路径系统PATH
appPath = QStandardPaths::findExecutable("spark-update-tool");
#endif
// 判断路径:开发环境 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!";
@ -568,17 +567,27 @@ void MainWindow::on_pushButton_14_clicked()
}
QProcess *process = new QProcess(this);
process->start(appPath, {"--silent"});
connect(process, QOverload<int>::of(&QProcess::finished),
[=](int exitCode) {
#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<int>::of(&QProcess::finished),
[process](int exitCode) {
if (exitCode == 0) {
qDebug() << "Update check successful";
} else {
qDebug() << "Update check failed";
qWarning() << "Update check failed with exit code:" << exitCode;
}
process->deleteLater();
});
}
}
}
}
}