mirror of
https://github.com/yuzu-emu/discord-rpc.git
synced 2024-11-24 03:55:41 +01:00
Fix ordering of ready/disconnect callbacks.
This commit is contained in:
parent
a7eb65355e
commit
60ad70adc2
@ -274,18 +274,28 @@ extern "C" void Discord_UpdatePresence(const DiscordRichPresence* presence)
|
|||||||
|
|
||||||
extern "C" void Discord_RunCallbacks()
|
extern "C" void Discord_RunCallbacks()
|
||||||
{
|
{
|
||||||
if (GotErrorMessage.exchange(false) && Handlers.errored) {
|
// Note on some weirdness: internally we might connect, get other signals, disconnect any number
|
||||||
Handlers.errored(LastErrorCode, LastErrorMessage);
|
// 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);
|
||||||
Handlers.disconnected(LastDisconnectErrorCode, LastDisconnectErrorMessage);
|
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) {
|
if (WasJustConnected.exchange(false) && Handlers.ready) {
|
||||||
Handlers.ready();
|
Handlers.ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GotErrorMessage.exchange(false) && Handlers.errored) {
|
||||||
|
Handlers.errored(LastErrorCode, LastErrorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
if (WasJoinGame.exchange(false) && Handlers.joinGame) {
|
if (WasJoinGame.exchange(false) && Handlers.joinGame) {
|
||||||
Handlers.joinGame(JoinGameSecret);
|
Handlers.joinGame(JoinGameSecret);
|
||||||
}
|
}
|
||||||
@ -293,4 +303,11 @@ extern "C" void Discord_RunCallbacks()
|
|||||||
if (WasSpectateGame.exchange(false) && Handlers.spectateGame) {
|
if (WasSpectateGame.exchange(false) && Handlers.spectateGame) {
|
||||||
Handlers.spectateGame(SpectateGameSecret);
|
Handlers.spectateGame(SpectateGameSecret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isConnected) {
|
||||||
|
// if we are not connected, disconnect message last
|
||||||
|
if (wasDisconnected && Handlers.disconnected) {
|
||||||
|
Handlers.disconnected(LastDisconnectErrorCode, LastDisconnectErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user