From 6b2ce266d4f919c302f51a6edeeb2bc88ed76e32 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 3 May 2021 03:14:36 +1000 Subject: [PATCH] dep/discord-rpc: Ensure the cleared presence gets sent at shutdown --- dep/discord-rpc/src/discord_rpc.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/dep/discord-rpc/src/discord_rpc.cpp b/dep/discord-rpc/src/discord_rpc.cpp index 03924538c..3eb2ec614 100644 --- a/dep/discord-rpc/src/discord_rpc.cpp +++ b/dep/discord-rpc/src/discord_rpc.cpp @@ -355,13 +355,20 @@ extern "C" DISCORD_EXPORT void Discord_Shutdown(void) Connection->onConnect = nullptr; Connection->onDisconnect = nullptr; Handlers = {}; + if (IoThread != nullptr) { + IoThread->Stop(); + delete IoThread; + IoThread = nullptr; + } + + // HACK: We need to send the updated (cleared) presence, but we're shutting down. + // Force an update, wait 100ms for it to clear (hopefully this will be long enough), and get any responses. + Discord_UpdateConnection(); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + Discord_UpdateConnection(); + QueuedPresence.length = 0; UpdatePresence.exchange(false); - if (IoThread != nullptr) { - IoThread->Stop(); - delete IoThread; - IoThread = nullptr; - } RpcConnection::Destroy(Connection); }