From c468af1dd3cd526239885e2270c805bafc04a078 Mon Sep 17 00:00:00 2001 From: OpenSauce04 Date: Tue, 11 Mar 2025 22:44:41 +0000 Subject: [PATCH] qt: Make update check concurrent and added connection timeout Co-authored-by: PabloMK7 --- src/citra_qt/citra_qt.cpp | 55 ++++++++++++++++++++++----------- src/citra_qt/citra_qt.h | 20 +++++++++--- src/citra_qt/update_checker.cpp | 5 +++ 3 files changed, 58 insertions(+), 22 deletions(-) diff --git a/src/citra_qt/citra_qt.cpp b/src/citra_qt/citra_qt.cpp index 0b9aedcba..391358fa0 100644 --- a/src/citra_qt/citra_qt.cpp +++ b/src/citra_qt/citra_qt.cpp @@ -308,24 +308,6 @@ GMainWindow::GMainWindow(Core::System& system_) } } -#ifdef ENABLE_QT_UPDATE_CHECKER - if (UISettings::values.check_for_update_on_start) { - const std::optional latest_release = UpdateChecker::CheckForUpdate(); - if (latest_release && latest_release.value() != Common::g_build_fullname) { - if (QMessageBox::information( - this, tr("Update Available"), - tr("Update %1 for Azahar is available.\nWould you like to download it?") - .arg(QString::fromStdString(latest_release.value())), - QMessageBox::Yes | QMessageBox::Ignore) == QMessageBox::Yes) { - QDesktopServices::openUrl(QUrl( - QString::fromStdString("https://github.com/azahar-emu/azahar/releases/tag/" + - latest_release.value()))); - exit(0); - } - } - } -#endif - #ifdef __unix__ SetGamemodeEnabled(Settings::values.enable_gamemode.GetValue()); #endif @@ -406,6 +388,21 @@ GMainWindow::GMainWindow(Core::System& system_) show(); +#ifdef ENABLE_QT_UPDATE_CHECKER + if (UISettings::values.check_for_update_on_start) { + update_future = QtConcurrent::run([]() -> QString { + const std::optional latest_release = UpdateChecker::CheckForUpdate(); + if (latest_release && latest_release.value() != Common::g_build_fullname) { + return QString::fromStdString(latest_release.value()); + } + return QString{}; + }); + QObject::connect(&update_watcher, &QFutureWatcher::finished, this, + &GMainWindow::OnEmulatorUpdateAvailable); + update_watcher.setFuture(update_future); + } +#endif + game_list->LoadCompatibilityList(); game_list->PopulateAsync(UISettings::values.game_dirs); @@ -3598,6 +3595,28 @@ void GMainWindow::OnMoviePlaybackCompleted() { QMessageBox::information(this, tr("Playback Completed"), tr("Movie playback completed.")); } +#ifdef ENABLE_QT_UPDATE_CHECKER +void GMainWindow::OnEmulatorUpdateAvailable() { + QString version_string = update_future.result(); + if (version_string.isEmpty()) + return; + + QMessageBox update_prompt(this); + update_prompt.setWindowTitle(tr("Update Available")); + update_prompt.setIcon(QMessageBox::Information); + update_prompt.addButton(QMessageBox::Yes); + update_prompt.addButton(QMessageBox::Ignore); + update_prompt.setText(tr("Update %1 for Azahar is available.\nWould you like to download it?") + .arg(version_string)); + update_prompt.exec(); + if (update_prompt.button(QMessageBox::Yes) == update_prompt.clickedButton()) { + QDesktopServices::openUrl( + QUrl(QString::fromStdString("https://github.com/azahar-emu/azahar/releases/tag/") + + version_string)); + } +} +#endif + void GMainWindow::UpdateWindowTitle() { const QString full_name = QString::fromUtf8(Common::g_build_fullname); diff --git a/src/citra_qt/citra_qt.h b/src/citra_qt/citra_qt.h index 078d254b5..e352b49a3 100644 --- a/src/citra_qt/citra_qt.h +++ b/src/citra_qt/citra_qt.h @@ -7,6 +7,13 @@ #include #include #include +#ifdef __unix__ +#include +#endif +#ifdef ENABLE_QT_UPDATE_CHECKER +#include +#include +#endif #include #include #include @@ -18,10 +25,6 @@ #include "core/core.h" #include "core/savestate.h" -#ifdef __unix__ -#include -#endif - // Needs to be included at the end due to https://bugreports.qt.io/browse/QTBUG-73263 #include @@ -290,6 +293,9 @@ private slots: void OnDecreaseVolume(); void OnIncreaseVolume(); void OnMute(); +#ifdef ENABLE_QT_UPDATE_CHECKER + void OnEmulatorUpdateAvailable(); +#endif private: Q_INVOKABLE void OnMoviePlaybackCompleted(); @@ -415,6 +421,12 @@ private: std::shared_ptr qt_cameras; + // Prompt shown when update check succeeds +#ifdef ENABLE_QT_UPDATE_CHECKER + QFuture update_future; + QFutureWatcher update_watcher; +#endif + #ifdef __unix__ QDBusObjectPath wake_lock{}; #endif diff --git a/src/citra_qt/update_checker.cpp b/src/citra_qt/update_checker.cpp index 050c19c8e..a8a3955d7 100644 --- a/src/citra_qt/update_checker.cpp +++ b/src/citra_qt/update_checker.cpp @@ -12,8 +12,13 @@ std::optional UpdateChecker::CheckForUpdate() { constexpr auto UPDATE_CHECK_URL = "http://api.github.com"; constexpr auto UPDATE_CHECK_PATH = "/repos/azahar-emu/azahar/releases/latest"; + constexpr std::size_t UPDATE_CHECK_TIMEOUT_SECONDS = 15; std::unique_ptr client = std::make_unique(UPDATE_CHECK_URL); + client->set_connection_timeout(UPDATE_CHECK_TIMEOUT_SECONDS); + client->set_read_timeout(UPDATE_CHECK_TIMEOUT_SECONDS); + client->set_write_timeout(UPDATE_CHECK_TIMEOUT_SECONDS); + if (client == nullptr) { LOG_ERROR(Frontend, "Invalid URL {}{}", UPDATE_CHECK_URL, UPDATE_CHECK_PATH); return {};