add option to type usernames as well as passwords

passwords is the "quick default", you have to pop down by
one on the menu to type a username.

This should address #401.
This commit is contained in:
bunnie 2023-08-08 01:19:51 +08:00
parent df663c32d2
commit 93a2dc0515
3 changed files with 35 additions and 12 deletions

View file

@ -252,11 +252,18 @@
"zh": "添加新项目"
},
"vault.menu_autotype": {
"en": "Autotype",
"en-tts": "Autotype",
"fr": "Autotype",
"ja": "自動的に入力",
"zh": "自动输入"
"en": "Autotype password",
"en-tts": "Autotype password",
"fr": "Autotype mot de passe",
"ja": "パスワードの自動入力",
"zh": "自动输入密码"
},
"vault.menu_autotype_username": {
"en": "Autotype username",
"en-tts": "Autotype username",
"fr": "Autotype nom d'utilisateur",
"ja": "ユーザー名を自動的に入力",
"zh": "自动输入用户名"
},
"vault.menu_change_font": {
"en": "Change list font",

View file

@ -28,7 +28,7 @@ use crate::vendor_commands::VendorSession;
use ux::framework::{VaultUx, DEFAULT_FONT, FONT_LIST, name_to_style};
use xous_ipc::Buffer;
use xous::{send_message, Message, msg_blocking_scalar_unpack};
use xous::{send_message, Message, msg_blocking_scalar_unpack, msg_scalar_unpack};
use usbd_human_interface_device::device::fido::*;
use num_traits::*;
@ -612,10 +612,10 @@ fn main() -> ! {
allow_totp_rendering.store(true, Ordering::SeqCst);
vaultux.update_mode();
}
Some(VaultOp::MenuAutotype) => {
Some(VaultOp::MenuAutotype) => msg_scalar_unpack!(msg, select_username, _, _, _, {
allow_totp_rendering.store(false, Ordering::SeqCst);
modals.dynamic_notification(Some(t!("vault.autotyping", locales::LANG)), None).ok();
match vaultux.autotype() {
match vaultux.autotype(select_username == 1) {
Err(xous::Error::UseBeforeInit) => { // USB not plugged in
modals.dynamic_notification_update(Some(t!("vault.error.usb_error", locales::LANG)), None).ok();
tt.sleep_ms(ERR_TIMEOUT_MS).unwrap();
@ -651,7 +651,7 @@ fn main() -> ! {
let buf = Buffer::into_buf(entry).expect("IPC error");
buf.send(actions_conn, ActionOp::UpdateOneItem.to_u32().unwrap()).expect("messaging error");
}
}
}),
Some(VaultOp::MenuDeleteStage1) => {
// stage 1 happens here because the filtered list and selection entry are in the responsive UX section.
if let Some(entry) = vaultux.selected_entry() {

View file

@ -187,6 +187,7 @@ impl VaultUx {
pub fn swap_submenu(&mut self) {
// always call delete on the potential optional items, to return us to a known state
self.menu_mgr.delete_item(t!("vault.menu_autotype", locales::LANG));
self.menu_mgr.delete_item(t!("vault.menu_autotype_username", locales::LANG));
self.menu_mgr.delete_item(t!("vault.menu_addnew", locales::LANG));
match *self.mode.lock().unwrap() {
VaultMode::Fido => (),
@ -201,6 +202,16 @@ impl VaultUx {
},
0
);
self.menu_mgr.insert_item(
MenuItem {
name: xous_ipc::String::from_str(t!("vault.menu_autotype_username", locales::LANG)),
action_conn: Some(self.main_conn),
action_opcode: VaultOp::MenuAutotype.to_u32().unwrap(),
action_payload: MenuPayload::Scalar([1, 0, 0, 0]),
close_on_select: true,
},
0
);
self.menu_mgr.insert_item(
MenuItem {
name: xous_ipc::String::from_str(t!("vault.menu_autotype", locales::LANG)),
@ -555,7 +566,7 @@ impl VaultUx {
pub(crate) fn set_autotype_delay_ms(&self, rate: usize) {
self.usb_dev.set_autotype_delay_ms(rate);
}
pub(crate) fn autotype(&mut self) -> Result<(), xous::Error> {
pub(crate) fn autotype(&mut self, type_username: bool) -> Result<(), xous::Error> {
let mode_cache = (*self.mode.lock().unwrap()).clone();
match mode_cache {
VaultMode::Password => {
@ -574,14 +585,19 @@ impl VaultUx {
match record.read_to_end(&mut data) {
Ok(_len) => {
if let Some(mut pw) = crate::storage::PasswordRecord::try_from(data).ok() {
match self.usb_dev.send_str(&pw.password) {
let to_type = if type_username {
&pw.username
} else {
&pw.password
};
match self.usb_dev.send_str(to_type) {
Ok(_) => {
pw.count += 1;
pw.atime = atime;
pw
},
Err(e) => {
log::error!("couldn't autotype password: {:?}", e);
log::error!("couldn't autotype: {:?}", e);
return Err(xous::Error::UseBeforeInit);
}
}