Skip to content

Commit

Permalink
Merge pull request #27 from configcat/blogspot-fixes
Browse files Browse the repository at this point in the history
Improved onboarding flow based on blog spot
  • Loading branch information
pasotee authored Sep 2, 2024
2 parents 1e3a3ee + c391ecf commit 51272db
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion ConfigCat.uplugin
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"FileVersion": 3,
"VersionName": "2.1.6",
"VersionName": "2.1.7",
"EngineVersion": "5.4",
"FriendlyName": "ConfigCat",
"Description": "ConfigCat is a hosted service for feature flag and configuration management. It lets you decouple feature releases from code deployments.",
Expand Down
44 changes: 27 additions & 17 deletions Source/ConfigCat/Private/ConfigCatSubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <Logging/LogVerbosity.h>
#include <Misc/ConfigCacheIni.h>
#include <Engine/GameInstance.h>
#include <Engine/Engine.h>

#include "ConfigCat.h"
#include "ConfigCatLog.h"
Expand All @@ -27,21 +28,30 @@ using namespace configcat;

namespace
{
void PrintError(const FString& ErrorMessage)
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, FString::Printf(TEXT("[ConfigCat] %s"), *ErrorMessage));
}
UE_LOG(LogConfigCat, Error, TEXT("%s"), *ErrorMessage);
}

bool EnsureConfigCatClient(const std::shared_ptr<configcat::ConfigCatClient>& Client)
{
if (ensure(Client))
if (Client)
{
return true;
}

UE_LOG(LogConfigCat, Warning, TEXT("Trying to access the ConfigCatClient before initialization or after shutdown."));
PrintError(TEXT("Trying to access the client before initialization or after shutdown."));
return false;
}

