Skip to content

Commit

Permalink
Fix crash when username is None
Browse files Browse the repository at this point in the history
  • Loading branch information
Radiicall committed Jul 22, 2024
1 parent 049a711 commit ec47510
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
6 changes: 3 additions & 3 deletions jellyfin-rpc/src/jellyfin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::time::{SystemTime, SystemTimeError, UNIX_EPOCH};
#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
pub struct RawSession {
pub user_name: String,
pub user_name: Option<String>,
pub now_playing_item: Option<NowPlayingItem>,
pub play_state: PlayState,
pub play_state: Option<PlayState>,
}

impl RawSession {
Expand All @@ -22,7 +22,7 @@ impl RawSession {

Session {
now_playing_item: self.now_playing_item.unwrap(),
play_state: self.play_state,
play_state: self.play_state.unwrap(),
item_id: id.to_string(),
}
}
Expand Down
55 changes: 31 additions & 24 deletions jellyfin-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,34 +194,41 @@ impl Client {
debug!("Found {} sessions", sessions.len());

for session in sessions {
debug!("Session username is {}", session.user_name);
if self
.usernames
.iter()
.all(|u| session.user_name.to_lowercase() != *u.to_lowercase())
{
continue;
}
debug!("Session username is {:?}", session.user_name);
if let Some(username) = session.user_name.as_ref() {
if self
.usernames
.iter()
.all(|u| username.to_lowercase() != u.to_lowercase())
{
continue;
}

if session.now_playing_item.is_none() {
continue;
}
debug!("NowPlayingItem exists");
if session.now_playing_item.is_none() {
continue;
}
debug!("NowPlayingItem exists");

let session = session.build();
if session.play_state.is_none() {
continue;
}
debug!("PlayState exists");

if session
.now_playing_item
.extra_type
.as_ref()
.is_some_and(|et| et == "ThemeSong")
{
debug!("Session is playing a theme song, continuing loop");
continue;
}
let session = session.build();

self.session = Some(session);
return Ok(());
if session
.now_playing_item
.extra_type
.as_ref()
.is_some_and(|et| et == "ThemeSong")
{
debug!("Session is playing a theme song, continuing loop");
continue;
}

self.session = Some(session);
return Ok(());
}
}
self.session = None;
Ok(())
Expand Down

0 comments on commit ec47510

Please sign in to comment.