Skip to content

Commit 6bb6ee6

Browse files
committed
fix: better handle daemon restarts
1 parent 94becdd commit 6bb6ee6

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

cosmic-applet-notifications/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl Application for Notifications {
183183
.min_width(1.0)
184184
.max_width(300.0)
185185
.min_height(100.0)
186-
.max_height(600.0);
186+
.max_height(900.0);
187187
get_popup(popup_settings)
188188
}
189189
}

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,25 @@ pub fn notifications() -> Subscription<AppletEvent> {
4141

4242
std::thread::spawn(move || -> anyhow::Result<()> {
4343
let mut msg = String::new();
44-
std::io::stdin().read_line(&mut msg)?;
45-
let raw_fd = msg.trim().parse::<RawFd>()?;
44+
45+
if let Err(err) = std::io::stdin().read_line(&mut msg) {
46+
error!("Failed to read line from panel: {}", err);
47+
anyhow::bail!("Failed to read line from panel");
48+
}
49+
50+
info!("Received fd from panel: {}", msg);
51+
let Ok(raw_fd) = msg.trim().parse::<RawFd>() else {
52+
error!("Failed to parse fd from panel");
53+
anyhow::bail!("Failed to parse fd from panel");
54+
};
4655
if raw_fd == 0 {
56+
error!("Invalid fd received from panel");
4757
anyhow::bail!("Invalid fd received from panel");
4858
}
49-
_ = tx.send(raw_fd);
59+
if let Err(err) = tx.send(raw_fd) {
60+
error!("Failed to send fd to main thread: {}", err);
61+
anyhow::bail!("Failed to send fd to main thread");
62+
}
5063
Ok(())
5164
});
5265

@@ -122,6 +135,10 @@ pub fn notifications() -> Subscription<AppletEvent> {
122135

123136
let mut lines = reader.lines();
124137
while let Ok(Some(line)) = lines.next_line().await {
138+
if line.is_empty() {
139+
warn!("Received empty line from notification stream. The notification daemon probably crashed, so we will exit.");
140+
std::process::exit(1);
141+
}
125142
if let Ok(event) = ron::de::from_str::<AppletEvent>(line.as_str()) {
126143
if let Err(_err) = output.send(event).await {
127144
error!("Error sending event");
@@ -130,8 +147,8 @@ pub fn notifications() -> Subscription<AppletEvent> {
130147
error!("Failed to deserialize event from notification stream");
131148
}
132149
}
133-
warn!("Notification stream closed");
134-
state = State::Finished;
150+
warn!("Notification stream closed. The notification daemon probably crashed, so we will exit.");
151+
std::process::exit(1);
135152
}
136153
State::Finished => {
137154
let () = futures::future::pending().await;

0 commit comments

Comments
 (0)