Skip to content

Commit

Permalink
clippy: fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
eladyn committed Dec 27, 2024
1 parent 0977bd8 commit 1e90c8d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub enum Backend {
}

fn default_backend() -> Backend {
return Backend::from_str(BACKEND_VALUES.first().unwrap()).unwrap();
Backend::from_str(BACKEND_VALUES.first().unwrap()).unwrap()
}

impl FromStr for Backend {
Expand Down
29 changes: 17 additions & 12 deletions src/dbus_mpris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ use std::convert::TryFrom;
use std::{
collections::HashMap,
pin::Pin,
sync::{Arc, Mutex, RwLock},
sync::{Arc, RwLock},
};
use thiserror::Error;
use time::format_description::well_known::Iso8601;
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
use tokio::sync::{
mpsc::{UnboundedReceiver, UnboundedSender},
Mutex,
};

type DbusMap = HashMap<String, Variant<Box<dyn RefArg>>>;

const MPRIS_PATH: &'static str = "/org/mpris/MediaPlayer2";
const CONTROLS_PATH: &'static str = "/rs/spotifyd/Controls";
const MPRIS_PATH: &str = "/org/mpris/MediaPlayer2";
const CONTROLS_PATH: &str = "/rs/spotifyd/Controls";

pub enum ControlMessage {
SetSpirc(Arc<Spirc>),
Expand Down Expand Up @@ -97,7 +100,7 @@ enum PlaybackStatus {
}

impl PlaybackStatus {
fn to_mpris(&self) -> &'static str {
fn to_mpris(self) -> &'static str {
match self {
PlaybackStatus::Playing => "Playing",
PlaybackStatus::Paused => "Paused",
Expand Down Expand Up @@ -137,7 +140,7 @@ enum RepeatState {
}

impl RepeatState {
fn to_mpris(&self) -> &'static str {
fn to_mpris(self) -> &'static str {
match self {
RepeatState::None => "None",
// RepeatState::Track => "Track",
Expand Down Expand Up @@ -427,8 +430,10 @@ async fn create_dbus_server(
conn.start_receive(
MatchRule::new_method_call(),
Box::new(move |msg, conn| {
let mut cr = cr.lock().unwrap();
cr.handle_message(msg, conn).unwrap();
tokio::task::block_in_place(|| {
let mut cr = cr.blocking_lock();
cr.handle_message(msg, conn).unwrap();
});
true
}),
);
Expand All @@ -449,7 +454,7 @@ async fn create_dbus_server(
let event = event.expect("event channel was unexpectedly closed");

if let PlayerEvent::SessionConnected { connection_id, .. } = event {
let mut cr = crossroads.lock().unwrap();
let mut cr = crossroads.lock().await;
let spirc = spirc.clone().unwrap();
register_player_interface(&mut cr, spirc, current_state.clone(), quit_tx.clone());
if cur_conn_id.is_none() {
Expand All @@ -459,7 +464,7 @@ async fn create_dbus_server(
} else if let PlayerEvent::SessionDisconnected { connection_id, .. } = event {
// if this message isn't outdated yet, we vanish from the bus
if cur_conn_id == Some(connection_id) {
let mut cr = crossroads.lock().unwrap();
let mut cr = crossroads.lock().await;
conn.release_name(&mpris_name).await?;
cr.remove::<()>(&MPRIS_PATH.into());
cur_conn_id = None;
Expand Down Expand Up @@ -509,12 +514,12 @@ async fn create_dbus_server(
break;
},
ControlMessage::SetSpirc(new_spirc) => {
let mut cr = crossroads.lock().unwrap();
let mut cr = crossroads.lock().await;
register_controls_interface(&mut cr, new_spirc.clone());
spirc = Some(new_spirc);
}
ControlMessage::DropSpirc => {
let mut cr = crossroads.lock().unwrap();
let mut cr = crossroads.lock().await;
conn.release_name(&mpris_name).await?;
cr.remove::<()>(&MPRIS_PATH.into());
cr.remove::<()>(&CONTROLS_PATH.into());
Expand Down

0 comments on commit 1e90c8d

Please sign in to comment.