Skip to content

Commit

Permalink
Shuffle setter.
Browse files Browse the repository at this point in the history
  • Loading branch information
juszczukd authored and slondr committed Mar 22, 2023
1 parent 5eca014 commit c5b4f9c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/dbus_mpris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,9 @@ async fn create_dbus_server(
Ok("Stopped".to_string())
});

let mv_device_name = device_name.clone();
let sp_client = Arc::clone(&spotify_api_client);
let sp_client2 = Arc::clone(&spotify_api_client);
b.property("Shuffle")
.emits_changed_false()
.get(move |_, _| {
Expand All @@ -421,6 +423,23 @@ async fn create_dbus_server(
.flatten()
.map_or(false, |p| p.shuffle_state);
Ok(shuffle_status)
})
.set(move |_, _, value| {
let device_id = get_device_id(&sp_client2, &mv_device_name, true);
if let Some(device_id) = device_id {
match sp_client2.shuffle(value, Some(&device_id)) {
Ok(_) => Ok(None),
Err(err) => {
let e = format!("SetShuffle failed: {}", err);
error!("{}", e);
Err(MethodErr::failed(&e))
}
}
} else {
let msg = format!("Could not find device with name {}", mv_device_name);
warn!("SetShuffle: {}", msg);
Err(MethodErr::failed(&msg))
}
});

b.property("Rate").emits_changed_const().get(|_, _| Ok(1.0));
Expand Down

0 comments on commit c5b4f9c

Please sign in to comment.