big overhaul
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
use mpris::PlayerFinder;
|
||||
use log::trace;
|
||||
use mpris::{PlayerFinder, Metadata, Player};
|
||||
use crate::structs::{data::Data, config::Config};
|
||||
|
||||
fn update_prefix(cfg: &Config, data: &mut char, name: &str) {
|
||||
if let Some(char) = cfg.player_prefixes.get(name) {
|
||||
*data = char.clone();
|
||||
trace!("updated prefix to {}", data);
|
||||
} else {
|
||||
*data = cfg.player_prefixes.get("default").unwrap_or(&'>').clone();
|
||||
trace!("set prefix to default ({})", data);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_players(
|
||||
pf: &PlayerFinder,
|
||||
cfg: &Config,
|
||||
@@ -10,31 +21,30 @@ pub fn update_players(
|
||||
if players.is_empty() {
|
||||
data.current_player = None;
|
||||
} else {
|
||||
let mut active: Vec<(i32, String)> = Vec::new();
|
||||
let mut active: Vec<(i32, Player)> = Vec::new();
|
||||
for player in players {
|
||||
if let Ok(mpris::PlaybackStatus::Playing) = player.get_playback_status() {
|
||||
let name = player.identity();
|
||||
let idx = cfg.find_player_priorities_idx(name);
|
||||
active.push((idx, name.to_owned()));
|
||||
let idx = cfg.find_player_priorities_idx(player.identity());
|
||||
active.push((idx, player));
|
||||
}
|
||||
}
|
||||
|
||||
if !active.is_empty() {
|
||||
data.current_player = Some(get_lowest(&active));
|
||||
let cur = get_lowest(&mut active);
|
||||
update_prefix(cfg, &mut data.display_prefix, cur.identity());
|
||||
data.current_player = Some(cur);
|
||||
} else {
|
||||
data.current_player = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_lowest(v: &Vec<(i32, String)>) -> String {
|
||||
let mut out = String::new();
|
||||
let mut lowest_index = i32::MAX;
|
||||
for (v_id, v_str) in v.iter() {
|
||||
if v_id < &lowest_index {
|
||||
out = v_str.to_owned();
|
||||
fn get_lowest(v: &mut Vec<(i32, Player)>) -> Player {
|
||||
let mut lowest_index = i32::MAX; //FIXME: use options here instead, also fixes a bug
|
||||
for (v_id, _) in v.into_iter() {
|
||||
if v_id < &mut lowest_index {
|
||||
lowest_index = *v_id;
|
||||
}
|
||||
}
|
||||
out
|
||||
v.swap_remove(lowest_index as usize).1
|
||||
}
|
||||
Reference in New Issue
Block a user