Skip to content

Commit

Permalink
performance update
Browse files Browse the repository at this point in the history
storing skin data instead of re-requesting it each patch.
  • Loading branch information
ShadowMonster99 committed Jan 18, 2024
1 parent e26eb0b commit 3210eab
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/core/injector/event_handler.cpp
Expand Up @@ -418,7 +418,7 @@ class client : public std::enable_shared_from_this<client>
checkRegex(hook, steam_cef_manager::script_type::javascript);
}

const auto colors = config.getRootColors();
const auto colors = config.getRootColors(skin_json_config);
std::string responseBody;

// if the hooked file is a css file, we want to add the colors structure.
Expand Down Expand Up @@ -1142,7 +1142,7 @@ unsigned long __stdcall Initialize(void*)
{
config.setupMillennium();
skin_json_config = config.getThemeData();
config.installFonts();
//config.installFonts();

//std::cout << skin_json_config.dump(4) << std::endl;

Expand All @@ -1151,15 +1151,15 @@ unsigned long __stdcall Initialize(void*)
console.imp("skin change event fired, updating skin patch config");
skin_json_config = config.getThemeData();
client::get_instance().update_fetch_hook_status();
config.installFonts();
//config.installFonts();
});

//config file watcher callback function
std::thread watcher(themeConfig::watchPath, config.getSkinDir(), []() {
console.log("skins folder has changed, updating required information");
skin_json_config = config.getThemeData();
client::get_instance().update_fetch_hook_status();
config.installFonts();
//config.installFonts();
m_Client.parseSkinData();
});

Expand Down
2 changes: 2 additions & 0 deletions src/core/injector/event_handler.hpp
Expand Up @@ -15,4 +15,6 @@ class steam_client
steam_client();
};

extern nlohmann::basic_json<> skin_json_config;

unsigned long __stdcall Initialize(void*);
3 changes: 2 additions & 1 deletion src/core/steam/cef_manager.cpp
Expand Up @@ -51,7 +51,8 @@ std::string injectSystemColors() {
return std::format("(document.querySelector('#SystemAccentColorInject') || document.head.appendChild(Object.assign(document.createElement('style'), {{ id: 'SystemAccentColorInject' }}))).innerText = `{}`;", getColorStr());
}
std::string injectGlobalColor() {
const auto colors = config.getRootColors();
const auto colors = config.getRootColors(skin_json_config);

return colors != "[NoColors]" ? std::format("(document.querySelector('#globalColors') || document.head.appendChild(Object.assign(document.createElement('style'), {{ id: 'globalColors' }}))).innerText = `{}`;", colors) : "";
}

Expand Down
14 changes: 11 additions & 3 deletions src/utils/config/config.cpp
Expand Up @@ -222,10 +222,8 @@ std::string themeConfig::getSkinDir()
return m_themesPath;
}

const std::string themeConfig::getRootColors()
const std::string themeConfig::getRootColors(nlohmann::basic_json<> data)
{
const auto data = config.getThemeData();

if (data.contains("GlobalsColors") && data.is_object())
{
std::string header = ":root { ";
Expand Down Expand Up @@ -416,6 +414,8 @@ const void themeConfig::setThemeData(nlohmann::json& object) noexcept

const nlohmann::json themeConfig::getThemeData(bool raw) noexcept
{
auto start_time = std::chrono::high_resolution_clock::now();

const std::string ACTIVE_ITEM = Settings::Get<std::string>("active-skin");

std::basic_ifstream<char, std::char_traits<char>> localTheme(std::format("{}/{}/skin.json", m_themesPath, ACTIVE_ITEM));
Expand Down Expand Up @@ -480,6 +480,14 @@ const nlohmann::json themeConfig::getThemeData(bool raw) noexcept
}
}


auto end_time = std::chrono::high_resolution_clock::now();

auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time);

std::cout << "Elapsed time: " << duration.count() << " ms" << '\n';


return jsonBuffer;
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/config/config.hpp
Expand Up @@ -70,7 +70,7 @@ class themeConfig
themeConfig();

std::string getSkinDir();
const std::string getRootColors();
const std::string getRootColors(nlohmann::basic_json<> data);
const void installFonts();

/// <summary>
Expand Down

0 comments on commit 3210eab

Please sign in to comment.