|
1 | 1 | #include "UpdaterController.h" |
2 | 2 | #include "ArtifactResolver.h" |
| 3 | +#include "UpdaterInstaller.h" |
3 | 4 | #include "UpdaterWorker.h" |
4 | 5 | #include "AppSettingsKeys.h" |
5 | 6 | #include "SentryReporter.h" |
@@ -34,6 +35,7 @@ QString stateToString(UpdaterController::State state) |
34 | 35 | case UpdaterController::State::Downloading: return QStringLiteral("downloading"); |
35 | 36 | case UpdaterController::State::Verifying: return QStringLiteral("verifying"); |
36 | 37 | case UpdaterController::State::ReadyToInstall: return QStringLiteral("ready_to_install"); |
| 38 | + case UpdaterController::State::Installing: return QStringLiteral("installing"); |
37 | 39 | } |
38 | 40 | return QStringLiteral("idle"); |
39 | 41 | } |
@@ -369,6 +371,54 @@ void UpdaterController::downloadAndInstall() |
369 | 371 | beginDownloadIfNeeded(true); |
370 | 372 | } |
371 | 373 |
|
| 374 | +void UpdaterController::installUpdate() |
| 375 | +{ |
| 376 | + if (m_state != State::ReadyToInstall) { |
| 377 | + return; |
| 378 | + } |
| 379 | + |
| 380 | + SentryReporter::addBreadcrumb(QStringLiteral("updater.install.start"), |
| 381 | + QStringLiteral("version=%1").arg(m_latestVersion)); |
| 382 | + setError(QString()); |
| 383 | + setState(State::Installing); |
| 384 | + logDialogStateBreadcrumb(); |
| 385 | + |
| 386 | + UpdaterInstaller::InstallContext context; |
| 387 | + context.stagedArtifactPath = m_stagedArtifactPath; |
| 388 | + context.releaseTag = m_latestVersion; |
| 389 | + context.executablePath = QCoreApplication::applicationFilePath(); |
| 390 | + context.installRoot = UpdaterInstaller::resolveInstallRoot(context.executablePath); |
| 391 | + context.parentPid = QCoreApplication::applicationPid(); |
| 392 | + |
| 393 | + const UpdaterInstaller::InstallPlan plan = UpdaterInstaller::prepareInstall(context); |
| 394 | + if (!plan.ok) { |
| 395 | + SentryReporter::addBreadcrumb(QStringLiteral("updater.install.error"), |
| 396 | + plan.errorMessage, |
| 397 | + QStringLiteral("error")); |
| 398 | + setError(plan.errorMessage.isEmpty() |
| 399 | + ? tr("Could not prepare the update for installation.") |
| 400 | + : plan.errorMessage); |
| 401 | + setState(State::Error); |
| 402 | + logDialogStateBreadcrumb(); |
| 403 | + return; |
| 404 | + } |
| 405 | + |
| 406 | + if (!UpdaterInstaller::launchRelauncher(plan)) { |
| 407 | + SentryReporter::addBreadcrumb(QStringLiteral("updater.install.error"), |
| 408 | + QStringLiteral("relauncher missing or failed to start"), |
| 409 | + QStringLiteral("error")); |
| 410 | + setError(tr("Could not launch the update installer. " |
| 411 | + "Make sure qtmesh-relauncher is next to the application binary.")); |
| 412 | + setState(State::Error); |
| 413 | + logDialogStateBreadcrumb(); |
| 414 | + return; |
| 415 | + } |
| 416 | + |
| 417 | + SentryReporter::addBreadcrumb(QStringLiteral("updater.install.relaunch"), |
| 418 | + plan.manifestPath); |
| 419 | + QApplication::quit(); |
| 420 | +} |
| 421 | + |
372 | 422 | void UpdaterController::beginDownloadIfNeeded(bool userInitiated) |
373 | 423 | { |
374 | 424 | if (m_state != State::UpdateAvailable) { |
|
0 commit comments