fix(bluetooth): stop discovery on leave asynchrously
This commit is contained in:
parent
55b0b19135
commit
66039e574e
1 changed files with 7 additions and 5 deletions
|
|
@ -194,6 +194,8 @@ impl page::Page<crate::pages::Message> for Page {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_leave(&mut self) -> Task<crate::pages::Message> {
|
fn on_leave(&mut self) -> Task<crate::pages::Message> {
|
||||||
|
let mut task = Task::none();
|
||||||
|
|
||||||
if let Some(cancel) = self.subscription.take() {
|
if let Some(cancel) = self.subscription.take() {
|
||||||
_ = cancel.send(());
|
_ = cancel.send(());
|
||||||
}
|
}
|
||||||
|
|
@ -201,19 +203,19 @@ impl page::Page<crate::pages::Message> for Page {
|
||||||
if let Some(connection) = self.connection.take() {
|
if let Some(connection) = self.connection.take() {
|
||||||
let adapters = self.model.adapters.clone();
|
let adapters = self.model.adapters.clone();
|
||||||
|
|
||||||
// Block the current thread to ensure that discovery is stopped
|
// Execute within task to ensure it completes before the app exits.
|
||||||
// on all adapters when the app is closed.
|
task = Task::future(async move {
|
||||||
Handle::current().block_on(async move {
|
|
||||||
for (path, _) in adapters {
|
for (path, _) in adapters {
|
||||||
stop_discovery(connection.clone(), path.clone()).await;
|
stop_discovery(connection.clone(), path.clone()).await;
|
||||||
}
|
}
|
||||||
_ = agent::unregister(connection).await;
|
_ = agent::unregister(connection).await;
|
||||||
});
|
})
|
||||||
|
.discard();
|
||||||
}
|
}
|
||||||
|
|
||||||
self.model.clear();
|
self.model.clear();
|
||||||
|
|
||||||
Task::none()
|
task
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dialog(&self) -> Option<Element<'_, crate::pages::Message>> {
|
fn dialog(&self) -> Option<Element<'_, crate::pages::Message>> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue