Skip to content

Commit

Permalink
Merge pull request #22 from RaidcoreGG/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
DeltaGW2 authored Feb 14, 2024
2 parents 80aa3e3 + e87805e commit 9cebfa8
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 17 deletions.
15 changes: 11 additions & 4 deletions src/API/APIClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,15 @@ json APIClient::Get(std::string aEndpoint, std::string aParameters)
if (cachedResponse != nullptr)
{
long long diff = Timestamp() - cachedResponse->Timestamp;
Log(("APIClient::" + BaseURL).c_str(), "diff: %d | curr: %d | cache: %d", diff, Timestamp(), cachedResponse->Timestamp);

if (diff < CacheLifetime && cachedResponse->Content != nullptr)
{
LogDebug(("APIClient::" + BaseURL).c_str(), "Cached message %d seconds old. Reading from cache.", diff);
//LogDebug(("APIClient::" + BaseURL).c_str(), "Cached message %d seconds old. Reading from cache.", diff);
return cachedResponse->Content;
}
else
{
LogDebug(("APIClient::" + BaseURL).c_str(), "Cached message %d seconds old. CacheLifetime %d. Queueing request.", diff, CacheLifetime);
//LogDebug(("APIClient::" + BaseURL).c_str(), "Cached message %d seconds old. CacheLifetime %d. Queueing request.", diff, CacheLifetime);
}
}

Expand Down Expand Up @@ -295,8 +294,16 @@ void APIClient::ProcessRequests()

std::filesystem::path normalizedPath = GetNormalizedPath(request.Query);

auto it = ResponseCache.find(normalizedPath);

if (it != ResponseCache.end())
{
delete it->second;
ResponseCache.erase(normalizedPath);
}

ResponseCache.insert({ normalizedPath, cached });

// notify caller
*(request.IsComplete) = true;
request.CV->notify_all();
Expand Down
10 changes: 5 additions & 5 deletions src/GUI/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,11 +661,6 @@ namespace GUI
/* add shortcut */
QuickAccess::AddShortcut(QA_MENU, ICON_NEXUS, ICON_NEXUS_HOVER, KB_MENU, "Nexus Menu");

if (IsUpdateAvailable && NotifyChangelog)
{
QuickAccess::NotifyShortcut(QA_MENU);
}

if (!Settings::Settings.is_null())
{
if (!Settings::Settings[OPT_ACCEPTEULA].is_null())
Expand Down Expand Up @@ -761,6 +756,11 @@ namespace GUI
}
}

if (IsUpdateAvailable && NotifyChangelog)
{
QuickAccess::NotifyShortcut(QA_MENU);
}

if (!HasAcceptedEULA)
{
EULAModal* eulaModal = new EULAModal();
Expand Down
8 changes: 6 additions & 2 deletions src/GUI/Widgets/Changelog/ChangelogWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "Paths.h"
#include "State.h"

#include "GUI/Widgets/QuickAccess/QuickAccess.h"

#include "imgui.h"
#include "imgui_extensions.h"

Expand All @@ -25,6 +27,8 @@ namespace GUI
{
if (!Visible) { return; }

QuickAccess::SetNotificationShortcut(QA_MENU, false);

ImGui::SetNextWindowSize(ImVec2(chlWidth * ImGui::GetFontSize(), chlHeight * ImGui::GetFontSize()), ImGuiCond_FirstUseEver);
if (ImGui::Begin(Name.c_str(), &Visible, ImGuiWindowFlags_NoCollapse))
{
Expand All @@ -33,11 +37,11 @@ namespace GUI

if (IsUpdateAvailable)
{
ImGui::TextDisabled("These changes take effect the next time you start the game:");
ImGui::TextColored(ImVec4(0, 0.580f, 1, 1), "These changes take effect the next time you start the game:");
}
else
{
ImGui::TextDisabled("Last changes:");
ImGui::Text("Last changes:");
}

if (!ChangelogText.empty())
Expand Down
15 changes: 15 additions & 0 deletions src/GUI/Widgets/QuickAccess/QuickAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,21 @@ namespace GUI
}
QuickAccess::Mutex.unlock();
}
void SetNotificationShortcut(const char* aIdentifier, bool aState)
{
std::string str = aIdentifier;

QuickAccess::Mutex.lock();
{
auto it = Registry.find(str);

if (it != Registry.end())
{
it->second.HasNotification = aState;
}
}
QuickAccess::Mutex.unlock();
}

void AddSimpleShortcut(const char* aIdentifier, GUI_RENDER aShortcutRenderCallback)
{
Expand Down
1 change: 1 addition & 0 deletions src/GUI/Widgets/QuickAccess/QuickAccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace GUI
void AddShortcut(const char* aIdentifier, const char* aTextureIdentifier, const char* aTextureHoverIdentifier, const char* aKeybindIdentifier, const char* aTooltipText);
void RemoveShortcut(const char* aIdentifier);
void NotifyShortcut(const char* aIdentifier);
void SetNotificationShortcut(const char* aIdentifier, bool aState);

void AddSimpleShortcut(const char* aIdentifier, GUI_RENDER aShortcutRenderCallback);
void RemoveSimpleShortcut(const char* aIdentifier);
Expand Down
2 changes: 1 addition & 1 deletion src/Loader/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ namespace Loader
}
}

