Fix: gracefully handle invalid DBus setups

Some systems may have an ncspot binary with enabled MPRIS/DBus support, even
though DBus is not actually running on the system or the session is broken.

ncspot should not panic in such a situation, but handle gracefully instead.

Should help with #1139
This commit is contained in:
Henrik Friedrichsen
2023-05-02 22:54:47 +02:00
parent cb9d9e7a93
commit 2771c319d6
2 changed files with 11 additions and 4 deletions

View File

@@ -365,7 +365,7 @@ fn main() -> Result<(), String> {
spotify.update_status(state.clone());
#[cfg(feature = "mpris")]
mpris_manager.update()?;
mpris_manager.update();
#[cfg(unix)]
ipc.publish(&state, queue.get_current());

View File

@@ -484,7 +484,12 @@ impl MprisManager {
let (tx, rx) = mpsc::unbounded_channel::<()>();
ASYNC_RUNTIME.spawn(Self::serve(UnboundedReceiverStream::new(rx), root, player));
ASYNC_RUNTIME.spawn(async {
let result = Self::serve(UnboundedReceiverStream::new(rx), root, player).await;
if let Err(e) = result {
log::error!("MPRIS error: {e}");
}
});
MprisManager { tx }
}
@@ -518,7 +523,9 @@ impl MprisManager {
}
}
pub fn update(&self) -> Result<(), String> {
self.tx.send(()).map_err(|e| e.to_string())
pub fn update(&self) {
if let Err(e) = self.tx.send(()) {
log::warn!("Could not update MPRIS state: {e}");
}
}
}