Skip to content

Commit 16d0a0c

Browse files
committed
More refactors for perf
1 parent 822fb7f commit 16d0a0c

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

cosmic-applet-audio/src/lib.rs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,11 @@ impl cosmic::Application for Audio {
490490
match msg {
491491
// This is where we match messages from the subscription to app state
492492
pulse::Message::SetSinks(sinks) => self.outputs = sinks,
493-
pulse::Message::SetSources(sources) => {
494-
self.inputs = sources
495-
.into_iter()
496-
.filter(|source| {
497-
!source.name.as_ref().is_some_and(|n| n.contains("monitor"))
498-
})
499-
.collect()
493+
pulse::Message::SetSources(mut sources) => {
494+
sources.retain(|source| {
495+
!source.name.as_ref().is_some_and(|n| n.contains("monitor"))
496+
});
497+
self.inputs = sources;
500498
}
501499
pulse::Message::SetDefaultSink(sink) => {
502500
self.update_output(Some(sink));
@@ -824,13 +822,7 @@ impl cosmic::Application for Audio {
824822
Some(output) => pretty_name(output.description.clone()),
825823
None => String::from("No device selected"),
826824
},
827-
self.outputs
828-
.iter()
829-
.map(|output| (
830-
output.name.clone().unwrap_or_default(),
831-
pretty_name(output.description.clone())
832-
))
833-
.collect(),
825+
self.outputs.as_slice(),
834826
Message::OutputToggle,
835827
Message::OutputChanged,
836828
),
@@ -841,13 +833,7 @@ impl cosmic::Application for Audio {
841833
Some(input) => pretty_name(input.description.clone()),
842834
None => fl!("no-device"),
843835
},
844-
self.inputs
845-
.iter()
846-
.map(|input| (
847-
input.name.clone().unwrap_or_default(),
848-
pretty_name(input.description.clone())
849-
))
850-
.collect(),
836+
self.inputs.as_slice(),
851837
Message::InputToggle,
852838
Message::InputChanged,
853839
)
@@ -975,17 +961,23 @@ fn revealer(
975961
open: bool,
976962
title: String,
977963
selected: String,
978-
options: Vec<(String, String)>,
964+
device_info: &[DeviceInfo],
979965
toggle: Message,
980966
mut change: impl FnMut(String) -> Message + 'static,
981967
) -> widget::Column<'static, Message, crate::Theme, Renderer> {
982968
if open {
983-
options.iter().fold(
969+
let options = device_info.iter().map(|device| {
970+
(
971+
device.name.clone().unwrap_or_default(),
972+
pretty_name(device.description.clone()),
973+
)
974+
});
975+
options.fold(
984976
column![revealer_head(open, title, selected, toggle)].width(Length::Fill),
985977
|col, (id, name)| {
986978
col.push(
987-
menu_button(text::body(name.clone()))
988-
.on_press(change(id.clone()))
979+
menu_button(text::body(name))
980+
.on_press(change(id))
989981
.width(Length::Fill)
990982
.padding([8, 48]),
991983
)

cosmic-applet-notifications/src/subscriptions/notifications.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub fn notifications(proxy: NotificationsAppletProxy<'static>) -> Subscription<O
8080
cosmic::iced::futures::select! {
8181
v = next_signal => {
8282
if let Some(msg) = v {
83-
let Some(args) = msg.args().into_iter().next() else {
83+
let Ok(args) = msg.args() else {
8484
break;
8585
};
8686
let notification = Notification::new(

0 commit comments

Comments
 (0)