mirror of
https://github.com/yuzu-emu/discord-rpc
synced 2024-11-23 15:03:49 +00:00
Fix ordering of ready/disconnect callbacks.
This commit is contained in:
parent
a7eb65355e
commit
60ad70adc2
1 changed files with 22 additions and 5 deletions
|
@ -274,18 +274,28 @@ extern "C" void Discord_UpdatePresence(const DiscordRichPresence* presence)
|
|||
|
||||
extern "C" void Discord_RunCallbacks()
|
||||
{
|
||||
if (GotErrorMessage.exchange(false) && Handlers.errored) {
|
||||
Handlers.errored(LastErrorCode, LastErrorMessage);
|
||||
}
|
||||
// Note on some weirdness: internally we might connect, get other signals, disconnect any number
|
||||
// of times inbetween calls here. Externally, we want the sequence to seem sane, so any other
|
||||
// signals are book-ended by calls to ready and disconnect.
|
||||
|
||||
if (WasJustDisconnected.exchange(false) && Handlers.disconnected) {
|
||||
bool wasDisconnected = WasJustDisconnected.exchange(false);
|
||||
bool isConnected = Connection->IsOpen();
|
||||
|
||||
if (isConnected) {
|
||||
// if we are connected, disconnect cb first
|
||||
if (wasDisconnected && Handlers.disconnected) {
|
||||
Handlers.disconnected(LastDisconnectErrorCode, LastDisconnectErrorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
if (WasJustConnected.exchange(false) && Handlers.ready) {
|
||||
Handlers.ready();
|
||||
}
|
||||
|
||||
if (GotErrorMessage.exchange(false) && Handlers.errored) {
|
||||
Handlers.errored(LastErrorCode, LastErrorMessage);
|
||||
}
|
||||
|
||||
if (WasJoinGame.exchange(false) && Handlers.joinGame) {
|
||||
Handlers.joinGame(JoinGameSecret);
|
||||
}
|
||||
|
@ -293,4 +303,11 @@ extern "C" void Discord_RunCallbacks()
|
|||
if (WasSpectateGame.exchange(false) && Handlers.spectateGame) {
|
||||
Handlers.spectateGame(SpectateGameSecret);
|
||||
}
|
||||
|
||||
if (!isConnected) {
|
||||
// if we are not connected, disconnect message last
|
||||
if (wasDisconnected && Handlers.disconnected) {
|
||||
Handlers.disconnected(LastDisconnectErrorCode, LastDisconnectErrorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue