From 66039e574ee17e042749feda8fd3ae5436de8a8e Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Thu, 12 Jun 2025 13:39:42 +0200 Subject: [PATCH] fix(bluetooth): stop discovery on leave asynchrously --- cosmic-settings/src/pages/bluetooth/mod.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cosmic-settings/src/pages/bluetooth/mod.rs b/cosmic-settings/src/pages/bluetooth/mod.rs index c3c1351..6cd81b8 100644 --- a/cosmic-settings/src/pages/bluetooth/mod.rs +++ b/cosmic-settings/src/pages/bluetooth/mod.rs @@ -194,6 +194,8 @@ impl page::Page for Page { } fn on_leave(&mut self) -> Task { + let mut task = Task::none(); + if let Some(cancel) = self.subscription.take() { _ = cancel.send(()); } @@ -201,19 +203,19 @@ impl page::Page for Page { if let Some(connection) = self.connection.take() { let adapters = self.model.adapters.clone(); - // Block the current thread to ensure that discovery is stopped - // on all adapters when the app is closed. - Handle::current().block_on(async move { + // Execute within task to ensure it completes before the app exits. + task = Task::future(async move { for (path, _) in adapters { stop_discovery(connection.clone(), path.clone()).await; } _ = agent::unregister(connection).await; - }); + }) + .discard(); } self.model.clear(); - Task::none() + task } fn dialog(&self) -> Option> {