From 3bd112c8f43b49aff3efaa997cbbe08df87a0300 Mon Sep 17 00:00:00 2001 From: acidicoala <67734819+acidicoala@users.noreply.github.com> Date: Sat, 17 Jan 2026 12:06:19 +0500 Subject: [PATCH] Refactored version check --- KoalaBox | 2 +- res/SmokeAPI.schema.json | 2 +- src/smoke_api/smoke_api.cpp | 52 +++++++++++++++++++-------------- src/smoke_api/smoke_api.hpp | 8 +++++ src/steamclient/steamclient.cpp | 4 +++ 5 files changed, 44 insertions(+), 24 deletions(-) diff --git a/KoalaBox b/KoalaBox index 26c9a26..997b5db 160000 --- a/KoalaBox +++ b/KoalaBox @@ -1 +1 @@ -Subproject commit 26c9a26337257816001e2d1290eb9db9e0d00878 +Subproject commit 997b5db2ee75beec83c674e247e64afa2832aa14 diff --git a/res/SmokeAPI.schema.json b/res/SmokeAPI.schema.json index b9f04ce..49542d4 100644 --- a/res/SmokeAPI.schema.json +++ b/res/SmokeAPI.schema.json @@ -20,8 +20,8 @@ "logging": { "type": "boolean", "default": false, - "x-packaged-default": true, "description": "Enables logging to SmokeAPI.log.log file.", + "x-packaged-default": true, "x-valid-values": "`true` or `false`." }, "log_steam_http": { diff --git a/src/smoke_api/smoke_api.cpp b/src/smoke_api/smoke_api.cpp index 1330df3..29e3482 100644 --- a/src/smoke_api/smoke_api.cpp +++ b/src/smoke_api/smoke_api.cpp @@ -59,23 +59,27 @@ namespace { bool is_hook_mode; void check_for_updates() { - const auto latest_release_url = std::format( - "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(); - 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 + try { + const auto latest_release_url = std::format( + "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(); + 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); 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( "{} -> steamapi_handle ({}) != original_steamapi_handle ({})", __func__, steamapi_handle, original_steamapi_handle @@ -287,12 +293,6 @@ namespace smoke_api { kb::win::check_self_duplicates(); #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 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() { try { static bool shutdown_complete = false; diff --git a/src/smoke_api/smoke_api.hpp b/src/smoke_api/smoke_api.hpp index 00b5a99..4a34bb0 100644 --- a/src/smoke_api/smoke_api.hpp +++ b/src/smoke_api/smoke_api.hpp @@ -4,6 +4,14 @@ namespace smoke_api { 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(); AppId_t get_app_id(); diff --git a/src/steamclient/steamclient.cpp b/src/steamclient/steamclient.cpp index e381d3f..9140ce6 100644 --- a/src/steamclient/steamclient.cpp +++ b/src/steamclient/steamclient.cpp @@ -4,6 +4,7 @@ #include #include "smoke_api/steamclient/steamclient.hpp" +#include "smoke_api/smoke_api.hpp" #include "smoke_api/types.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; 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( __func__, interface_version,