|
30 | 30 | #include "SentryReporter.h" |
31 | 31 | #ifdef ENABLE_AUTO_UPDATER |
32 | 32 | #include "updater/UpdaterController.h" |
| 33 | +#include "updater/UpdaterTelemetry.h" |
33 | 34 | #endif |
34 | 35 | #include <QDialog> |
35 | 36 | #include <QProgressDialog> |
@@ -678,13 +679,13 @@ void MainWindow::initToolBar() |
678 | 679 |
|
679 | 680 | #ifdef ENABLE_AUTO_UPDATER |
680 | 681 | connect(UpdaterController::instance(), &UpdaterController::showDialogRequested, |
681 | | - this, &MainWindow::showUpdaterDialog); |
| 682 | + this, [this](bool runCheck) { showUpdaterDialog(runCheck); }); |
| 683 | + connect(UpdaterController::instance(), &UpdaterController::backgroundUpdateAvailable, |
| 684 | + this, [this](const QString& version) { showUpdateToast(version); }); |
682 | 685 | #ifndef QTMESH_UNIT_TESTS |
683 | | - if (UpdaterController::instance()->checkOnStartup()) { |
684 | | - QTimer::singleShot(3000, this, []() { |
685 | | - UpdaterController::instance()->checkForUpdates(); |
686 | | - }); |
687 | | - } |
| 686 | + QTimer::singleShot(5000, this, []() { |
| 687 | + UpdaterController::instance()->checkForUpdatesInBackground(); |
| 688 | + }); |
688 | 689 | #endif |
689 | 690 | #endif |
690 | 691 |
|
@@ -4521,6 +4522,56 @@ void MainWindow::showUpdaterDialog(bool runCheck) |
4521 | 4522 | engine->load(QUrl(QStringLiteral("qrc:/UpdaterDialog/UpdaterDialog.qml"))); |
4522 | 4523 | } |
4523 | 4524 |
|
| 4525 | +void MainWindow::showUpdateToast(const QString& version) |
| 4526 | +{ |
| 4527 | + UpdaterTelemetry::breadcrumb(QStringLiteral("updater.background.toast"), |
| 4528 | + QStringLiteral("version=%1").arg(version)); |
| 4529 | + |
| 4530 | + if (m_updateToastEngine) { |
| 4531 | + if (auto* toast = m_updateToastWindow) { |
| 4532 | + QMetaObject::invokeMethod(toast, "showForVersion", Q_ARG(QVariant, version)); |
| 4533 | + } |
| 4534 | + return; |
| 4535 | + } |
| 4536 | + |
| 4537 | + m_updateToastEngine = new QQmlApplicationEngine(this); |
| 4538 | + m_updateToastEngine->addImportPath(QStringLiteral("qrc:/")); |
| 4539 | + qmlRegisterSingletonType<PropertiesPanelController>( |
| 4540 | + "PropertiesPanel", 1, 0, "PropertiesPanelController", |
| 4541 | + [](QQmlEngine* eng, QJSEngine*) -> QObject* { |
| 4542 | + return PropertiesPanelController::qmlInstance(eng, nullptr); |
| 4543 | + }); |
| 4544 | + qmlRegisterSingletonType<UpdaterController>( |
| 4545 | + "Updater", 1, 0, "UpdaterController", |
| 4546 | + [](QQmlEngine* eng, QJSEngine*) -> QObject* { |
| 4547 | + return UpdaterController::qmlInstance(eng, nullptr); |
| 4548 | + }); |
| 4549 | + |
| 4550 | + connect(m_updateToastEngine, &QQmlApplicationEngine::objectCreated, this, |
| 4551 | + [this, version](QObject* obj, const QUrl&) { |
| 4552 | + if (!obj) { |
| 4553 | + m_updateToastEngine->deleteLater(); |
| 4554 | + m_updateToastEngine = nullptr; |
| 4555 | + return; |
| 4556 | + } |
| 4557 | + |
| 4558 | + m_updateToastWindow = obj; |
| 4559 | + if (auto* window = qobject_cast<QQuickWindow*>(obj)) { |
| 4560 | + QQuickWindow::setGraphicsApi(QSGRendererInterface::Software); |
| 4561 | + connect(window, &QQuickWindow::destroyed, this, [this]() { |
| 4562 | + m_updateToastWindow = nullptr; |
| 4563 | + if (m_updateToastEngine) { |
| 4564 | + m_updateToastEngine->deleteLater(); |
| 4565 | + m_updateToastEngine = nullptr; |
| 4566 | + } |
| 4567 | + }); |
| 4568 | + } |
| 4569 | + QMetaObject::invokeMethod(obj, "showForVersion", Q_ARG(QVariant, version)); |
| 4570 | + }); |
| 4571 | + |
| 4572 | + m_updateToastEngine->load(QUrl(QStringLiteral("qrc:/UpdateToast/UpdateToast.qml"))); |
| 4573 | +} |
| 4574 | + |
4524 | 4575 | void MainWindow::on_actionVerify_Update_triggered() |
4525 | 4576 | { |
4526 | 4577 | showUpdaterDialog(true); |
|
0 commit comments