Skip to content

Commit 867f537

Browse files
committed
chore(mpris): alias zbus::fdo::{Error, Result} for readability
1 parent 90e64b2 commit 867f537

1 file changed

Lines changed: 22 additions & 33 deletions

File tree

src/mpris_event_handler.rs

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use log::{debug, info, warn};
55
use thiserror::Error;
66
use time::format_description::well_known::Iso8601;
77
use tokio::sync::mpsc;
8-
use zbus::connection;
8+
use zbus::{connection, fdo};
99

1010
use librespot::{
1111
core::date::Date,
@@ -636,16 +636,14 @@ impl MprisPlayerService {
636636
// Calling Play after this should cause playback to start again from the same position.
637637
//
638638
// If `self.can_pause` is `false`, attempting to call this method should have no effect.
639-
async fn pause(&self) -> zbus::fdo::Result<()> {
639+
async fn pause(&self) -> fdo::Result<()> {
640640
debug!("org.mpris.MediaPlayer2.Player::Pause");
641641
match (&self.spirc, &self.metadata.mpris.track_id) {
642642
(Some(spirc), Some(_)) => spirc
643643
.pause()
644-
.map_err(|err| zbus::fdo::Error::Failed(format!("{err}"))),
645-
(Some(_), None) => {
646-
zbus::fdo::Result::Err(zbus::fdo::Error::Failed(String::from("No track")))
647-
}
648-
_ => zbus::fdo::Result::Err(zbus::fdo::Error::Failed(String::from("Can't play/pause"))),
644+
.map_err(|err| fdo::Error::Failed(format!("{err}"))),
645+
(Some(_), None) => fdo::Result::Err(fdo::Error::Failed(String::from("No track"))),
646+
_ => fdo::Result::Err(fdo::Error::Failed(String::from("Can't play/pause"))),
649647
}
650648
}
651649

@@ -657,16 +655,14 @@ impl MprisPlayerService {
657655
//
658656
// If `self.can_pause` is `false`, attempting to call this method should have no effect and
659657
// raise an error.
660-
async fn play_pause(&self) -> zbus::fdo::Result<()> {
658+
async fn play_pause(&self) -> fdo::Result<()> {
661659
debug!("org.mpris.MediaPlayer2.Player::PlayPause");
662660
match (&self.spirc, &self.metadata.mpris.track_id) {
663661
(Some(spirc), Some(_)) => spirc
664662
.play_pause()
665-
.map_err(|err| zbus::fdo::Error::Failed(format!("{err}"))),
666-
(Some(_), None) => {
667-
zbus::fdo::Result::Err(zbus::fdo::Error::Failed(String::from("No track")))
668-
}
669-
_ => zbus::fdo::Result::Err(zbus::fdo::Error::Failed(String::from("Can't play/pause"))),
663+
.map_err(|err| fdo::Error::Failed(format!("{err}"))),
664+
(Some(_), None) => fdo::Result::Err(fdo::Error::Failed(String::from("No track"))),
665+
_ => fdo::Result::Err(fdo::Error::Failed(String::from("Can't play/pause"))),
670666
}
671667
}
672668

@@ -696,7 +692,7 @@ impl MprisPlayerService {
696692
// If there is no track to play, this has no effect.
697693
//
698694
// If `self.can_play` is `false`, attempting to call this method should have no effect.
699-
async fn play(&self) -> zbus::fdo::Result<()> {
695+
async fn play(&self) -> fdo::Result<()> {
700696
debug!("org.mpris.MediaPlayer2.Player::Play");
701697
if let Some(spirc) = &self.spirc {
702698
let _ = spirc.activate();
@@ -708,12 +704,10 @@ impl MprisPlayerService {
708704
spirc.activate()?;
709705
spirc.play()
710706
})();
711-
result.map_err(|err| zbus::fdo::Error::Failed(format!("{err}")))
712-
}
713-
(Some(_), None) => {
714-
zbus::fdo::Result::Err(zbus::fdo::Error::Failed(String::from("No track")))
707+
result.map_err(|err| fdo::Error::Failed(format!("{err}")))
715708
}
716-
_ => zbus::fdo::Result::Err(zbus::fdo::Error::Failed(String::from("Can't play/pause"))),
709+
(Some(_), None) => fdo::Result::Err(fdo::Error::Failed(String::from("No track"))),
710+
_ => fdo::Result::Err(fdo::Error::Failed(String::from("Can't play/pause"))),
717711
}
718712
}
719713

@@ -800,11 +794,9 @@ impl MprisPlayerService {
800794
// * `uri`: Uri of the track to load. Its uri scheme should be an element of the
801795
// `org.mpris.MediaPlayer2.SupportedUriSchemes` property and the mime-type should
802796
// match one of the elements of the `org.mpris.MediaPlayer2.SupportedMimeTypes`.
803-
async fn open_uri(&self, uri: &str) -> zbus::fdo::Result<()> {
797+
async fn open_uri(&self, uri: &str) -> fdo::Result<()> {
804798
debug!("org.mpris.MediaPlayer2.Player::OpenUri({uri:?})");
805-
Err(zbus::fdo::Error::NotSupported(
806-
"OpenUri not supported".to_owned(),
807-
))
799+
Err(fdo::Error::NotSupported("OpenUri not supported".to_owned()))
808800
}
809801

810802
// The current playback status.
@@ -833,7 +825,7 @@ impl MprisPlayerService {
833825
}
834826

835827
#[zbus(property)]
836-
async fn set_loop_status(&mut self, value: LoopStatus) -> zbus::fdo::Result<()> {
828+
async fn set_loop_status(&mut self, value: LoopStatus) -> fdo::Result<()> {
837829
debug!("org.mpris.MediaPlayer2.Player::LoopStatus({value:?})");
838830
match value {
839831
LoopStatus::None => {
@@ -919,12 +911,9 @@ impl MprisPlayerService {
919911
#[zbus(property(emits_changed_signal = "true"))]
920912
async fn metadata(
921913
&self,
922-
) -> zbus::fdo::Result<std::collections::HashMap<String, zbus::zvariant::OwnedValue>> {
914+
) -> fdo::Result<std::collections::HashMap<String, zbus::zvariant::OwnedValue>> {
923915
debug!("org.mpris.MediaPlayer2.Player::Metadata");
924-
self.metadata
925-
.clone()
926-
.try_into()
927-
.map_err(zbus::fdo::Error::ZBus)
916+
self.metadata.clone().try_into().map_err(fdo::Error::ZBus)
928917
}
929918

930919
// The volume level.
@@ -940,7 +929,7 @@ impl MprisPlayerService {
940929
}
941930

942931
#[zbus(property)]
943-
async fn set_volume(&mut self, value: Volume) -> zbus::fdo::Result<()> {
932+
async fn set_volume(&mut self, value: Volume) -> fdo::Result<()> {
944933
debug!("org.mpris.MediaPlayer2.Player::Volume({value})");
945934
if let Some(spirc) = &self.spirc {
946935
// As of rust 1.45, cast is guaranteed to round to 0 and saturate.
@@ -949,7 +938,7 @@ impl MprisPlayerService {
949938
let mapped_volume = (value * (u16::MAX as f64)).round() as u16;
950939
spirc
951940
.set_volume(mapped_volume)
952-
.map_err(|err| zbus::fdo::Error::Failed(format!("{err}")))?;
941+
.map_err(|err| fdo::Error::Failed(format!("{err}")))?;
953942
}
954943
Ok(())
955944
}
@@ -964,7 +953,7 @@ impl MprisPlayerService {
964953
// If the playback progresses in a way that is inconstistant with the `Rate` property, the
965954
// `Seeked` signal is emited.
966955
#[zbus(property(emits_changed_signal = "false"))]
967-
async fn position(&self) -> zbus::fdo::Result<TimeInUs> {
956+
async fn position(&self) -> fdo::Result<TimeInUs> {
968957
debug!("org.mpris.MediaPlayer2.Player::Position");
969958

970959
self.position
@@ -974,7 +963,7 @@ impl MprisPlayerService {
974963
.saturating_add(position.last_update.elapsed().as_millis());
975964
corrected as i64 * 1000
976965
})
977-
.ok_or(zbus::fdo::Error::Failed(String::from("Got no position")))
966+
.ok_or(fdo::Error::Failed(String::from("Got no position")))
978967
}
979968

980969
// The minimum value which the `Rate` property can take. Clients should not attempt to set the

0 commit comments

Comments
 (0)