mirror of
https://github.com/figsoda/mmtc
synced 2025-02-16 13:28:33 +00:00
allow detecting player state
This commit is contained in:
parent
fcf106b0e3
commit
99562b90ad
3 changed files with 11 additions and 2 deletions
|
@ -88,12 +88,14 @@ pub enum AddStyle {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
pub enum Condition {
|
||||
Playing,
|
||||
Repeat,
|
||||
Random,
|
||||
Single,
|
||||
Oneshot,
|
||||
Consume,
|
||||
Playing,
|
||||
Paused,
|
||||
Stopped,
|
||||
TitleExist,
|
||||
ArtistExist,
|
||||
AlbumExist,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue