Skip to content

Commit

Permalink
refactor: attempt to quit display background service when sender is c…
Browse files Browse the repository at this point in the history
…losed
  • Loading branch information
wash2 committed Nov 14, 2024
1 parent ba0fec1 commit bd35742
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions cosmic-settings/src/pages/display/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ impl page::Page<crate::pages::Message> for Page {
&mut self,
sender: tokio::sync::mpsc::Sender<crate::pages::Message>,
) -> Task<crate::pages::Message> {
use std::time::Duration;

if let Some(task) = self.background_service.take() {
task.abort();
}
Expand All @@ -253,11 +255,21 @@ impl page::Page<crate::pages::Message> for Page {
};

while context.dispatch(&mut event_queue).await.is_ok() {
while let Ok(message) = rx.try_recv() {
if sender.is_closed() {
break;
}
'outer: while let Ok(message) = rx.try_recv() {
if let cosmic_randr::Message::ManagerDone = message {
let _ = sender
.send(pages::Message::Displays(Message::Refresh))
.await;
if matches!(
tokio::time::timeout(
Duration::from_secs(1),
sender.send(pages::Message::Displays(Message::Refresh))
)
.await,
Err(_) | Ok(Err(_))
) {
break 'outer;
}
}
}
}
Expand Down

0 comments on commit bd35742

Please sign in to comment.