clippy
This commit is contained in:
@@ -475,7 +475,7 @@ impl BackendThread<MediaMessage, Sender<MediaMessage>> for MediaBackend {
|
||||
let instance = instance.clone();
|
||||
move || {
|
||||
while let Ok(sender) = registration_rx.recv() {
|
||||
if let Ok(_) = sender.send(MediaMessage::Init(tx.clone())) {
|
||||
if sender.send(MediaMessage::Init(tx.clone())).is_ok() {
|
||||
let mut instance_guard = instance.lock().unwrap();
|
||||
if let Some(name) = &instance_guard.active_player
|
||||
&& let Some(status) = instance_guard.players.get(name)
|
||||
@@ -517,28 +517,28 @@ impl BackendThread<MediaMessage, Sender<MediaMessage>> for MediaBackend {
|
||||
};
|
||||
while let Ok(msg) = rx.recv() {
|
||||
let mut instance_guard = instance.lock().unwrap();
|
||||
if let Some(name) = &instance_guard.active_player {
|
||||
if let Some(status) = instance_guard.players.get(name) {
|
||||
match msg {
|
||||
MediaMessage::PlayerPlay => {
|
||||
if let PlayerStatus::Paused(_) = status {
|
||||
instance_guard.active_player_play(&connection).await;
|
||||
}
|
||||
if let Some(name) = &instance_guard.active_player
|
||||
&& let Some(status) = instance_guard.players.get(name)
|
||||
{
|
||||
match msg {
|
||||
MediaMessage::PlayerPlay => {
|
||||
if let PlayerStatus::Paused(_) = status {
|
||||
instance_guard.active_player_play(&connection).await;
|
||||
}
|
||||
MediaMessage::PlayerPause => {
|
||||
if let PlayerStatus::Playing(_) = status {
|
||||
instance_guard.active_player_pause(&connection).await;
|
||||
}
|
||||
}
|
||||
MediaMessage::PlayerStop => {
|
||||
if let PlayerStatus::Playing(_) | PlayerStatus::Paused(_) =
|
||||
status
|
||||
{
|
||||
instance_guard.active_player_stop(&connection).await;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
MediaMessage::PlayerPause => {
|
||||
if let PlayerStatus::Playing(_) = status {
|
||||
instance_guard.active_player_pause(&connection).await;
|
||||
}
|
||||
}
|
||||
MediaMessage::PlayerStop => {
|
||||
if let PlayerStatus::Playing(_) | PlayerStatus::Paused(_) =
|
||||
status
|
||||
{
|
||||
instance_guard.active_player_stop(&connection).await;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -575,7 +575,7 @@ impl MediaBackend {
|
||||
.collect();
|
||||
|
||||
for player in players {
|
||||
Self::spawn_new_player_watcher(&connection, &instance, &player);
|
||||
Self::spawn_new_player_watcher(connection, &instance, &player);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -680,11 +680,11 @@ impl MediaBackend {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Some(value) = args.changed_properties().get("PlaybackStatus") {
|
||||
if let Ok(status) = <String>::try_from(value.clone()) {
|
||||
debug!(&LOGGER, "Player ({name}) status has changed to: '{status}'");
|
||||
Self::insert_or_update_player(&instance, &props, name.into(), status).await;
|
||||
}
|
||||
if let Some(value) = args.changed_properties().get("PlaybackStatus")
|
||||
&& let Ok(status) = <String>::try_from(value.clone())
|
||||
{
|
||||
debug!(&LOGGER, "Player ({name}) status has changed to: '{status}'");
|
||||
Self::insert_or_update_player(&instance, &props, name.into(), status).await;
|
||||
}
|
||||
}
|
||||
debug!(&LOGGER, "(2) Removing player: {name}");
|
||||
@@ -699,7 +699,7 @@ impl MediaBackend {
|
||||
player_name: String,
|
||||
player_status: String,
|
||||
) {
|
||||
match Self::get_player_status_from_string(&props, player_status).await {
|
||||
match Self::get_player_status_from_string(props, player_status).await {
|
||||
Ok(status) => {
|
||||
let mut instance_guard = instance.lock().unwrap();
|
||||
instance_guard.players.insert(player_name.clone(), status);
|
||||
@@ -757,57 +757,51 @@ impl MediaBackend {
|
||||
}
|
||||
|
||||
async fn active_player_play(&self, connection: &zbus::Connection) {
|
||||
if let Some(player_name) = &self.active_player {
|
||||
if let Ok(proxy) = zbus::Proxy::new(
|
||||
&connection,
|
||||
if let Some(player_name) = &self.active_player
|
||||
&& let Ok(proxy) = zbus::Proxy::new(
|
||||
connection,
|
||||
player_name.as_str(),
|
||||
MPRIS_PATH,
|
||||
MPRIS_PLAYER_INTERFACE,
|
||||
)
|
||||
.await
|
||||
{
|
||||
if let Err(e) = proxy.call_method("Play", &()).await {
|
||||
warn!(
|
||||
&LOGGER,
|
||||
"Error starting play for player: {player_name}, {e}"
|
||||
);
|
||||
}
|
||||
}
|
||||
&& let Err(e) = proxy.call_method("Play", &()).await
|
||||
{
|
||||
warn!(
|
||||
&LOGGER,
|
||||
"Error starting play for player: {player_name}, {e}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async fn active_player_pause(&mut self, connection: &zbus::Connection) {
|
||||
if let Some(player_name) = &self.active_player {
|
||||
if let Ok(proxy) = zbus::Proxy::new(
|
||||
&connection,
|
||||
if let Some(player_name) = &self.active_player
|
||||
&& let Ok(proxy) = zbus::Proxy::new(
|
||||
connection,
|
||||
player_name.as_str(),
|
||||
MPRIS_PATH,
|
||||
MPRIS_PLAYER_INTERFACE,
|
||||
)
|
||||
.await
|
||||
{
|
||||
if let Err(e) = proxy.call_method("Pause", &()).await {
|
||||
warn!(&LOGGER, "Error pausing player: {player_name}, {e}");
|
||||
}
|
||||
}
|
||||
&& let Err(e) = proxy.call_method("Pause", &()).await
|
||||
{
|
||||
warn!(&LOGGER, "Error pausing player: {player_name}, {e}");
|
||||
self.select_active_player(self.active_player.clone());
|
||||
}
|
||||
}
|
||||
|
||||
async fn active_player_stop(&mut self, connection: &zbus::Connection) {
|
||||
if let Some(player_name) = &self.active_player {
|
||||
if let Ok(proxy) = zbus::Proxy::new(
|
||||
&connection,
|
||||
if let Some(player_name) = &self.active_player
|
||||
&& let Ok(proxy) = zbus::Proxy::new(
|
||||
connection,
|
||||
player_name.as_str(),
|
||||
MPRIS_PATH,
|
||||
MPRIS_PLAYER_INTERFACE,
|
||||
)
|
||||
.await
|
||||
{
|
||||
if let Err(e) = proxy.call_method("Stop", &()).await {
|
||||
warn!(&LOGGER, "Error stopping player: {player_name}, {e}");
|
||||
}
|
||||
}
|
||||
&& let Err(e) = proxy.call_method("Stop", &()).await
|
||||
{
|
||||
warn!(&LOGGER, "Error stopping player: {player_name}, {e}");
|
||||
}
|
||||
self.select_active_player(None);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use jmb_logger_rs::*;
|
||||
use std::io::Read;
|
||||
use std::net::Shutdown;
|
||||
use std::os::unix::net::UnixListener;
|
||||
use std::str::FromStr;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
pub struct ControlSocket {
|
||||
@@ -34,11 +35,11 @@ impl SimpleBackendThread<ControlCommand> for ControlSocket {
|
||||
}
|
||||
});
|
||||
std::thread::spawn(move || {
|
||||
if std::fs::metadata(SOCKET_PATH).is_ok() {
|
||||
if let Err(e) = std::fs::remove_file(SOCKET_PATH) {
|
||||
error!(&LOGGER, "Error deleting old socket file: {e}");
|
||||
return;
|
||||
}
|
||||
if std::fs::metadata(SOCKET_PATH).is_ok()
|
||||
&& let Err(e) = std::fs::remove_file(SOCKET_PATH)
|
||||
{
|
||||
error!(&LOGGER, "Error deleting old socket file: {e}");
|
||||
return;
|
||||
}
|
||||
let socket = UnixListener::bind(SOCKET_PATH);
|
||||
let Ok(socket) = socket else {
|
||||
@@ -58,7 +59,7 @@ impl SimpleBackendThread<ControlCommand> for ControlSocket {
|
||||
let _ = stream.shutdown(Shutdown::Both);
|
||||
continue;
|
||||
}
|
||||
if let Some(command) = ControlCommand::from_str(&read) {
|
||||
if let Ok(command) = ControlCommand::from_str(&read) {
|
||||
instance.lock().unwrap().publish(command);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,11 +97,13 @@ impl I915Engine {
|
||||
let pmu_type = read_number(&format!("{base}/type"))? as u32;
|
||||
let config = read_config(&format!("{base}/events/{name}"))?;
|
||||
|
||||
let mut attr = PerfEventAttr::default();
|
||||
attr.type_ = pmu_type;
|
||||
attr.size = size_of::<PerfEventAttr>() as u32;
|
||||
attr.config = config;
|
||||
attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING;
|
||||
let attr = PerfEventAttr {
|
||||
type_: pmu_type,
|
||||
size: size_of::<PerfEventAttr>() as u32,
|
||||
config,
|
||||
read_format: PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// pid = -1 and cpu = -1: system-wide event, if permitted.
|
||||
let fd = unsafe {
|
||||
@@ -181,7 +183,7 @@ impl I915UtilizationMonitor {
|
||||
for (engine, sample) in &mut self.engines {
|
||||
let new_sample = engine.read().unwrap();
|
||||
if let Some(last) = sample {
|
||||
values.push(new_sample.calculate_utilization(&last) as u8);
|
||||
values.push(new_sample.calculate_utilization(last) as u8);
|
||||
}
|
||||
let _ = sample.insert(new_sample);
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ impl HyprlandComms {
|
||||
.output()
|
||||
}
|
||||
|
||||
pub fn cursor_monitor() -> Option<MonitorId> {
|
||||
pub fn _cursor_monitor() -> Option<MonitorId> {
|
||||
if let Ok(pos) = CursorPosition::get()
|
||||
&& let Ok(monitors) = Monitors::get()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user