Let's just register in init

This commit is contained in:
Chris Marsh 2017-07-27 13:29:24 -07:00
parent 1f6fd05884
commit f617f3b78d
4 changed files with 12 additions and 12 deletions

View file

@ -97,16 +97,13 @@ static void gameLoop()
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
/* This would typically be in an installer and/or wrapped to only run once */
Discord_Register(APPLICATION_ID);
DiscordEventHandlers handlers; DiscordEventHandlers handlers;
memset(&handlers, 0, sizeof(handlers)); memset(&handlers, 0, sizeof(handlers));
handlers.ready = handleDiscordReady; handlers.ready = handleDiscordReady;
handlers.disconnected = handleDiscordDisconnected; handlers.disconnected = handleDiscordDisconnected;
handlers.errored = handleDiscordError; handlers.errored = handleDiscordError;
handlers.presenceRequested = handleDiscordPresenceRequested; handlers.presenceRequested = handleDiscordPresenceRequested;
Discord_Initialize(APPLICATION_ID, &handlers); Discord_Initialize(APPLICATION_ID, &handlers, 1);
gameLoop(); gameLoop();

View file

@ -5,12 +5,6 @@
extern "C" { extern "C" {
#endif #endif
/* Registration */
void Discord_Register(const char* applicationId);
/* RPC */
typedef struct DiscordRichPresence { typedef struct DiscordRichPresence {
const char* state; const char* state;
const char* details; const char* details;
@ -38,7 +32,7 @@ typedef struct DiscordEventHandlers {
void (*spectateGame)(const char* spectateSecret); void (*spectateGame)(const char* spectateSecret);
} DiscordEventHandlers; } DiscordEventHandlers;
void Discord_Initialize(const char* applicationId, DiscordEventHandlers* handlers); void Discord_Initialize(const char* applicationId, DiscordEventHandlers* handlers, int autoRegister);
void Discord_Shutdown(); void Discord_Shutdown();
/* checks for incoming messages, dispatches callbacks */ /* checks for incoming messages, dispatches callbacks */

4
src/discord-register.h Normal file
View file

@ -0,0 +1,4 @@
#pragma once
void Discord_Register(const char* applicationId);

View file

@ -1,6 +1,7 @@
#include "discord-rpc.h" #include "discord-rpc.h"
#include "backoff.h" #include "backoff.h"
#include "discord-register.h"
#include "rpc_connection.h" #include "rpc_connection.h"
#include "serialization.h" #include "serialization.h"
@ -179,8 +180,12 @@ bool RegisterForEvent(const char* evtName)
return false; return false;
} }
extern "C" void Discord_Initialize(const char* applicationId, DiscordEventHandlers* handlers) extern "C" void Discord_Initialize(const char* applicationId, DiscordEventHandlers* handlers, int autoRegister)
{ {
if (autoRegister) {
Discord_Register(applicationId);
}
Pid = GetProcessId(); Pid = GetProcessId();
if (handlers) { if (handlers) {