Skip to content

Commit 3e09084

Browse files
committed
fixup! feat: winrtble adapter_info and StateUpdate implementation
1 parent 20dc206 commit 3e09084

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/winrtble/adapter.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct Adapter {
3737
}
3838

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

6365
Adapter {
6466
watcher,
@@ -131,6 +133,6 @@ impl Central for Adapter {
131133
}
132134

133135
async fn adapter_state(&self) -> Result<CentralState> {
134-
Ok(get_central_state(self.radio.clone()))
136+
Ok(get_central_state(&self.radio))
135137
}
136138
}

src/winrtble/manager.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl api::Manager for Manager {
3535
Ok(radios
3636
.into_iter()
3737
.filter(|radio| radio.Kind() == Ok(RadioKind::Bluetooth))
38-
.map(|radio| Adapter::new(radio.clone()))
38+
.map(|radio| Adapter::new(radio))
3939
.collect())
4040
}
4141
}

0 commit comments

Comments
 (0)