working on refactoring some functions
This commit is contained in:
parent
758108c925
commit
62a81cfaab
|
|
@ -21,16 +21,6 @@ impl Field {
|
|||
}
|
||||
}
|
||||
|
||||
// I shouldn't need this; remove when done with testing FIXME
|
||||
impl Default for Field {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
field: Default::default(),
|
||||
num_chars: Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Rating {
|
||||
pub nil: char,
|
||||
|
|
@ -93,6 +83,14 @@ impl Config {
|
|||
pub fn priorities_to_lower(&mut self) {
|
||||
self.player_priorities = self.player_priorities.iter().map(|i| i.to_lowercase()).collect();
|
||||
}
|
||||
|
||||
pub fn find_player_priorities_idx(&self, name: &str) -> i32 {
|
||||
match self.player_priorities.iter()
|
||||
.position(|x| x.to_ascii_lowercase().eq(&name.to_ascii_lowercase())) {
|
||||
Some(idx) => idx as i32,
|
||||
None => i32::MAX,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn ms(str: &str) -> String {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ fn update_prefix(cfg: &Config, data: &mut Data) {
|
|||
data.display_prefix = char.clone();
|
||||
trace!("updated prefix to {}", data.display_prefix);
|
||||
} else {
|
||||
data.display_prefix = cfg.player_prefixes.get("default").unwrap().clone(); //todo: error handling
|
||||
data.display_prefix = cfg.player_prefixes.get("default").unwrap_or(&'>').clone();
|
||||
trace!("set prefix to default ({})", data.display_prefix);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ pub fn update_players(
|
|||
cfg: &Config,
|
||||
mut data: &mut Data,
|
||||
) {
|
||||
let players = pf.find_all().unwrap(); //todo: error handling
|
||||
let players = pf.find_all().unwrap_or(Vec::new());
|
||||
if players.is_empty() {
|
||||
data.current_player = None;
|
||||
} else {
|
||||
|
|
@ -14,13 +14,14 @@ pub fn update_players(
|
|||
for player in players {
|
||||
if cfg.player_priorities.contains(&player.identity().to_owned().to_ascii_lowercase()) {
|
||||
let name = player.identity();
|
||||
let idx = cfg.player_priorities.iter().position(|x| x.to_ascii_lowercase().eq(&name.to_ascii_lowercase())).unwrap() as i32; //todo: move to function in config; error handling
|
||||
let status = player.get_playback_status().unwrap(); //todo: error handling
|
||||
match status {
|
||||
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())),
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
if !active[0].is_empty() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue