From 02f3e8d76cac41cbec2ac1b7cfe6375ff12a14a9 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Fri, 10 Feb 2023 15:06:28 -0500 Subject: [PATCH] refactor(bluetooth): handle end of device scan stream --- cosmic-applet-bluetooth/src/app.rs | 1 + cosmic-applet-bluetooth/src/bluetooth.rs | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cosmic-applet-bluetooth/src/app.rs b/cosmic-applet-bluetooth/src/app.rs index 884a5fec..d1f2478c 100644 --- a/cosmic-applet-bluetooth/src/app.rs +++ b/cosmic-applet-bluetooth/src/app.rs @@ -159,6 +159,7 @@ impl Application for CosmicBluetoothApplet { self.bluer_state = state; } BluerEvent::Finished => { + // TODO should this exit with an error causing a restart? eprintln!("bluetooth subscription finished. exiting..."); std::process::exit(0); } diff --git a/cosmic-applet-bluetooth/src/bluetooth.rs b/cosmic-applet-bluetooth/src/bluetooth.rs index 37fe74f8..d3d061f8 100644 --- a/cosmic-applet-bluetooth/src/bluetooth.rs +++ b/cosmic-applet-bluetooth/src/bluetooth.rs @@ -35,13 +35,13 @@ async fn start_listening(id: I, state: State) -> (Option<(I, Bl State::Ready => { let session = match Session::new().await { Ok(s) => s, - Err(_) => return (None, State::Finished), + Err(_) => return (Some((id, BluerEvent::Finished)), State::Finished), }; let (tx, rx) = channel(100); let session_state = match BluerSessionState::new(session, rx).await { Ok(s) => s, - Err(_) => return (None, State::Finished), + Err(_) => return (Some((id, BluerEvent::Finished)), State::Finished), }; let state = session_state.bluer_state().await; @@ -60,7 +60,7 @@ async fn start_listening(id: I, state: State) -> (Option<(I, Bl let mut session_rx = match session_state.rx.take() { Some(rx) => rx, None => { - return (None, State::Finished); // fail if we can't get the rx + return (Some((id, BluerEvent::Finished)), State::Finished); // fail if we can't get the rx } }; @@ -85,7 +85,7 @@ async fn start_listening(id: I, state: State) -> (Option<(I, Bl _ => None, } } else { - return (None, State::Finished); + return (Some((id, BluerEvent::Finished)), State::Finished); }; session_state.rx = Some(session_rx); (event, State::Waiting { session_state }) @@ -480,6 +480,7 @@ impl BluerSessionState { milli_timeout = (milli_timeout * 2).max(5120); } } + let _ = tx.send(BluerSessionEvent::ChangeStreamEnded).await; Ok(()) }); }