mirror of
https://github.com/pythops/bluetui.git
synced 2026-05-07 05:49:14 +08:00
trust and connect to new paired device
This commit is contained in:
@@ -13,6 +13,7 @@ pub enum Event {
|
||||
Mouse(MouseEvent),
|
||||
Resize(u16, u16),
|
||||
Notification(Notification),
|
||||
NewPairedDevice,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
||||
@@ -99,6 +99,40 @@ async fn pair(app: &mut App, sender: UnboundedSender<Event>) {
|
||||
NotificationLevel::Info,
|
||||
sender.clone(),
|
||||
);
|
||||
|
||||
let _ = sender.send(Event::NewPairedDevice);
|
||||
match device.set_trusted(true).await {
|
||||
Ok(_) => {
|
||||
let _ = Notification::send(
|
||||
"Device trusted".to_string(),
|
||||
NotificationLevel::Info,
|
||||
sender.clone(),
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
let _ = Notification::send(
|
||||
e.to_string(),
|
||||
NotificationLevel::Error,
|
||||
sender.clone(),
|
||||
);
|
||||
}
|
||||
};
|
||||
match device.connect().await {
|
||||
Ok(_) => {
|
||||
let _ = Notification::send(
|
||||
"Device connected".to_string(),
|
||||
NotificationLevel::Info,
|
||||
sender.clone(),
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
let _ = Notification::send(
|
||||
e.to_string(),
|
||||
NotificationLevel::Error,
|
||||
sender.clone(),
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
Err(e) => {
|
||||
let _ = Notification::send(
|
||||
|
||||
@@ -52,6 +52,9 @@ async fn main() -> AppResult<()> {
|
||||
Event::Notification(notification) => {
|
||||
app.notifications.push(notification);
|
||||
}
|
||||
Event::NewPairedDevice => {
|
||||
app.focused_block = bluetui::app::FocusedBlock::PairedDevices;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user