From 6a7e48e9c34590d79a757e16538b6453803624d8 Mon Sep 17 00:00:00 2001 From: Panda Soli Date: Wed, 27 Sep 2023 15:31:33 -0300 Subject: [PATCH] implemet buttons --- examples/send-presence/send-presence.c | 10 +++++++--- include/discord_rpc.h | 7 +++++++ src/discord_register_linux.cpp | 12 ++++++------ src/serialization.cpp | 14 ++++++++++++++ 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/examples/send-presence/send-presence.c b/examples/send-presence/send-presence.c index 1b651f2c..0ac6b133 100644 --- a/examples/send-presence/send-presence.c +++ b/examples/send-presence/send-presence.c @@ -34,6 +34,9 @@ static int prompt(char* line, size_t size) static void updateDiscordPresence() { if (SendPresence) { + DiscordPresenceButton btn2 = {"DuckDuckGo", "https://duckduckgo.com", NULL}; + DiscordPresenceButton btn1 = {"Google", "https://google.com", &btn2}; + char buffer[256]; DiscordRichPresence discordPresence; memset(&discordPresence, 0, sizeof(discordPresence)); @@ -48,10 +51,11 @@ static void updateDiscordPresence() discordPresence.partySize = 1; discordPresence.partyMax = 6; discordPresence.partyPrivacy = DISCORD_PARTY_PUBLIC; - discordPresence.matchSecret = "xyzzy"; - discordPresence.joinSecret = "join"; - discordPresence.spectateSecret = "look"; + // discordPresence.matchSecret = "xyzzy"; + // discordPresence.joinSecret = "join"; + // discordPresence.spectateSecret = "look"; discordPresence.instance = 0; + discordPresence.buttons = &btn1; Discord_UpdatePresence(&discordPresence); } else { diff --git a/include/discord_rpc.h b/include/discord_rpc.h index 9470434a..c8782ef9 100644 --- a/include/discord_rpc.h +++ b/include/discord_rpc.h @@ -23,6 +23,12 @@ extern "C" { #endif +typedef struct DiscordPresenceButton { + const char* label; + const char* url; + const struct DiscordPresenceButton* next; +} DiscordPresenceButton; + typedef struct DiscordRichPresence { const char* state; /* max 128 bytes */ const char* details; /* max 128 bytes */ @@ -40,6 +46,7 @@ typedef struct DiscordRichPresence { const char* joinSecret; /* max 128 bytes */ const char* spectateSecret; /* max 128 bytes */ int8_t instance; + const DiscordPresenceButton* buttons; } DiscordRichPresence; typedef struct DiscordUser { diff --git a/src/discord_register_linux.cpp b/src/discord_register_linux.cpp index dd92eea0..dfc5340c 100644 --- a/src/discord_register_linux.cpp +++ b/src/discord_register_linux.cpp @@ -42,12 +42,12 @@ extern "C" DISCORD_EXPORT void Discord_Register(const char* applicationId, const } const char* desktopFileFormat = "[Desktop Entry]\n" - "Name=Game %s\n" - "Exec=%s %%u\n" // note: it really wants that %u in there - "Type=Application\n" - "NoDisplay=true\n" - "Categories=Discord;Games;\n" - "MimeType=x-scheme-handler/discord-%s;\n"; + "Name=Game %s\n" + "Exec=%s %%u\n" // note: it really wants that %u in there + "Type=Application\n" + "NoDisplay=true\n" + "Categories=Discord;Games;\n" + "MimeType=x-scheme-handler/discord-%s;\n"; char desktopFile[2048]; int fileLen = snprintf( desktopFile, sizeof(desktopFile), desktopFileFormat, applicationId, command, applicationId); diff --git a/src/serialization.cpp b/src/serialization.cpp index 70efa637..35efef2a 100644 --- a/src/serialization.cpp +++ b/src/serialization.cpp @@ -160,6 +160,20 @@ size_t JsonWriteRichPresenceObj(char* dest, writer.Key("instance"); writer.Bool(presence->instance != 0); + + if (presence->buttons) { + WriteArray buttons(writer, "buttons"); + + const DiscordPresenceButton* current = presence->buttons; + do { + if (current->label && current->url) { + WriteObject button(writer); + + WriteOptionalString(writer, "label", current->label); + WriteOptionalString(writer, "url", current->url); + } + } while ((current = current->next) != NULL); + } } } }