mgr: Do not fail locking if spotify is not running

This commit is contained in:
2025-10-01 07:55:32 +02:00
parent 1c544e8902
commit e4a22a1b89
2 changed files with 15 additions and 2 deletions

View File

@@ -153,7 +153,11 @@ fn screen_off() -> Result<(), Error> {
} }
fn lock() -> Result<cmd::RunningProcess, Error> { fn lock() -> Result<cmd::RunningProcess, Error> {
spotify::pause()?; match spotify::pause() {
Ok(_) => (),
Err(spotify::Error::NotFound) => (),
Err(e) => return Err(e.into()),
}
let lock_handle = cmd::start_command( let lock_handle = cmd::start_command(
"i3lock", "i3lock",

View File

@@ -15,6 +15,8 @@ pub enum Error {
Cli(#[from] cli::ParseError), Cli(#[from] cli::ParseError),
#[error(transparent)] #[error(transparent)]
Systemd(#[from] systemd::Error), Systemd(#[from] systemd::Error),
#[error("spotify does not seem to be running")]
NotFound,
} }
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
@@ -156,7 +158,14 @@ pub(crate) fn set(status: Status) -> Result<(), Error> {
} }
fn playerctl(cmd: &str) -> 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> { pub(crate) fn pause() -> Result<(), Error> {