mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
implement totp auto-typing
also extend totp updater to return the string so we can use that result to type a code
This commit is contained in:
parent
8a980c1c81
commit
7e5aaa805d
1 changed files with 22 additions and 4 deletions
|
|
@ -85,6 +85,8 @@ pub struct VaultUi {
|
||||||
item_height: isize,
|
item_height: isize,
|
||||||
style: GlyphStyle,
|
style: GlyphStyle,
|
||||||
storage_manager: Manager,
|
storage_manager: Manager,
|
||||||
|
|
||||||
|
usb_dev: usb_bao1x::UsbHid,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VaultUi {
|
impl VaultUi {
|
||||||
|
|
@ -118,6 +120,7 @@ impl VaultUi {
|
||||||
item_height: height / glyph_height,
|
item_height: height / glyph_height,
|
||||||
style,
|
style,
|
||||||
storage_manager: Manager::new(xns),
|
storage_manager: Manager::new(xns),
|
||||||
|
usb_dev: usb_bao1x::UsbHid::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,17 +133,27 @@ impl VaultUi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn update_selected_totp_code(&mut self) {
|
pub(crate) fn update_selected_totp_code(&mut self) -> Option<String> {
|
||||||
if self.totp_list.len() > 0 {
|
if self.totp_list.len() > 0 {
|
||||||
let selected = self.totp_list.get_selected();
|
let selected = self.totp_list.get_selected();
|
||||||
let mut locked_lists = self.item_lists.lock().unwrap();
|
let mut locked_lists = self.item_lists.lock().unwrap();
|
||||||
let full_list = locked_lists.full_list(VaultMode::Totp);
|
let full_list = locked_lists.full_list(VaultMode::Totp);
|
||||||
if let Some(selected_item) = full_list.iter().find(|item| item.name() == selected) {
|
if let Some(selected_item) = full_list.iter().find(|item| item.name() == selected) {
|
||||||
match crate::totp::db_str_to_code(&selected_item.extra) {
|
match crate::totp::db_str_to_code(&selected_item.extra) {
|
||||||
Ok(s) => self.totp_code = Some(s),
|
Ok(s) => {
|
||||||
_ => self.totp_code = None,
|
self.totp_code = Some(s.clone());
|
||||||
|
Some(s)
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
self.totp_code = None;
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -473,7 +486,12 @@ impl VaultUi {
|
||||||
NavDir::Down => {
|
NavDir::Down => {
|
||||||
self.totp_list.key_action('↓');
|
self.totp_list.key_action('↓');
|
||||||
}
|
}
|
||||||
_ => unimplemented!(),
|
_ => {
|
||||||
|
if let Some(code) = self.update_selected_totp_code() {
|
||||||
|
// ignore USB errors while sending code
|
||||||
|
self.usb_dev.send_str(&code).ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self.totp_code = None;
|
self.totp_code = None;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue