Skip to content

Commit c456673

Browse files
committed
more logging
1 parent 2f7255e commit c456673

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

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

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
use tokio::{
2-
io::{AsyncBufReadExt, BufReader},
3-
net::UnixStream,
4-
sync::oneshot,
5-
};
6-
use tracing::{error, info};
71
use cosmic::{
82
iced::{
93
futures::{self, SinkExt},
@@ -12,8 +6,14 @@ use cosmic::{
126
iced_futures::Subscription,
137
};
148
use cosmic_notifications_util::AppletEvent;
15-
use std::os::unix::io::{FromRawFd, RawFd};
169
use sendfd::RecvWithFd;
10+
use std::os::unix::io::{FromRawFd, RawFd};
11+
use tokio::{
12+
io::{self, AsyncBufReadExt, BufReader},
13+
net::UnixStream,
14+
sync::oneshot,
15+
};
16+
use tracing::{error, info, warn};
1717

1818
#[derive(Debug)]
1919
pub enum State {
@@ -42,14 +42,14 @@ pub fn notifications() -> Subscription<AppletEvent> {
4242
std::thread::spawn(move || -> anyhow::Result<()> {
4343
let mut msg = String::new();
4444
std::io::stdin().read_line(&mut msg)?;
45-
let raw_fd = msg.trim().parse::<RawFd>()?;
45+
let raw_fd = msg.trim().parse::<RawFd>()?;
4646
if raw_fd == 0 {
4747
anyhow::bail!("Invalid fd received from panel");
4848
}
4949
_ = tx.send(raw_fd);
5050
Ok(())
5151
});
52-
52+
5353
let Ok(raw_fd) = rx.await else {
5454
error!("Failed to receive raw fd from panel");
5555
state = State::Finished;
@@ -63,10 +63,9 @@ pub fn notifications() -> Subscription<AppletEvent> {
6363
continue;
6464
};
6565
state = State::WaitingForDaemon(stream);
66-
6766
}
6867
State::WaitingForDaemon(stream) => {
69-
info!("Waiting for daemon to send us a stream");
68+
info!("Waiting for panel to send us a stream");
7069
if let Err(err) = stream.readable().await {
7170
error!("Failed to wait for stream to be readable {}", err);
7271
state = State::Finished;
@@ -79,21 +78,35 @@ pub fn notifications() -> Subscription<AppletEvent> {
7978

8079
match stream.recv_with_fd(&mut buf, &mut fd_buf) {
8180
Ok((data_cnt, fd_cnt)) => {
81+
if data_cnt == 0 && fd_cnt == 0 {
82+
warn!("Received EOF from panel");
83+
state = State::Finished;
84+
85+
continue;
86+
}
8287
if data_cnt != 4 || fd_cnt != 1 {
83-
error!("Invalid data received from panel");
88+
error!(
89+
"Invalid data received from panel {} {}",
90+
data_cnt, fd_cnt
91+
);
8492
state = State::Finished;
8593

8694
continue;
8795
}
88-
let notif_stream = unsafe { std::os::unix::net::UnixStream::from_raw_fd(fd_buf[0]) };
96+
let notif_stream = unsafe {
97+
std::os::unix::net::UnixStream::from_raw_fd(fd_buf[0])
98+
};
8999
let Ok(notif_stream) = UnixStream::from_std(notif_stream) else {
90100
error!("Failed to convert raw fd to unix stream");
91101
state = State::Finished;
92102
continue;
93103
};
94-
104+
95105
state = State::WaitingForNotificationEvent(notif_stream);
96106
}
107+
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
108+
continue;
109+
}
97110
Err(err) => {
98111
error!("Failed to receive fd from panel: {}", err);
99112
state = State::Finished;
@@ -103,6 +116,7 @@ pub fn notifications() -> Subscription<AppletEvent> {
103116
}
104117
}
105118
State::WaitingForNotificationEvent(stream) => {
119+
info!("Waiting for notification event");
106120
let mut reader = BufReader::new(stream);
107121
// todo read messages
108122
let mut request_buf = String::with_capacity(1024);
@@ -124,6 +138,6 @@ pub fn notifications() -> Subscription<AppletEvent> {
124138
}
125139
}
126140
}
127-
}
141+
},
128142
)
129-
}
143+
}

0 commit comments

Comments
 (0)