audio: Fix clippy lints
This commit is contained in:
parent
5c16665b7b
commit
b9a2655210
2 changed files with 46 additions and 39 deletions
|
|
@ -22,7 +22,7 @@ use iced::Color;
|
|||
|
||||
mod pulse;
|
||||
use crate::pulse::DeviceInfo;
|
||||
use libpulse_binding::volume::{Volume, VolumeLinear};
|
||||
use libpulse_binding::volume::VolumeLinear;
|
||||
|
||||
pub fn main() -> cosmic::iced::Result {
|
||||
let helper = CosmicAppletHelper::default();
|
||||
|
|
@ -134,7 +134,7 @@ impl Application for Audio {
|
|||
if let Some(device) = &self.current_output {
|
||||
if let Some(name) = &device.name {
|
||||
connection.send(pulse::Message::SetSinkVolumeByName(
|
||||
name.clone().to_string(),
|
||||
name.clone(),
|
||||
device.volume,
|
||||
))
|
||||
}
|
||||
|
|
@ -151,7 +151,7 @@ impl Application for Audio {
|
|||
if let Some(name) = &device.name {
|
||||
println!("increasing volume of {}", name);
|
||||
connection.send(pulse::Message::SetSourceVolumeByName(
|
||||
name.clone().to_string(),
|
||||
name.clone(),
|
||||
device.volume,
|
||||
))
|
||||
}
|
||||
|
|
@ -241,28 +241,40 @@ impl Application for Audio {
|
|||
self.current_output
|
||||
.as_ref()
|
||||
.map(|o| o.volume.avg())
|
||||
.unwrap_or(Volume::default()),
|
||||
.unwrap_or_default(),
|
||||
)
|
||||
.0 * 100.0;
|
||||
let in_f64 = VolumeLinear::from(
|
||||
self.current_input
|
||||
.as_ref()
|
||||
.map(|o| o.volume.avg())
|
||||
.unwrap_or(Volume::default()),
|
||||
.unwrap_or_default(),
|
||||
)
|
||||
.0 * 100.0;
|
||||
|
||||
let sink = row![
|
||||
icon("audio-volume-high-symbolic", 64).width(Length::Units(24)).height(Length::Units(24)).style(Svg::SymbolicActive),
|
||||
slider(0.0..=100.0, out_f64, Message::SetOutputVolume).width(Length::FillPortion(5)),
|
||||
text(format!("{}%", out_f64.round())).width(Length::FillPortion(1)).horizontal_alignment(Horizontal::Right)
|
||||
icon("audio-volume-high-symbolic", 64)
|
||||
.width(Length::Units(24))
|
||||
.height(Length::Units(24))
|
||||
.style(Svg::SymbolicActive),
|
||||
slider(0.0..=100.0, out_f64, Message::SetOutputVolume)
|
||||
.width(Length::FillPortion(5)),
|
||||
text(format!("{}%", out_f64.round()))
|
||||
.width(Length::FillPortion(1))
|
||||
.horizontal_alignment(Horizontal::Right)
|
||||
]
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center);
|
||||
let source = row![
|
||||
icon("audio-input-microphone-symbolic", 64).width(Length::Units(24)).height(Length::Units(24)).style(Svg::SymbolicActive),
|
||||
slider(0.0..=100.0, in_f64, Message::SetInputVolume).width(Length::FillPortion(5)),
|
||||
text(format!("{}%", in_f64.round())).width(Length::FillPortion(1)).horizontal_alignment(Horizontal::Right)
|
||||
icon("audio-input-microphone-symbolic", 64)
|
||||
.width(Length::Units(24))
|
||||
.height(Length::Units(24))
|
||||
.style(Svg::SymbolicActive),
|
||||
slider(0.0..=100.0, in_f64, Message::SetInputVolume)
|
||||
.width(Length::FillPortion(5)),
|
||||
text(format!("{}%", in_f64.round()))
|
||||
.width(Length::FillPortion(1))
|
||||
.horizontal_alignment(Horizontal::Right)
|
||||
]
|
||||
.spacing(10)
|
||||
.align_items(Alignment::Center);
|
||||
|
|
@ -322,14 +334,14 @@ fn spacer() -> iced::widget::Space {
|
|||
Space::with_width(Length::Fill)
|
||||
}
|
||||
|
||||
fn revealer<'a>(
|
||||
fn revealer(
|
||||
open: bool,
|
||||
title: &'a str,
|
||||
title: &str,
|
||||
selected: String,
|
||||
options: Vec<String>,
|
||||
toggle: Message,
|
||||
_change: Message,
|
||||
) -> widget::Column<'a, Message, Renderer> {
|
||||
) -> widget::Column<Message, Renderer> {
|
||||
if open {
|
||||
options.iter().fold(
|
||||
column![revealer_head(open, title, selected, toggle)].width(Length::Fill),
|
||||
|
|
@ -340,9 +352,9 @@ fn revealer<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
fn revealer_head<'a>(
|
||||
fn revealer_head(
|
||||
_open: bool,
|
||||
title: &'a str,
|
||||
title: &str,
|
||||
selected: String,
|
||||
toggle: Message,
|
||||
) -> widget::Button<Message, Renderer> {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ use libpulse_binding::{
|
|||
callbacks::ListResult,
|
||||
context::{
|
||||
introspect::{Introspector, SinkInfo, SourceInfo},
|
||||
subscribe::{Facility, InterestMaskSet, Operation},
|
||||
Context,
|
||||
},
|
||||
error::PAErr,
|
||||
|
|
@ -80,8 +79,7 @@ pub struct Connection(tokio::sync::mpsc::Sender<Message>);
|
|||
|
||||
impl Connection {
|
||||
pub fn send(&mut self, message: Message) {
|
||||
let _ = self
|
||||
.0
|
||||
self.0
|
||||
.try_send(message)
|
||||
.expect("Send message to PulseAudio server");
|
||||
}
|
||||
|
|
@ -198,7 +196,7 @@ impl PulseHandle {
|
|||
}
|
||||
|
||||
fn blocking_send_disconnected(sender: &mut tokio::sync::mpsc::Sender<Message>) {
|
||||
sender.blocking_send(Message::Disconnected);
|
||||
sender.blocking_send(Message::Disconnected).unwrap()
|
||||
}
|
||||
|
||||
fn blocking_send_connected(sender: &mut tokio::sync::mpsc::Sender<Message>) {
|
||||
|
|
@ -209,6 +207,7 @@ impl PulseHandle {
|
|||
sender.send(Message::Disconnected).await.unwrap()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
async fn send_connected(sender: &mut tokio::sync::mpsc::Sender<Message>) {
|
||||
sender.send(Message::Connected).await.unwrap()
|
||||
}
|
||||
|
|
@ -258,7 +257,7 @@ impl PulseServer {
|
|||
context
|
||||
.borrow_mut()
|
||||
.connect(None, pulse::context::FlagSet::NOFLAGS, None)
|
||||
.map_err(|e| PulseServerError::PAErr(e))?;
|
||||
.map_err(PulseServerError::PAErr)?;
|
||||
|
||||
Ok(PulseServer {
|
||||
mainloop,
|
||||
|
|
@ -308,13 +307,11 @@ impl PulseServer {
|
|||
}
|
||||
},
|
||||
);
|
||||
self.wait_for_result(operation)
|
||||
.and_then(|_| {
|
||||
list.borrow_mut().take().ok_or(PulseServerError::Misc(
|
||||
"get_sinks(): failed to wait for operation",
|
||||
))
|
||||
})
|
||||
.and_then(|result| Ok(result))
|
||||
self.wait_for_result(operation).and_then(|_| {
|
||||
list.borrow_mut().take().ok_or(PulseServerError::Misc(
|
||||
"get_sinks(): failed to wait for operation",
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
// Get a list of input devices
|
||||
|
|
@ -329,13 +326,11 @@ impl PulseServer {
|
|||
}
|
||||
},
|
||||
);
|
||||
self.wait_for_result(operation)
|
||||
.and_then(|_| {
|
||||
list.borrow_mut().take().ok_or(PulseServerError::Misc(
|
||||
"get_sources(): Failed to wait for operation",
|
||||
))
|
||||
})
|
||||
.and_then(|result| Ok(result))
|
||||
self.wait_for_result(operation).and_then(|_| {
|
||||
list.borrow_mut().take().ok_or(PulseServerError::Misc(
|
||||
"get_sources(): Failed to wait for operation",
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_server_info(&mut self) -> Result<ServerInfo, PulseServerError> {
|
||||
|
|
@ -355,7 +350,7 @@ impl PulseServer {
|
|||
let server_info = self.get_server_info();
|
||||
match server_info {
|
||||
Ok(info) => {
|
||||
let name = &info.default_sink_name.unwrap_or(String::new());
|
||||
let name = &info.default_sink_name.unwrap_or_default();
|
||||
let device = Rc::new(RefCell::new(Some(None)));
|
||||
let dev_ref = device.clone();
|
||||
let op = self.introspector.get_sink_info_by_name(
|
||||
|
|
@ -368,7 +363,7 @@ impl PulseServer {
|
|||
);
|
||||
self.wait_for_result(op)?;
|
||||
let mut result = device.borrow_mut();
|
||||
result.take().unwrap().ok_or_else(|| {
|
||||
result.take().unwrap().ok_or({
|
||||
PulseServerError::Misc("get_default_sink(): Error getting requested device")
|
||||
})
|
||||
}
|
||||
|
|
@ -380,7 +375,7 @@ impl PulseServer {
|
|||
let server_info = self.get_server_info();
|
||||
match server_info {
|
||||
Ok(info) => {
|
||||
let name = &info.default_source_name.unwrap_or(String::new());
|
||||
let name = &info.default_source_name.unwrap_or_default();
|
||||
let device = Rc::new(RefCell::new(Some(None)));
|
||||
let dev_ref = device.clone();
|
||||
let op = self.introspector.get_source_info_by_name(
|
||||
|
|
@ -393,7 +388,7 @@ impl PulseServer {
|
|||
);
|
||||
self.wait_for_result(op)?;
|
||||
let mut result = device.borrow_mut();
|
||||
result.take().unwrap().ok_or_else(|| {
|
||||
result.take().unwrap().ok_or({
|
||||
PulseServerError::Misc("get_default_source(): Error getting requested device")
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue