From 2c9470bdd704e1a1b4a92e40576604d374eb0575 Mon Sep 17 00:00:00 2001 From: PixelDoted <34966285+PixelDoted@users.noreply.github.com> Date: Tue, 31 Oct 2023 11:51:38 -0500 Subject: [PATCH] only countdown when there's a confirm popup Co-authored-by: Ashley Wulber <48420062+wash2@users.noreply.github.com> --- cosmic-applet-power/src/main.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cosmic-applet-power/src/main.rs b/cosmic-applet-power/src/main.rs index 7ff802e8..ced654cb 100644 --- a/cosmic-applet-power/src/main.rs +++ b/cosmic-applet-power/src/main.rs @@ -109,18 +109,18 @@ impl cosmic::Application for Power { } fn subscription(&self) -> Subscription { - Subscription::batch(vec![ - events_with(|e, _status| match e { - cosmic::iced::Event::PlatformSpecific(PlatformSpecific::Wayland( - wayland::Event::Layer(LayerEvent::Unfocused, ..), - )) => Some(Message::Cancel), - // cosmic::iced::Event::PlatformSpecific(PlatformSpecific::Wayland( - // wayland::Event::Seat(wayland::SeatEvent::Leave, _), - // )) => Some(Message::Cancel), - _ => None, - }), - time::every(Duration::from_millis(1000)).map(|_| Message::Countdown), - ]) + let mut subscriptions = Vec::with_capacity(2); + subscriptions.push(events_with(|e, _status| match e { + cosmic::iced::Event::PlatformSpecific(PlatformSpecific::Wayland( + wayland::Event::Layer(LayerEvent::Unfocused, ..), + )) => Some(Message::Cancel), + _ => None, + })); + if self.action_to_confirm.is_some() { + subscriptions + .push(time::every(Duration::from_millis(1000)).map(|_| Message::Countdown)); + } + Subscription::batch(subscriptions) } fn update(&mut self, message: Message) -> Command {