From f617f3b78d88055b2e8390bf856c6d0e2a617ba3 Mon Sep 17 00:00:00 2001 From: Chris Marsh Date: Thu, 27 Jul 2017 13:29:24 -0700 Subject: [PATCH] Let's just register in init --- examples/send-presence/send-presence.c | 5 +---- include/discord-rpc.h | 8 +------- src/discord-register.h | 4 ++++ src/discord-rpc.cpp | 7 ++++++- 4 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 src/discord-register.h diff --git a/examples/send-presence/send-presence.c b/examples/send-presence/send-presence.c index 68082ea..082a396 100644 --- a/examples/send-presence/send-presence.c +++ b/examples/send-presence/send-presence.c @@ -97,16 +97,13 @@ static void gameLoop() 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; memset(&handlers, 0, sizeof(handlers)); handlers.ready = handleDiscordReady; handlers.disconnected = handleDiscordDisconnected; handlers.errored = handleDiscordError; handlers.presenceRequested = handleDiscordPresenceRequested; - Discord_Initialize(APPLICATION_ID, &handlers); + Discord_Initialize(APPLICATION_ID, &handlers, 1); gameLoop(); diff --git a/include/discord-rpc.h b/include/discord-rpc.h index 33400ce..519740e 100644 --- a/include/discord-rpc.h +++ b/include/discord-rpc.h @@ -5,12 +5,6 @@ extern "C" { #endif -/* Registration */ - -void Discord_Register(const char* applicationId); - -/* RPC */ - typedef struct DiscordRichPresence { const char* state; const char* details; @@ -38,7 +32,7 @@ typedef struct DiscordEventHandlers { void (*spectateGame)(const char* spectateSecret); } DiscordEventHandlers; -void Discord_Initialize(const char* applicationId, DiscordEventHandlers* handlers); +void Discord_Initialize(const char* applicationId, DiscordEventHandlers* handlers, int autoRegister); void Discord_Shutdown(); /* checks for incoming messages, dispatches callbacks */ diff --git a/src/discord-register.h b/src/discord-register.h new file mode 100644 index 0000000..631631f --- /dev/null +++ b/src/discord-register.h @@ -0,0 +1,4 @@ +#pragma once + +void Discord_Register(const char* applicationId); + diff --git a/src/discord-rpc.cpp b/src/discord-rpc.cpp index 07271b9..5f7303a 100644 --- a/src/discord-rpc.cpp +++ b/src/discord-rpc.cpp @@ -1,6 +1,7 @@ #include "discord-rpc.h" #include "backoff.h" +#include "discord-register.h" #include "rpc_connection.h" #include "serialization.h" @@ -179,8 +180,12 @@ bool RegisterForEvent(const char* evtName) 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(); if (handlers) {