Skip to content

Commit 3bd112c

Browse files
committed
Refactored version check
1 parent 7b54b4b commit 3bd112c

File tree

5 files changed

+44
-24
lines changed

5 files changed

+44
-24
lines changed

KoalaBox

res/SmokeAPI.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"logging": {
2121
"type": "boolean",
2222
"default": false,
23-
"x-packaged-default": true,
2423
"description": "Enables logging to SmokeAPI.log.log file.",
24+
"x-packaged-default": true,
2525
"x-valid-values": "`true` or `false`."
2626
},
2727
"log_steam_http": {

src/smoke_api/smoke_api.cpp

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,27 @@ namespace {
5959
bool is_hook_mode;
6060

6161
void check_for_updates() {
62-
const auto latest_release_url = std::format(
63-
"https://api.github.com/repos/acidicoala/{}/releases/latest",
64-
PROJECT_NAME
65-
);
66-
const auto res = kb::http_client::get_json(latest_release_url);
67-
const auto latest_tag = res["tag_name"].get<std::string>();
68-
const auto current_tag = std::format("v{}", PROJECT_VERSION);
69-
70-
if(current_tag == latest_tag) {
71-
LOG_DEBUG("Running the latest version");
72-
} else {
73-
const auto release_page = std::format(
74-
"https://github.com/acidicoala/{}/releases/{}",
75-
PROJECT_NAME, latest_tag
62+
try {
63+
const auto latest_release_url = std::format(
64+
"https://api.github.com/repos/acidicoala/{}/releases/latest",
65+
PROJECT_NAME
7666
);
67+
const auto res = kb::http_client::get_json(latest_release_url);
68+
const auto latest_tag = res["tag_name"].get<std::string>();
69+
const auto current_tag = std::format("v{}", PROJECT_VERSION);
7770

78-
LOG_WARN("New version {} available: {}", latest_tag, release_page);
71+
if(current_tag == latest_tag) {
72+
LOG_DEBUG("Running the latest version");
73+
} else {
74+
const auto release_page = std::format(
75+
"https://github.com/acidicoala/{}/releases/{}",
76+
PROJECT_NAME, latest_tag
77+
);
78+
79+
LOG_WARN("New version {} available: {}", latest_tag, release_page);
80+
}
81+
} catch(const std::exception& e) {
82+
LOG_ERROR("{} -> Unexpected error: {}", __func__, e.what());
7983
}
8084
}
8185

@@ -134,7 +138,9 @@ namespace {
134138
static const auto CreateInterface$ = KB_LIB_GET_FUNC(steamclient_handle, CreateInterface);
135139

136140
if(auto* steamapi_handle = kb::lib::get_lib_handle(STEAM_API_MODULE)) {
137-
if(steamapi_handle != original_steamapi_handle) {
141+
if(original_steamapi_handle == nullptr) { // hook mode on Windows
142+
original_steamapi_handle = steamapi_handle;
143+
} else if(steamapi_handle != original_steamapi_handle) {
138144
LOG_WARN(
139145
"{} -> steamapi_handle ({}) != original_steamapi_handle ({})",
140146
__func__, steamapi_handle, original_steamapi_handle
@@ -287,12 +293,6 @@ namespace smoke_api {
287293
kb::win::check_self_duplicates();
288294
#endif
289295

290-
#ifdef KB_DEBUG
291-
// TODO: Add config option to toggle this and show native OS notification
292-
// The real reason behind this is for automatic testing of HTTPs dependencies
293-
std::thread(check_for_updates).detach();
294-
#endif
295-
296296
// We need to hook functions in either mode
297297
kb::hook::init(true);
298298

@@ -313,6 +313,14 @@ namespace smoke_api {
313313
}
314314
}
315315

316+
void post_init() {
317+
#ifdef KB_DEBUG
318+
// TODO: Add config option to toggle this and show native OS notification
319+
// The real reason behind this is for automatic testing of HTTPs dependencies
320+
std::thread(check_for_updates).detach();
321+
#endif
322+
}
323+
316324
void shutdown() {
317325
try {
318326
static bool shutdown_complete = false;

src/smoke_api/smoke_api.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
namespace smoke_api {
66
void init(void* self_module_handle);
7+
8+
/**
9+
* Post-initialization procedures that must be done after the module is finished loading.
10+
* Reason being that on Windows we should not start new threads while being in DllMain callback,
11+
* otherwise we would run into deadlocks/race-conditions/undefined behavior.
12+
*/
13+
void post_init();
14+
715
void shutdown();
816

917
AppId_t get_app_id();

src/steamclient/steamclient.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <koalabox/logger.hpp>
55

66
#include "smoke_api/steamclient/steamclient.hpp"
7+
#include "smoke_api/smoke_api.hpp"
78
#include "smoke_api/types.hpp"
89

910
#include "steam_api/steam_client.hpp"
@@ -16,6 +17,9 @@ C_DECL(void*) CreateInterface(const char* interface_version, create_interface_re
1617
static std::mutex section;
1718
const std::lock_guard lock(section);
1819

20+
static std::once_flag once_flag;
21+
std::call_once(once_flag, smoke_api::post_init);
22+
1923
return steam_client::GetGenericInterface(
2024
__func__,
2125
interface_version,

0 commit comments

Comments
 (0)