template <typename T>
T GetValue(const std::shared_ptr<ConfigCatClient>& Client, FString Key, T DefaultValue, const UConfigCatUserWrapper* User)
{
if(!EnsureConfigCatClient(Client))
if (!EnsureConfigCatClient(Client))
{
return DefaultValue;
}
Expand All @@ -54,7 +64,7 @@ namespace
template <typename T>
UConfigCatEvaluationWrapper* GetEvaluationDetails(const std::shared_ptr<ConfigCatClient>& Client, FString Key, T DefaultValue, const UConfigCatUserWrapper* User)
{
if(!EnsureConfigCatClient(Client))
if (!EnsureConfigCatClient(Client))
{
return {};
}
Expand Down Expand Up @@ -98,7 +108,7 @@ FString UConfigCatSubsystem::GetStringValue(const FString& Key, const FString& D

UConfigCatValueWrapper* UConfigCatSubsystem::GetConfigValue(const FString& Key, const UConfigCatUserWrapper* User) const
{
if(!EnsureConfigCatClient(ConfigCatClient))
if (!EnsureConfigCatClient(ConfigCatClient))
{
return {};
}
Expand Down Expand Up @@ -132,7 +142,7 @@ UConfigCatEvaluationWrapper* UConfigCatSubsystem::GetStringValueDetails(const FS

TArray<FString> UConfigCatSubsystem::GetAllKeys() const
{
if(!EnsureConfigCatClient(ConfigCatClient))
if (!EnsureConfigCatClient(ConfigCatClient))
{
return {};
}
Expand All @@ -150,7 +160,7 @@ TArray<FString> UConfigCatSubsystem::GetAllKeys() const

bool UConfigCatSubsystem::GetKeyAndValue(const FString& VariationId, FString& OutKey, UConfigCatValueWrapper*& OutValue) const
{
if(!EnsureConfigCatClient(ConfigCatClient))
if (!EnsureConfigCatClient(ConfigCatClient))
{
return false;
}
Expand All @@ -171,7 +181,7 @@ bool UConfigCatSubsystem::GetKeyAndValue(const FString& VariationId, FString& Ou

TMap<FString, UConfigCatValueWrapper*> UConfigCatSubsystem::GetAllValues(const UConfigCatUserWrapper* User) const
{
if(!EnsureConfigCatClient(ConfigCatClient))
if (!EnsureConfigCatClient(ConfigCatClient))
{
return {};
}
Expand All @@ -189,7 +199,7 @@ TMap<FString, UConfigCatValueWrapper*> UConfigCatSubsystem::GetAllValues(const U

TArray<UConfigCatEvaluationWrapper*> UConfigCatSubsystem::GetAllValueDetails(const UConfigCatUserWrapper* User) const
{
if(!EnsureConfigCatClient(ConfigCatClient))
if (!EnsureConfigCatClient(ConfigCatClient))
{
return {};
}
Expand All @@ -207,7 +217,7 @@ TArray<UConfigCatEvaluationWrapper*> UConfigCatSubsystem::GetAllValueDetails(con

void UConfigCatSubsystem::ForceRefresh()
{
if(!EnsureConfigCatClient(ConfigCatClient))
if (!EnsureConfigCatClient(ConfigCatClient))
{
return;
}
Expand All @@ -217,7 +227,7 @@ void UConfigCatSubsystem::ForceRefresh()

void UConfigCatSubsystem::SetDefaultUser(const UConfigCatUserWrapper* User)
{
if(!EnsureConfigCatClient(ConfigCatClient))
if (!EnsureConfigCatClient(ConfigCatClient))
{
return;
}
Expand All @@ -232,7 +242,7 @@ void UConfigCatSubsystem::SetDefaultUser(const UConfigCatUserWrapper* User)

void UConfigCatSubsystem::ClearDefaultUser()
{
if(!EnsureConfigCatClient(ConfigCatClient))
if (!EnsureConfigCatClient(ConfigCatClient))
{
return;
}
Expand All @@ -242,7 +252,7 @@ void UConfigCatSubsystem::ClearDefaultUser()

void UConfigCatSubsystem::SetOnline()
{
if(!EnsureConfigCatClient(ConfigCatClient))
if (!EnsureConfigCatClient(ConfigCatClient))
{
return;
}
Expand All @@ -252,7 +262,7 @@ void UConfigCatSubsystem::SetOnline()

void UConfigCatSubsystem::SetOffline()
{
if(!EnsureConfigCatClient(ConfigCatClient))
if (!EnsureConfigCatClient(ConfigCatClient))
{
return;
}
Expand All @@ -262,7 +272,7 @@ void UConfigCatSubsystem::SetOffline()

bool UConfigCatSubsystem::IsOffline() const
{
if(!EnsureConfigCatClient(ConfigCatClient))
if (!EnsureConfigCatClient(ConfigCatClient))
{
return true;
}
Expand All @@ -279,7 +289,7 @@ void UConfigCatSubsystem::Initialize(FSubsystemCollectionBase& Collection)
const UConfigCatSettings* ConfigCatSettings = GetDefault<UConfigCatSettings>();
if (!ConfigCatSettings || ConfigCatSettings->SdkKey.IsEmpty())
{
UE_LOG(LogConfigCat, Warning, TEXT("Empty SdkKey detected. Please set your SdkKey in the Project Settings."));
PrintError(TEXT("SdkKey missing. Please set your SdkKey in the Project Settings."));
return;
}

Expand Down Expand Up @@ -336,7 +346,7 @@ void UConfigCatSubsystem::Initialize(FSubsystemCollectionBase& Collection)
ConfigCatClient = ConfigCatClient::get(SdkKey, &Options);

#ifdef CONFIGCAT_HTTPTHREAD_WORKAROUND
if(ConfigCatSettings->PollingMode == EPollingMode::Auto)
if (ConfigCatSettings->PollingMode == EPollingMode::Auto)
{
ForceRefresh();
}
Expand Down
2 changes: 2 additions & 0 deletions Source/ConfigCat/Public/ConfigCatNetworkAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <ConfigCatCppSDK/Include/httpsessionadapter.h>
#include <Interfaces/IHttpRequest.h>

#include <memory>

namespace configcat
{
class PollingMode;
Expand Down

0 comments on commit 51272db

Please sign in to comment.