Skip to content

Commit

Permalink
fixup! feat: winrtble adapter_info and StateUpdate implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonlesisz committed Sep 10, 2024
1 parent 20dc206 commit 3e09084
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/winrtble/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct Adapter {
}

// https://github.com/microsoft/windows-rs/blob/master/crates/libs/windows/src/Windows/Devices/Radios/mod.rs
fn get_central_state(radio: Radio) -> CentralState {
fn get_central_state(radio: &Radio) -> CentralState {
let state = radio.State().unwrap_or(RadioState::Unknown);
match state {
RadioState::On => CentralState::PoweredOn,
Expand All @@ -54,11 +54,13 @@ impl Adapter {
let radio_clone = radio.clone();
let manager_clone = manager.clone();
let handler = TypedEventHandler::new(move |_sender, _args| {
let state = get_central_state(radio_clone.clone());
let state = get_central_state(&radio_clone);
manager_clone.emit(CentralEvent::StateUpdate(state.into()));
Ok(())
});
radio.StateChanged(&handler);
if let Err(err) = radio.StateChanged(&handler) {
eprintln!("radio.StateChanged error: {}", err);
}

Adapter {
watcher,
Expand Down Expand Up @@ -131,6 +133,6 @@ impl Central for Adapter {
}

async fn adapter_state(&self) -> Result<CentralState> {
Ok(get_central_state(self.radio.clone()))
Ok(get_central_state(&self.radio))
}
}
2 changes: 1 addition & 1 deletion src/winrtble/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl api::Manager for Manager {
Ok(radios
.into_iter()
.filter(|radio| radio.Kind() == Ok(RadioKind::Bluetooth))
.map(|radio| Adapter::new(radio.clone()))
.map(|radio| Adapter::new(radio))
.collect())
}
}

0 comments on commit 3e09084

Please sign in to comment.