mirror of
https://github.com/yuzu-emu/discord-rpc.git
synced 2024-11-23 19:55:38 +01:00
ACTUALLY register the handlers on init
This commit is contained in:
parent
c70acbe7d1
commit
be8a8e9380
@ -47,6 +47,7 @@ struct JoinRequest {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static RpcConnection* Connection{nullptr};
|
static RpcConnection* Connection{nullptr};
|
||||||
|
static DiscordEventHandlers QueuedHandlers{};
|
||||||
static DiscordEventHandlers Handlers{};
|
static DiscordEventHandlers Handlers{};
|
||||||
static std::atomic_bool WasJustConnected{false};
|
static std::atomic_bool WasJustConnected{false};
|
||||||
static std::atomic_bool WasJustDisconnected{false};
|
static std::atomic_bool WasJustDisconnected{false};
|
||||||
@ -282,12 +283,16 @@ extern "C" DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
|
|||||||
|
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(HandlerMutex);
|
std::lock_guard<std::mutex> guard(HandlerMutex);
|
||||||
|
|
||||||
if (handlers) {
|
if (handlers) {
|
||||||
Handlers = *handlers;
|
QueuedHandlers = *handlers;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Handlers = {};
|
QueuedHandlers = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Handlers = {};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Connection) {
|
if (Connection) {
|
||||||
@ -296,13 +301,17 @@ extern "C" DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
|
|||||||
|
|
||||||
Connection = RpcConnection::Create(applicationId);
|
Connection = RpcConnection::Create(applicationId);
|
||||||
Connection->onConnect = []() {
|
Connection->onConnect = []() {
|
||||||
Discord_UpdateHandlers(&Handlers);
|
Discord_UpdateHandlers(&QueuedHandlers);
|
||||||
WasJustConnected.exchange(true);
|
WasJustConnected.exchange(true);
|
||||||
ReconnectTimeMs.reset();
|
ReconnectTimeMs.reset();
|
||||||
};
|
};
|
||||||
Connection->onDisconnect = [](int err, const char* message) {
|
Connection->onDisconnect = [](int err, const char* message) {
|
||||||
LastDisconnectErrorCode = err;
|
LastDisconnectErrorCode = err;
|
||||||
StringCopy(LastDisconnectErrorMessage, message);
|
StringCopy(LastDisconnectErrorMessage, message);
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(HandlerMutex);
|
||||||
|
Handlers = {};
|
||||||
|
}
|
||||||
WasJustDisconnected.exchange(true);
|
WasJustDisconnected.exchange(true);
|
||||||
UpdateReconnectTime();
|
UpdateReconnectTime();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user