fix(notifications): only connect to notifications daemon once
This commit is contained in:
parent
94a3c35e22
commit
6875bb38c0
2 changed files with 5 additions and 14 deletions
|
|
@ -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::{
|
||||
|
|
|
|||
|
|
@ -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<N
|
|||
std::any::TypeId::of::<SomeWorker>(),
|
||||
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<NotificationsAppletProxy<'static>> {
|
||||
let raw_fd = std::env::var("COSMIC_NOTIFICATIONS")?;
|
||||
let raw_fd = raw_fd.parse::<RawFd>()?;
|
||||
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)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue