From a4e63ae51ad92939adc09fae32a0b97c80f6a60e Mon Sep 17 00:00:00 2001 From: GHOSCHT <31184695+GHOSCHT@users.noreply.github.com> Date: Thu, 14 Mar 2024 11:20:26 +0100 Subject: [PATCH] Warn when no active mpris player is found previously would panic --- src/mpris_client.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/mpris_client.rs b/src/mpris_client.rs index 0f122af..08d090b 100644 --- a/src/mpris_client.rs +++ b/src/mpris_client.rs @@ -1,3 +1,4 @@ +use log::warn; use mpris::Player; use mpris::PlayerFinder; use regex::Regex; @@ -36,10 +37,15 @@ where { let player = PlayerFinder::new() .expect("Could not connect to D-Bus") - .find_active() - .expect("Could not find any player"); - - function(&player); + .find_active(); + match player { + Ok(p) => { + function(&p); + } + Err(err) => { + warn!("Could not find an active player: {err}"); + } + } } fn exec_functionality(player_id: Option<&str>, exec_closure: F)