From 6875bb38c06e422c511440707fea5563d8b02adf Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 18 Jan 2024 22:13:05 -0500 Subject: [PATCH] fix(notifications): only connect to notifications daemon once --- cosmic-applet-notifications/src/main.rs | 2 +- .../src/subscriptions/notifications.rs | 17 ++++------------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/cosmic-applet-notifications/src/main.rs b/cosmic-applet-notifications/src/main.rs index f4cc61cf..425ebb3c 100644 --- a/cosmic-applet-notifications/src/main.rs +++ b/cosmic-applet-notifications/src/main.rs @@ -5,7 +5,7 @@ use cosmic::applet::token::subscription::{ }; use cosmic::applet::{menu_button, menu_control_padding, padded_control}; use cosmic::cctk::sctk::reexports::calloop; -use cosmic::cosmic_config::{config_subscription, Config, CosmicConfigEntry}; +use cosmic::cosmic_config::{Config, CosmicConfigEntry}; use cosmic::iced::wayland::popup::{destroy_popup, get_popup}; use cosmic::iced::Limits; use cosmic::iced::{ diff --git a/cosmic-applet-notifications/src/subscriptions/notifications.rs b/cosmic-applet-notifications/src/subscriptions/notifications.rs index 09e3f53b..e1d6ecdc 100644 --- a/cosmic-applet-notifications/src/subscriptions/notifications.rs +++ b/cosmic-applet-notifications/src/subscriptions/notifications.rs @@ -17,8 +17,7 @@ use zbus::{ #[derive(Debug)] pub enum State { - Ready, - WaitingForNotificationEvent(NotificationsAppletProxy<'static>, u8), + WaitingForNotificationEvent(u8), Finished, } @@ -29,20 +28,11 @@ pub fn notifications(proxy: NotificationsAppletProxy<'static>) -> Subscription(), 50, |mut output| async move { - let mut state = State::Ready; + let mut state = State::WaitingForNotificationEvent(0); loop { match &mut state { - State::Ready => { - state = match get_proxy().await { - Ok(p) => State::WaitingForNotificationEvent(p, 0), - Err(err) => { - error!("Failed to connect to notifications daemon {}", err); - State::Finished - } - }; - } - State::WaitingForNotificationEvent(proxy, mut fail_count) => { + State::WaitingForNotificationEvent(mut fail_count) => { trace!("Waiting for notification events..."); let mut signal = match proxy.receive_notify().await { Ok(s) => s, @@ -110,6 +100,7 @@ trait NotificationsApplet { pub async fn get_proxy() -> anyhow::Result> { let raw_fd = std::env::var("COSMIC_NOTIFICATIONS")?; let raw_fd = raw_fd.parse::()?; + tracing::info!("Connecting to notifications daemon on fd {}", raw_fd); let stream = unsafe { std::os::unix::net::UnixStream::from_raw_fd(raw_fd) }; stream.set_nonblocking(true)?;