Refactored version check

This commit is contained in:
acidicoala
2026-01-17 12:06:19 +05:00
parent 7b54b4bc7b
commit 3bd112c8f4
5 changed files with 44 additions and 24 deletions

View File

@@ -20,8 +20,8 @@
"logging": { "logging": {
"type": "boolean", "type": "boolean",
"default": false, "default": false,
"x-packaged-default": true,
"description": "Enables logging to SmokeAPI.log.log file.", "description": "Enables logging to SmokeAPI.log.log file.",
"x-packaged-default": true,
"x-valid-values": "`true` or `false`." "x-valid-values": "`true` or `false`."
}, },
"log_steam_http": { "log_steam_http": {

View File

@@ -59,23 +59,27 @@ namespace {
bool is_hook_mode; bool is_hook_mode;
void check_for_updates() { void check_for_updates() {
const auto latest_release_url = std::format( try {
"https://api.github.com/repos/acidicoala/{}/releases/latest", const auto latest_release_url = std::format(
PROJECT_NAME "https://api.github.com/repos/acidicoala/{}/releases/latest",
); PROJECT_NAME
const auto res = kb::http_client::get_json(latest_release_url);
const auto latest_tag = res["tag_name"].get<std::string>();
const auto current_tag = std::format("v{}", PROJECT_VERSION);
if(current_tag == latest_tag) {
LOG_DEBUG("Running the latest version");
} else {
const auto release_page = std::format(
"https://github.com/acidicoala/{}/releases/{}",
PROJECT_NAME, latest_tag
); );
const auto res = kb::http_client::get_json(latest_release_url);
const auto latest_tag = res["tag_name"].get<std::string>();
const auto current_tag = std::format("v{}", PROJECT_VERSION);
LOG_WARN("New version {} available: {}", latest_tag, release_page); if(current_tag == latest_tag) {
LOG_DEBUG("Running the latest version");
} else {
const auto release_page = std::format(
"https://github.com/acidicoala/{}/releases/{}",
PROJECT_NAME, latest_tag
);
LOG_WARN("New version {} available: {}", latest_tag, release_page);
}
} catch(const std::exception& e) {
LOG_ERROR("{} -> Unexpected error: {}", __func__, e.what());
} }
} }
@@ -134,7 +138,9 @@ namespace {
static const auto CreateInterface$ = KB_LIB_GET_FUNC(steamclient_handle, CreateInterface); static const auto CreateInterface$ = KB_LIB_GET_FUNC(steamclient_handle, CreateInterface);
if(auto* steamapi_handle = kb::lib::get_lib_handle(STEAM_API_MODULE)) { if(auto* steamapi_handle = kb::lib::get_lib_handle(STEAM_API_MODULE)) {
if(steamapi_handle != original_steamapi_handle) { if(original_steamapi_handle == nullptr) { // hook mode on Windows
original_steamapi_handle = steamapi_handle;
} else if(steamapi_handle != original_steamapi_handle) {
LOG_WARN( LOG_WARN(
"{} -> steamapi_handle ({}) != original_steamapi_handle ({})", "{} -> steamapi_handle ({}) != original_steamapi_handle ({})",
__func__, steamapi_handle, original_steamapi_handle __func__, steamapi_handle, original_steamapi_handle
@@ -287,12 +293,6 @@ namespace smoke_api {
kb::win::check_self_duplicates(); kb::win::check_self_duplicates();
#endif #endif
#ifdef KB_DEBUG
// TODO: Add config option to toggle this and show native OS notification
// The real reason behind this is for automatic testing of HTTPs dependencies
std::thread(check_for_updates).detach();
#endif
// We need to hook functions in either mode // We need to hook functions in either mode
kb::hook::init(true); kb::hook::init(true);
@@ -313,6 +313,14 @@ namespace smoke_api {
} }
} }
void post_init() {
#ifdef KB_DEBUG
// TODO: Add config option to toggle this and show native OS notification
// The real reason behind this is for automatic testing of HTTPs dependencies
std::thread(check_for_updates).detach();
#endif
}
void shutdown() { void shutdown() {
try { try {
static bool shutdown_complete = false; static bool shutdown_complete = false;

View File

@@ -4,6 +4,14 @@
namespace smoke_api { namespace smoke_api {
void init(void* self_module_handle); void init(void* self_module_handle);
/**
* Post-initialization procedures that must be done after the module is finished loading.
* Reason being that on Windows we should not start new threads while being in DllMain callback,
* otherwise we would run into deadlocks/race-conditions/undefined behavior.
*/
void post_init();
void shutdown(); void shutdown();
AppId_t get_app_id(); AppId_t get_app_id();

View File

@@ -4,6 +4,7 @@
#include <koalabox/logger.hpp> #include <koalabox/logger.hpp>
#include "smoke_api/steamclient/steamclient.hpp" #include "smoke_api/steamclient/steamclient.hpp"
#include "smoke_api/smoke_api.hpp"
#include "smoke_api/types.hpp" #include "smoke_api/types.hpp"
#include "steam_api/steam_client.hpp" #include "steam_api/steam_client.hpp"
@@ -16,6 +17,9 @@ C_DECL(void*) CreateInterface(const char* interface_version, create_interface_re
static std::mutex section; static std::mutex section;
const std::lock_guard lock(section); const std::lock_guard lock(section);
static std::once_flag once_flag;
std::call_once(once_flag, smoke_api::post_init);
return steam_client::GetGenericInterface( return steam_client::GetGenericInterface(
__func__, __func__,
interface_version, interface_version,