changes to update_message
This commit is contained in:
parent
9874686595
commit
3be9b6ccea
|
|
@ -46,8 +46,9 @@ fn value_to_string(v: &MetadataValue, sep: char) -> String {
|
|||
fn rating_to_string(r: Option<&MetadataValue>, map: &Rating) -> Option<String> {
|
||||
match r {
|
||||
Some(rating) => {
|
||||
let f = (rating.as_f64().unwrap() * 10_f64).round() as i64;
|
||||
match f { //todo: refactor
|
||||
if let Some(f) = rating.as_f64() {
|
||||
let i = (f * 10_f64.round()) as i64;
|
||||
match i {
|
||||
0 => Some(Rating::repeat(map.nil, 5)),
|
||||
1 => Some(format!("{}{}", Rating::repeat(map.half, 1), Rating::repeat(map.nil, 4))),
|
||||
2 => Some(format!("{}{}", Rating::repeat(map.full, 1), Rating::repeat(map.nil, 4))),
|
||||
|
|
@ -61,10 +62,12 @@ fn rating_to_string(r: Option<&MetadataValue>, map: &Rating) -> Option<String> {
|
|||
10.. => Some(Rating::repeat(map.full, 5)),
|
||||
_ => Some(format!("Invalid rating!"))
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
None => {
|
||||
None
|
||||
// Rating::repeat(map.nil, 5)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,35 +10,22 @@ pub fn update_players(
|
|||
if players.is_empty() {
|
||||
data.current_player = None;
|
||||
} else {
|
||||
let mut active: Vec<Vec<(i32, String)>> = vec![Vec::new(), Vec::new(), Vec::new()];
|
||||
let mut active: Vec<(i32, String)> = Vec::new();
|
||||
for player in players {
|
||||
if cfg.player_priorities.contains(&player.identity().to_owned().to_ascii_lowercase()) {
|
||||
if let Ok(mpris::PlaybackStatus::Playing) = player.get_playback_status() {
|
||||
let name = player.identity();
|
||||
let idx = cfg.find_player_priorities_idx(name);
|
||||
if let Ok(status) = player.get_playback_status() {
|
||||
match status {
|
||||
mpris::PlaybackStatus::Playing => active[0].push((idx, name.to_owned())),
|
||||
mpris::PlaybackStatus::Paused => active[1].push((idx, name.to_owned())),
|
||||
mpris::PlaybackStatus::Stopped => active[2].push((idx, name.to_owned())),
|
||||
};
|
||||
active.push((idx, name.to_owned()));
|
||||
}
|
||||
}
|
||||
}
|
||||
if !active[0].is_empty() {
|
||||
data.current_player = Some(get_lowest(&active[0]));
|
||||
} else if !active[1].is_empty() {
|
||||
data.current_player = Some(get_lowest(&active[1]));
|
||||
} else if !active[2].is_empty() {
|
||||
data.current_player = Some(get_lowest(&active[2]));
|
||||
} else {
|
||||
if let Ok(player) = pf.find_active() {
|
||||
data.current_player = Some(player.identity().to_owned());
|
||||
|
||||
if !active.is_empty() {
|
||||
data.current_player = Some(get_lowest(&active));
|
||||
} else {
|
||||
data.current_player = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_lowest(v: &Vec<(i32, String)>) -> String {
|
||||
let mut out = String::new();
|
||||
|
|
|
|||
Loading…
Reference in New Issue