-
-
Notifications
You must be signed in to change notification settings - Fork 113
Added UpdateButtons
#175
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
Added UpdateButtons
#175
Conversation
I forgot to mention that there was also an issue for this #147 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall good contribution. Only request minor change to the UpdateButton(Button[], int)
call
DiscordRPC/DiscordRpcClient.cs
Outdated
public RichPresence UpdateButtons(Button[] button, int buttonId) | ||
{ | ||
if (!IsInitialized) | ||
{ | ||
throw new UninitializedException(); | ||
} | ||
|
||
// Get the original index of the button | ||
var buttonIndex = buttonId - 1; | ||
|
||
// Clone the presence | ||
RichPresence presence; | ||
lock (_sync) | ||
{ | ||
if (CurrentPresence == null) | ||
{ | ||
presence = new RichPresence(); | ||
} | ||
else | ||
{ | ||
presence = CurrentPresence.Clone(); | ||
} | ||
} | ||
|
||
// Update the buttons | ||
presence.Buttons[buttonIndex] = button[buttonIndex]; | ||
SetPresence(presence); | ||
|
||
return presence; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better way to implement this function is to:
- Make it only take a single Button instead of an array
- Turn
buttonId
intoindex
instead which starts from 0. - Rename it to
UpdateButton
orSetButton
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll look into the code later today for the minor changes you have requested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I implemented your request. I added that the index
in the SetButton
method is 0
by default. Users can now use this method by the following way:
// Using button as an variable
var newButton = new Button()
{
Label = "Updated btn",
Url = "https://github.com/Lachee/discord-rpc-csharp"
};
client.SetButton(newButton);
// Updating it without an variable
client.SetButton(new Button()
{
Label = "Updated btn",
Url = "https://github.com/Lachee/discord-rpc-csharp"
});
Implemented the request. See: #175 (comment)
This pull request will allow users to update and remove their buttons without having to restart the program.
You can use this code in the following way:
Updating all the buttons
When a user wants to update all their buttons from the current Rich Presence they can do the following:
Updating a single button
When a user wants to update a single button from the current Rich Presence they can do the following:
Example: You have 2 buttons. The first one is a link to your website and the second one is a link to your Discord server. You want to update the second one with an up-to-date invite link you can do the following code:
Removing buttons
When a user want to remove their buttons from the current Rich Presence they can do the following:
If there are any follow up questions or things I might have missed let me know and I will look into it asap!