Warn when no active mpris player is found

previously would panic
This commit is contained in:
GHOSCHT 2024-03-14 11:20:26 +01:00
parent 2f325db170
commit a4e63ae51a
Signed by: ghoscht
GPG key ID: 2C2C1C62A5388E82

View file

@ -1,3 +1,4 @@
use log::warn;
use mpris::Player; use mpris::Player;
use mpris::PlayerFinder; use mpris::PlayerFinder;
use regex::Regex; use regex::Regex;
@ -36,10 +37,15 @@ where
{ {
let player = PlayerFinder::new() let player = PlayerFinder::new()
.expect("Could not connect to D-Bus") .expect("Could not connect to D-Bus")
.find_active() .find_active();
.expect("Could not find any player"); match player {
Ok(p) => {
function(&player); function(&p);
}
Err(err) => {
warn!("Could not find an active player: {err}");
}
}
} }
fn exec_functionality<F>(player_id: Option<&str>, exec_closure: F) fn exec_functionality<F>(player_id: Option<&str>, exec_closure: F)