From e4a22a1b892f6b3371da344c87eeac4d68f68002 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20K=C3=B6rber?= Date: Wed, 1 Oct 2025 07:55:32 +0200 Subject: [PATCH] mgr: Do not fail locking if spotify is not running --- mgr/src/power.rs | 6 +++++- mgr/src/spotify.rs | 11 ++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/mgr/src/power.rs b/mgr/src/power.rs index 6a6cae1..8f625b6 100644 --- a/mgr/src/power.rs +++ b/mgr/src/power.rs @@ -153,7 +153,11 @@ fn screen_off() -> Result<(), Error> { } fn lock() -> Result { - spotify::pause()?; + match spotify::pause() { + Ok(_) => (), + Err(spotify::Error::NotFound) => (), + Err(e) => return Err(e.into()), + } let lock_handle = cmd::start_command( "i3lock", diff --git a/mgr/src/spotify.rs b/mgr/src/spotify.rs index 8712494..267cb98 100644 --- a/mgr/src/spotify.rs +++ b/mgr/src/spotify.rs @@ -15,6 +15,8 @@ pub enum Error { Cli(#[from] cli::ParseError), #[error(transparent)] Systemd(#[from] systemd::Error), + #[error("spotify does not seem to be running")] + NotFound, } #[derive(Debug, Clone, Copy)] @@ -156,7 +158,14 @@ pub(crate) fn set(status: Status) -> Result<(), Error> { } fn playerctl(cmd: &str) -> Result<(), Error> { - Ok(cmd::command("playerctl", &["-p", "spotify", cmd])?) + if cmd::run_command("playerctl", &["-p", "spotify", cmd])? + .stderr + .contains("No players found") + { + Err(Error::NotFound) + } else { + Ok(()) + } } pub(crate) fn pause() -> Result<(), Error> {