-
Notifications
You must be signed in to change notification settings - Fork 252
Add discord rpc #605
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
base: main
Are you sure you want to change the base?
Add discord rpc #605
Conversation
jacksongoode
left a comment
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.
This is nice - thank you for contributing! but I'd like to do a proper re-review after the unrelated linting changes were resolved.
aae9446 to
d709f7b
Compare
The lsp defaults to 4 spaces for some reason without it
b5eacf2 to
e3fa164
Compare
|
I had a little skim over this PR! It's looking good so far! Also I think the taplo.toml shouldn't be included to the PR. |
|
Just a question, do we have to make it so that the user makes up their ID or are we able to say generate it for them so its more automatic? |
|
Link #186 to close |
|
Any news with this pr? |
|
Also curious about this. And we should maybe hide the ID once the rpc is connected? |
jacksongoode
left a comment
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.
Here are some more comments, but it looks good, just some note around following Last.fm's scrobbler pattern.
| while !discord_presence::Client::is_ready() { | ||
| std::thread::sleep(Duration::from_millis(10)); | ||
| } |
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.
Is 10ms a little too fast for this? Also could there be a case where it never becomes ready? We should have some fallback to kill the loop in that case.
| DiscordRpcCmd::UpdateAppId(new_id) => { | ||
| // take the old client out | ||
| if let Some(old) = rpc.client.take() { | ||
| if let Err(e) = old.shutdown() { | ||
| log::warn!("shutdown failed: {}", e); | ||
| } | ||
| } | ||
| // create replacement | ||
| match Self::create_client(new_id) { | ||
| Ok(new_cli) => rpc.client = Some(new_cli), | ||
| Err(e) => log::warn!("failed to create new client: {}", e), | ||
| } | ||
| } | ||
| } | ||
| } | ||
| // when tx is dropped everywhere, rx returns Err -> loop ends, rpc is dropped |
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.
Nit, these comments can be capitalized.
| None | ||
| } | ||
|
|
||
| fn parse_valid_app_id(id_str: &str) -> Option<u64> { |
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.
Could you add a link to some docs as to what is a valid app id?
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.
| fn update_discord_rpc(&mut self, playback: &Playback) { | ||
| if let Some(now_playing) = playback.now_playing.as_ref() { | ||
| if let Some(discord_rpc_sender) = &mut self.discord_rpc_sender { | ||
| let (title, artist, album_name, images, duration, progress) = | ||
| match &now_playing.item { |
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.
This logic is quite nested, maybe you can opt for some early returns to keep it a little cleaner here.
| self.report_now_playing(&data.playback); | ||
| self.update_discord_rpc(&data.playback); |
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.
If you have a look at the Last.fm reporting it is inside report_now_playing. We should put the Discord rpc scrobbler there as well and generally follow Last.fm's pattern unless there's some reason not to.
| pub lastfm_api_key: Option<String>, | ||
| pub lastfm_api_secret: Option<String>, | ||
| pub lastfm_enable: bool, | ||
| pub discord_rpc_app_id: String, |
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.
Shouldn't this be an Option?
| .with_spacer(theme::grid(1.0)) | ||
| .with_child( | ||
| Label::new( | ||
| "Connects to a running Discord client to display currently playing music", |
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.
| "Connects to a running Discord client to display currently playing music", | |
| "Connects to a running Discord client to display what's currently playing", |
| )) | ||
| .with_spacer(theme::grid(1.0)) | ||
| .with_child( | ||
| Button::new("Create a Discord App →") |
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.
Like the Last.fm button, I don't think we need the arrow - for consistency sake.
| self.for_all_pages(request, |page: Page<Option<EpisodeLink>>| { | ||
| if !page.items.is_empty() { | ||
| let ids = page | ||
| .items | ||
| .into_iter() | ||
| .filter_map(|link| link.map(|link| link.id)); |
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.
Unrelated change?
| @@ -0,0 +1,2 @@ | |||
| [formatting] | |||
| indent_string = " " | |||
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.
Also unrelated?
closes #186
Add Discord Rich Presence (RPC) Support
This adds basic support for Discord Rich Presence to psst.
If you enable it and provide a valid Discord Application ID, the app will connect to your running Discord client and show the currently playing track in your profile.
Changes
discord_rpc.rsmodule underpsst-coreto manage the Discord RPC connection in a background thread.discord-presenceas a new dependency.discord_rpc_enable(bool)discord_rpc_app_id(string)PlaybackController:Behavior
Notes
discord-presence.Screenshots
Why
Because Discord status is cool
and now people can see what garbage music you're listening to in real time.