LogInfo(CH_LOADER, "Successfully installed %s.", aAddon->Name);
LogInfo(CH_LOADER, "Successfully installed %s.", aAddon->Name.c_str());
}

AddonAPI* GetAddonAPI(int aVersion)
Expand Down
10 changes: 5 additions & 5 deletions src/Textures/TextureLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace TextureLoader

void LoadFromFile(const char* aIdentifier, const char* aFilename, TEXTURES_RECEIVECALLBACK aCallback)
{
LogInfo(CH_TEXTURES, "TextureLoader::LoadFromFile(aIdentifier: %s, aFilename: %s, aCallback: %p)", aIdentifier, aFilename, aCallback);
//LogInfo(CH_TEXTURES, "TextureLoader::LoadFromFile(aIdentifier: %s, aFilename: %s, aCallback: %p)", aIdentifier, aFilename, aCallback);

std::string str = aIdentifier;

Expand Down Expand Up @@ -72,7 +72,7 @@ namespace TextureLoader
}
void LoadFromResource(const char* aIdentifier, unsigned aResourceID, HMODULE aModule, TEXTURES_RECEIVECALLBACK aCallback)
{
LogInfo(CH_TEXTURES, "TextureLoader::LoadFromResource(aIdentifier: %s, aResourceID: %u, aModule: %p, aCallback: %p)", aIdentifier, aResourceID, aModule, aCallback);
//LogInfo(CH_TEXTURES, "TextureLoader::LoadFromResource(aIdentifier: %s, aResourceID: %u, aModule: %p, aCallback: %p)", aIdentifier, aResourceID, aModule, aCallback);

std::string str = aIdentifier;

Expand Down Expand Up @@ -123,7 +123,7 @@ namespace TextureLoader
}
void LoadFromURL(const char* aIdentifier, const char* aRemote, const char* aEndpoint, TEXTURES_RECEIVECALLBACK aCallback)
{
LogInfo(CH_TEXTURES, "TextureLoader::LoadFromURL(aIdentifier: %s, aRemote: %s, aEndpoint: %s, aCallback: %p)", aIdentifier, aRemote, aEndpoint, aCallback);
//LogInfo(CH_TEXTURES, "TextureLoader::LoadFromURL(aIdentifier: %s, aRemote: %s, aEndpoint: %s, aCallback: %p)", aIdentifier, aRemote, aEndpoint, aCallback);

std::string str = aIdentifier;

Expand Down Expand Up @@ -170,7 +170,7 @@ namespace TextureLoader
}
void LoadFromMemory(const char* aIdentifier, void* aData, size_t aSize, TEXTURES_RECEIVECALLBACK aCallback)
{
LogInfo(CH_TEXTURES, "TextureLoader::LoadFromMemory(aIdentifier: %s, aData: %p, aSize: %u, aCallback: %p)", aIdentifier, aData, aSize, aCallback);
//LogInfo(CH_TEXTURES, "TextureLoader::LoadFromMemory(aIdentifier: %s, aData: %p, aSize: %u, aCallback: %p)", aIdentifier, aData, aSize, aCallback);

std::string str = aIdentifier;

Expand Down Expand Up @@ -207,7 +207,7 @@ namespace TextureLoader
{
std::string str = aIdentifier;

LogDebug(CH_TEXTURES, "Queued %s", str.c_str());
//LogDebug(CH_TEXTURES, "Queued %s", str.c_str());

QueuedTexture raw{};
raw.Identifier = str;
Expand Down

0 comments on commit 9cebfa8

Please sign in to comment.