mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2025-03-13 09:12:27 +01:00
qt: Added update checker behind CMake option ENABLE_QT_UPDATE_CHECKER
This commit is contained in:
parent
4cbfba8205
commit
6cff570a12
@ -11,6 +11,10 @@ else
|
||||
export EXTRA_CMAKE_FLAGS=(-DCITRA_USE_PRECOMPILED_HEADERS=OFF)
|
||||
fi
|
||||
|
||||
if [ "$GITHUB_REF_TYPE" == "tag" ]; then
|
||||
export EXTRA_CMAKE_FLAGS=($EXTRA_CMAKE_FLAGS -DENABLE_QT_UPDATE_CHECKER=ON)
|
||||
fi
|
||||
|
||||
mkdir build && cd build
|
||||
cmake .. -G Ninja \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
|
@ -68,6 +68,7 @@ option(USE_SYSTEM_SDL2 "Use the system SDL2 lib (instead of the bundled one)" OF
|
||||
# Set bundled qt as dependent options.
|
||||
option(ENABLE_QT "Enable the Qt frontend" ON)
|
||||
option(ENABLE_QT_TRANSLATION "Enable translations for the Qt frontend" OFF)
|
||||
option(ENABLE_QT_UPDATE_CHECKER "Enable built-in update checker for the Qt frontend" OFF)
|
||||
|
||||
CMAKE_DEPENDENT_OPTION(ENABLE_TESTS "Enable generating tests executable" ON "NOT IOS" OFF)
|
||||
CMAKE_DEPENDENT_OPTION(ENABLE_ROOM "Enable generating dedicated room executable" ON "NOT ANDROID AND NOT IOS" OFF)
|
||||
|
@ -198,6 +198,12 @@ 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(citra_qt PRIVATE httplib json-headers)
|
||||
target_sources(citra_qt PRIVATE update_checker.cpp)
|
||||
target_compile_definitions(citra_qt PUBLIC ENABLE_QT_UPDATE_CHECKER)
|
||||
endif()
|
||||
|
||||
if (ENABLE_QT_TRANSLATION)
|
||||
set(CITRA_QT_LANGUAGES "${PROJECT_SOURCE_DIR}/dist/languages" CACHE PATH "Path to the translation bundle for the Qt frontend")
|
||||
option(GENERATE_QT_TRANSLATION "Generate en.ts as the translation source file" OFF)
|
||||
|
@ -69,6 +69,9 @@
|
||||
#include "citra_qt/play_time_manager.h"
|
||||
#include "citra_qt/qt_image_interface.h"
|
||||
#include "citra_qt/uisettings.h"
|
||||
#ifdef ENABLE_QT_UPDATE_CHECKER
|
||||
#include "citra_qt/update_checker.h"
|
||||
#endif
|
||||
#include "citra_qt/util/clickable_label.h"
|
||||
#include "citra_qt/util/graphics_device_info.h"
|
||||
#include "citra_qt/util/util.h"
|
||||
@ -305,6 +308,21 @@ GMainWindow::GMainWindow(Core::System& system_)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ENABLE_QT_UPDATE_CHECKER
|
||||
const std::optional<std::string> 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
|
||||
|
50
src/citra_qt/update_checker.cpp
Normal file
50
src/citra_qt/update_checker.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright Citra Emulator Project / Azahar Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <httplib.h>
|
||||
#include <json.hpp>
|
||||
#include "common/logging/log.h"
|
||||
#include "update_checker.h"
|
||||
|
||||
std::optional<std::string> UpdateChecker::CheckForUpdate() {
|
||||
constexpr auto UPDATE_CHECK_URL = "http://api.github.com";
|
||||
constexpr auto UPDATE_CHECK_PATH = "/repos/azahar-emu/azahar/releases/latest";
|
||||
|
||||
std::unique_ptr<httplib::Client> client = std::make_unique<httplib::Client>(UPDATE_CHECK_URL);
|
||||
if (client == nullptr) {
|
||||
LOG_ERROR(Frontend, "Invalid URL {}{}", UPDATE_CHECK_URL, UPDATE_CHECK_PATH);
|
||||
return {};
|
||||
}
|
||||
|
||||
httplib::Request request{
|
||||
.method = "GET",
|
||||
.path = UPDATE_CHECK_PATH,
|
||||
};
|
||||
|
||||
client->set_follow_location(true);
|
||||
const auto result = client->send(request);
|
||||
if (!result) {
|
||||
LOG_ERROR(Frontend, "GET to {}{} returned null", UPDATE_CHECK_URL, UPDATE_CHECK_PATH);
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto& response = result.value();
|
||||
if (response.status >= 400) {
|
||||
LOG_ERROR(Frontend, "GET to {}{} returned error status code: {}", UPDATE_CHECK_URL,
|
||||
UPDATE_CHECK_PATH, response.status);
|
||||
return {};
|
||||
}
|
||||
if (!response.headers.contains("content-type")) {
|
||||
LOG_ERROR(Frontend, "GET to {}{} returned no content", UPDATE_CHECK_URL, UPDATE_CHECK_PATH);
|
||||
return {};
|
||||
}
|
||||
|
||||
try {
|
||||
return nlohmann::json::parse(response.body).at("tag_name");
|
||||
} catch (nlohmann::detail::out_of_range&) {
|
||||
return {};
|
||||
}
|
||||
}
|
12
src/citra_qt/update_checker.h
Normal file
12
src/citra_qt/update_checker.h
Normal file
@ -0,0 +1,12 @@
|
||||
// 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> CheckForUpdate();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user