[frontend, android] Move update_checker to frontend_common and add Android support (#2687)

I still have to add a setting to disable the auto update checking on a later PR, firstly lets make sure i didn't accidentally break anything  with CMAKE. or QT.

Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/2687
Reviewed-by: Lizzie <lizzie@eden-emu.dev>
Reviewed-by: crueter <crueter@eden-emu.dev>
Co-authored-by: Inix <Nixy01@proton.me>
Co-committed-by: Inix <Nixy01@proton.me>
This commit is contained in:
Inix 2025-10-21 23:36:35 +02:00 committed by crueter
parent 1971fbe5af
commit cde02bfe46
No known key found for this signature in database
GPG key ID: 425ACD2D4830EBC6
50 changed files with 221 additions and 110 deletions

View file

@ -263,10 +263,8 @@ file(GLOB COMPAT_LIST
file(GLOB_RECURSE ICONS ${PROJECT_SOURCE_DIR}/dist/icons/*)
file(GLOB_RECURSE THEMES ${PROJECT_SOURCE_DIR}/dist/qt_themes/*)
if (ENABLE_QT_UPDATE_CHECKER)
target_link_libraries(yuzu PRIVATE httplib::httplib)
target_sources(yuzu PRIVATE update_checker.cpp)
target_compile_definitions(yuzu PUBLIC ENABLE_QT_UPDATE_CHECKER)
if (ENABLE_UPDATE_CHECKER)
target_compile_definitions(yuzu PUBLIC ENABLE_UPDATE_CHECKER)
endif()
if (ENABLE_QT_TRANSLATION)

View file

@ -54,8 +54,8 @@
#include "yuzu/multiplayer/state.h"
#include "yuzu/util/controller_navigation.h"
#ifdef ENABLE_QT_UPDATE_CHECKER
#include "yuzu/update_checker.h"
#ifdef ENABLE_UPDATE_CHECKER
#include "frontend_common/update_checker.h"
#endif
#ifdef YUZU_ROOM
@ -517,7 +517,7 @@ GMainWindow::GMainWindow(bool has_broken_vulkan)
show();
#ifdef ENABLE_QT_UPDATE_CHECKER
#ifdef ENABLE_UPDATE_CHECKER
if (UISettings::values.check_for_updates) {
update_future = QtConcurrent::run([]() -> QString {
const bool is_prerelease = ((strstr(Common::g_build_version, "pre-alpha") != NULL) ||
@ -4220,7 +4220,7 @@ void GMainWindow::MigrateConfigFiles() {
}
}
#ifdef ENABLE_QT_UPDATE_CHECKER
#ifdef ENABLE_UPDATE_CHECKER
void GMainWindow::OnEmulatorUpdateAvailable() {
QString version_string = update_future.result();
if (version_string.isEmpty())

View file

@ -32,7 +32,7 @@
#include <QtDBus/QtDBus>
#endif
#ifdef ENABLE_QT_UPDATE_CHECKER
#ifdef ENABLE_UPDATE_CHECKER
#include <QFuture>
#include <QFutureWatcher>
#endif
@ -420,7 +420,7 @@ private slots:
void OnEmulationStopped();
void OnEmulationStopTimeExpired();
#ifdef ENABLE_QT_UPDATE_CHECKER
#ifdef ENABLE_UPDATE_CHECKER
void OnEmulatorUpdateAvailable();
#endif
@ -476,7 +476,7 @@ private:
std::unique_ptr<PlayTime::PlayTimeManager> play_time_manager;
std::shared_ptr<InputCommon::InputSubsystem> input_subsystem;
#ifdef ENABLE_QT_UPDATE_CHECKER
#ifdef ENABLE_UPDATE_CHECKER
QFuture<QString> update_future;
QFutureWatcher<QString> update_watcher;
#endif

View file

@ -1,137 +0,0 @@
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright Citra Emulator Project / Azahar Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "update_checker.h"
#include "common/logging/log.h"
#include "common/scm_rev.h"
#include <fmt/format.h>
#ifndef CPPHTTPLIB_OPENSSL_SUPPORT
#define CPPHTTPLIB_OPENSSL_SUPPORT
#endif
#include <httplib.h>
#ifdef YUZU_BUNDLED_OPENSSL
#include <openssl/cert.h>
#endif
#include <nlohmann/json.hpp>
#include <optional>
#include <qdebug.h>
#include <string>
std::optional<std::string> UpdateChecker::GetResponse(std::string url, std::string path)
{
try {
constexpr std::size_t timeout_seconds = 15;
std::unique_ptr<httplib::Client> client = std::make_unique<httplib::Client>(url);
client->set_connection_timeout(timeout_seconds);
client->set_read_timeout(timeout_seconds);
client->set_write_timeout(timeout_seconds);
#ifdef YUZU_BUNDLED_OPENSSL
client->load_ca_cert_store(kCert, sizeof(kCert));
#endif
if (client == nullptr) {
LOG_ERROR(Frontend, "Invalid URL {}{}", url, path);
return {};
}
httplib::Request request{
.method = "GET",
.path = path,
};
client->set_follow_location(true);
httplib::Result result;
result = client->send(request);
if (!result) {
LOG_ERROR(Frontend, "GET to {}{} returned null", url, path);
return {};
}
const auto &response = result.value();
if (response.status >= 400) {
LOG_ERROR(Frontend,
"GET to {}{} returned error status code: {}",
url,
path,
response.status);
return {};
}
if (!response.headers.contains("content-type")) {
LOG_ERROR(Frontend, "GET to {}{} returned no content", url, path);
return {};
}
return response.body;
} catch (std::exception &e) {
qDebug() << e.what();
return std::nullopt;
}
}
std::optional<std::string> UpdateChecker::GetLatestRelease(bool include_prereleases)
{
const auto update_check_url = std::string{Common::g_build_auto_update_api};
std::string update_check_path = fmt::format("/repos/{}",
std::string{Common::g_build_auto_update_repo});
try {
if (include_prereleases) { // This can return either a prerelease or a stable release,
// whichever is more recent.
const auto update_check_tags_path = update_check_path + "/tags";
const auto update_check_releases_path = update_check_path + "/releases";
const auto tags_response = GetResponse(update_check_url, update_check_tags_path);
const auto releases_response = GetResponse(update_check_url, update_check_releases_path);
if (!tags_response || !releases_response)
return {};
const std::string latest_tag
= nlohmann::json::parse(tags_response.value()).at(0).at("name");
const bool latest_tag_has_release = releases_response.value().find(
fmt::format("\"{}\"", latest_tag))
!= std::string::npos;
// If there is a newer tag, but that tag has no associated release, don't prompt the
// user to update.
if (!latest_tag_has_release)
return {};
return latest_tag;
} else { // This is a stable release, only check for other stable releases.
update_check_path += "/releases/latest";
const auto response = GetResponse(update_check_url, update_check_path);
if (!response)
return {};
const std::string latest_tag = nlohmann::json::parse(response.value()).at("tag_name");
return latest_tag;
}
} catch (nlohmann::detail::out_of_range &) {
LOG_ERROR(Frontend,
"Parsing JSON response from {}{} failed during update check: "
"nlohmann::detail::out_of_range",
update_check_url,
update_check_path);
return {};
} catch (nlohmann::detail::type_error &) {
LOG_ERROR(Frontend,
"Parsing JSON response from {}{} failed during update check: "
"nlohmann::detail::type_error",
update_check_url,
update_check_path);
return {};
}
}

View file

@ -1,13 +0,0 @@
// Copyright Citra Emulator Project / Azahar Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <optional>
#include <string>
namespace UpdateChecker {
std::optional<std::string> GetResponse(std::string url, std::string path);
std::optional<std::string> GetLatestRelease(bool);
} // namespace UpdateChecker