mirror of
https://github.com/yuzu-emu/discord-rpc.git
synced 2024-12-23 11:05:39 +00:00
Allow for disconnect/reconnect.
This commit is contained in:
parent
54bef63d67
commit
0271889b2e
|
@ -75,6 +75,18 @@ static int prompt(char* line, size_t size)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void discordInit()
|
||||||
|
{
|
||||||
|
DiscordEventHandlers handlers;
|
||||||
|
memset(&handlers, 0, sizeof(handlers));
|
||||||
|
handlers.ready = handleDiscordReady;
|
||||||
|
handlers.disconnected = handleDiscordDisconnected;
|
||||||
|
handlers.errored = handleDiscordError;
|
||||||
|
handlers.joinGame = handleDiscordJoin;
|
||||||
|
handlers.spectateGame = handleDiscordSpectate;
|
||||||
|
Discord_Initialize(APPLICATION_ID, &handlers, 1);
|
||||||
|
}
|
||||||
|
|
||||||
static void gameLoop()
|
static void gameLoop()
|
||||||
{
|
{
|
||||||
char line[512];
|
char line[512];
|
||||||
|
@ -88,6 +100,19 @@ static void gameLoop()
|
||||||
if (line[0] == 'q') {
|
if (line[0] == 'q') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (line[0] == 't') {
|
||||||
|
printf("Shutting off Discord.\n");
|
||||||
|
Discord_Shutdown();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line[0] == 'y') {
|
||||||
|
printf("Reinit Discord.\n");
|
||||||
|
discordInit();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (time(NULL) & 1) {
|
if (time(NULL) & 1) {
|
||||||
printf("I don't understand that.\n");
|
printf("I don't understand that.\n");
|
||||||
}
|
}
|
||||||
|
@ -113,15 +138,7 @@ static void gameLoop()
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
DiscordEventHandlers handlers;
|
discordInit();
|
||||||
memset(&handlers, 0, sizeof(handlers));
|
|
||||||
handlers.ready = handleDiscordReady;
|
|
||||||
handlers.disconnected = handleDiscordDisconnected;
|
|
||||||
handlers.errored = handleDiscordError;
|
|
||||||
handlers.joinGame = handleDiscordJoin;
|
|
||||||
handlers.spectateGame = handleDiscordSpectate;
|
|
||||||
|
|
||||||
Discord_Initialize(APPLICATION_ID, &handlers, 1);
|
|
||||||
|
|
||||||
gameLoop();
|
gameLoop();
|
||||||
|
|
||||||
|
|
|
@ -223,6 +223,10 @@ extern "C" void Discord_Initialize(const char* applicationId,
|
||||||
Handlers = {};
|
Handlers = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Connection) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Connection = RpcConnection::Create(applicationId);
|
Connection = RpcConnection::Create(applicationId);
|
||||||
Connection->onConnect = []() {
|
Connection->onConnect = []() {
|
||||||
WasJustConnected.exchange(true);
|
WasJustConnected.exchange(true);
|
||||||
|
@ -244,12 +248,16 @@ extern "C" void Discord_Initialize(const char* applicationId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef DISCORD_DISABLE_IO_THREAD
|
#ifndef DISCORD_DISABLE_IO_THREAD
|
||||||
|
KeepRunning.store(true);
|
||||||
IoThread = std::thread(DiscordRpcIo);
|
IoThread = std::thread(DiscordRpcIo);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void Discord_Shutdown()
|
extern "C" void Discord_Shutdown()
|
||||||
{
|
{
|
||||||
|
if (!Connection) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Connection->onConnect = nullptr;
|
Connection->onConnect = nullptr;
|
||||||
Connection->onDisconnect = nullptr;
|
Connection->onDisconnect = nullptr;
|
||||||
Handlers = {};
|
Handlers = {};
|
||||||
|
|
|
@ -17,6 +17,7 @@ static RpcConnection Instance;
|
||||||
{
|
{
|
||||||
c->Close();
|
c->Close();
|
||||||
BaseConnection::Destroy(c->connection);
|
BaseConnection::Destroy(c->connection);
|
||||||
|
c = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RpcConnection::Open()
|
void RpcConnection::Open()
|
||||||
|
|
Loading…
Reference in a new issue