Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement buttons #386

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions examples/send-presence/send-presence.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions include/discord_rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions src/discord_register_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions src/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down