allow detecting player state

This commit is contained in:
figsoda 2020-11-01 15:23:31 -05:00
parent fcf106b0e3
commit 99562b90ad
3 changed files with 11 additions and 2 deletions

View file

@ -88,12 +88,14 @@ pub enum AddStyle {
#[derive(Deserialize)]
pub enum Condition {
Playing,
Repeat,
Random,
Single,
Oneshot,
Consume,
Playing,
Paused,
Stopped,
TitleExist,
ArtistExist,
AlbumExist,

View file

@ -445,12 +445,14 @@ fn eval_cond(
selected: bool,
) -> bool {
match cond {
Condition::Playing => current_track.is_some(),
Condition::Repeat => status.repeat,
Condition::Random => status.random,
Condition::Single => status.single == Some(true),
Condition::Oneshot => status.single == None,
Condition::Consume => status.consume,
Condition::Playing => status.state == Some(true),
Condition::Paused => status.state == Some(false),
Condition::Stopped => status.state == None,
Condition::TitleExist => matches!(current_track, Some(Track { title: Some(_), .. })),
Condition::ArtistExist => matches!(
current_track,

View file

@ -17,6 +17,7 @@ pub struct Status {
pub random: bool,
pub single: Option<bool>, // None: oneshot
pub consume: bool,
pub state: Option<bool>, // Some(true): play, Some(false): pause, None: stop
pub song: Option<Song>,
}
@ -139,6 +140,7 @@ pub async fn status(cl: &mut Client) -> Result<Status> {
let mut random = None;
let mut single = None;
let mut consume = None;
let mut state = None;
let mut pos = None;
let mut elapsed = None;
@ -157,6 +159,8 @@ pub async fn status(cl: &mut Client) -> Result<Status> {
b"single: oneshot" => single = Some(None),
b"consume: 0" => consume = Some(false),
b"consume: 1" => consume = Some(true),
b"state: play" => state = Some(true),
b"state: pause" => state = Some(false),
expand!([@b"song: ", xs @ ..]) => {
pos = Some(String::from_utf8_lossy(xs).parse()?);
}
@ -175,6 +179,7 @@ pub async fn status(cl: &mut Client) -> Result<Status> {
random,
single,
consume,
state,
song: if let (Some(pos), Some(elapsed)) = (pos, elapsed) {
Some(Song { pos, elapsed })
} else {