mirror of
https://github.com/yuzu-emu/discord-rpc
synced 2024-11-22 17:53:40 +00:00
change to a UObject
This commit is contained in:
parent
63b467f81d
commit
bd995f047d
3 changed files with 37 additions and 18 deletions
Binary file not shown.
|
@ -4,27 +4,41 @@
|
|||
|
||||
#include "discord-rpc.h"
|
||||
|
||||
DEFINE_LOG_CATEGORY(DiscordLogCategory)
|
||||
DEFINE_LOG_CATEGORY(Discord)
|
||||
|
||||
/*static*/ void UDiscordRpcBlueprint::Initialize(const FString& applicationId, bool autoRegister)
|
||||
static UDiscordRpc* self = nullptr;
|
||||
static void ReadyHandler() {
|
||||
UE_LOG(Discord, Log, TEXT("Discord connected"));
|
||||
if (self) {
|
||||
self->IsConnected = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void DisconnectHandler(int errorCode, const char* message) {
|
||||
UE_LOG(Discord, Log, TEXT("Discord disconnected (%d): %s"), errorCode, message);
|
||||
if (self) {
|
||||
self->IsConnected = false;
|
||||
}
|
||||
};
|
||||
|
||||
void UDiscordRpc::Initialize(const FString& applicationId, bool autoRegister)
|
||||
{
|
||||
self = this;
|
||||
IsConnected = false;
|
||||
DiscordEventHandlers handlers{};
|
||||
handlers.ready = []() {
|
||||
UE_LOG(DiscordLogCategory, Log, TEXT("Discord connected"));
|
||||
};
|
||||
handlers.disconnected = [](int errorCode, const char* message) {
|
||||
UE_LOG(DiscordLogCategory, Log, TEXT("Discord disconnected (%d): %s"), errorCode, message);
|
||||
};
|
||||
handlers.ready = ReadyHandler;
|
||||
handlers.disconnected = DisconnectHandler;
|
||||
auto appId = StringCast<ANSICHAR>(*applicationId);
|
||||
Discord_Initialize((const char*)appId.Get(), &handlers, autoRegister);
|
||||
}
|
||||
|
||||
/*static*/ void UDiscordRpcBlueprint::Shutdown()
|
||||
void UDiscordRpc::Shutdown()
|
||||
{
|
||||
Discord_Shutdown();
|
||||
self = nullptr;
|
||||
}
|
||||
|
||||
/*static*/ void UDiscordRpcBlueprint::RunCallbacks()
|
||||
void UDiscordRpc::RunCallbacks()
|
||||
{
|
||||
Discord_RunCallbacks();
|
||||
}
|
||||
|
|
|
@ -6,22 +6,27 @@
|
|||
#include "CoreMinimal.h"
|
||||
#include "DiscordRpcBlueprint.generated.h"
|
||||
|
||||
DECLARE_LOG_CATEGORY_EXTERN(DiscordLogCategory, Log, All);
|
||||
DECLARE_LOG_CATEGORY_EXTERN(Discord, Log, All);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class DISCORDRPC_API UDiscordRpcBlueprint : public UBlueprintFunctionLibrary
|
||||
UCLASS(BlueprintType, meta = (DisplayName = "Discord RPC"), Category = "Discord")
|
||||
class DISCORDRPC_API UDiscordRpc : public UObject
|
||||
{
|
||||
GENERATED_BODY()
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Discord Initialize connection", Keywords = "Discord rpc"), Category = "Discord")
|
||||
static void Initialize(const FString& applicationId, bool autoRegister);
|
||||
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Discord initialize connection", Keywords = "Discord rpc"), Category = "Discord")
|
||||
void Initialize(const FString& applicationId, bool autoRegister);
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Discord shut down connection", Keywords = "Discord rpc"), Category = "Discord")
|
||||
static void Shutdown();
|
||||
void Shutdown();
|
||||
|
||||
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Discord check for callbacks", Keywords = "Discord rpc"), Category = "Discord")
|
||||
static void RunCallbacks();
|
||||
void RunCallbacks();
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (DisplayName = "Discord connected", Keywords = "Discord rpc"), Category = "Discord")
|
||||
bool IsConnected;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue