Skip to content

Commit

Permalink
Merge pull request #145 from Radiicall/button-fixes
Browse files Browse the repository at this point in the history
Fixes issues with custom buttons and forbids dynamic buttons with localhost urls
  • Loading branch information
Radiicall authored Sep 7, 2024
2 parents d5fc10e + 7239f9f commit 3fff9e5
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions jellyfin-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use discord_rich_presence::{
};
pub use error::JfError;
pub use jellyfin::{Button, MediaType};
use jellyfin::{EndTime, Item, RawSession, Session};
use jellyfin::{EndTime, ExternalUrl, Item, RawSession, Session};
use log::debug;
use reqwest::header::{HeaderMap, AUTHORIZATION};
use std::str::FromStr;
Expand Down Expand Up @@ -245,14 +245,18 @@ impl Client {
&session.now_playing_item.external_urls,
self.buttons.as_ref(),
) {
let ext_urls: Vec<&ExternalUrl> = ext_urls
.iter()
.filter(|eu| !eu.url.starts_with("http://localhost") && !eu.url.starts_with("https://localhost"))
.collect();
let mut i = 0;
for button in buttons {
if activity_buttons.len() == 2 {
break;
}

if button.is_dynamic() {
if ext_urls.len() - 1 == i {
if ext_urls.len() > i {
activity_buttons.push(Button::new(
ext_urls[i].name.clone(),
ext_urls[i].url.clone(),
Expand All @@ -264,24 +268,28 @@ impl Client {
}
}
return Some(activity_buttons);
} else if let Some(ext_urls) = &session.now_playing_item.external_urls {
for ext_url in ext_urls {
} else if let Some(buttons) = self.buttons.as_ref() {
for button in buttons {
if activity_buttons.len() == 2 {
break;
}

activity_buttons.push(Button::new(ext_url.name.clone(), ext_url.url.clone()))
if !button.is_dynamic() {
activity_buttons.push(button.clone())
}
}
return Some(activity_buttons);
} else if let Some(buttons) = self.buttons.as_ref() {
for button in buttons {
} else if let Some(ext_urls) = &session.now_playing_item.external_urls {
let ext_urls: Vec<&ExternalUrl> = ext_urls
.iter()
.filter(|eu| !eu.url.starts_with("http://localhost") && !eu.url.starts_with("https://localhost"))
.collect();
for ext_url in ext_urls {
if activity_buttons.len() == 2 {
break;
}

if !button.is_dynamic() {
activity_buttons.push(button.clone())
}
activity_buttons.push(Button::new(ext_url.name.clone(), ext_url.url.clone()))
}
return Some(activity_buttons);
}
Expand Down

0 comments on commit 3fff9e5

Please sign in to comment.