From 880675c23881ce5653d38fcaa38967a25fb6e21f Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 6 Nov 2022 18:44:56 +0800 Subject: [PATCH] remove UX delays between dialog boxes --- apps/vault/Cargo.toml | 2 ++ apps/vault/src/actions.rs | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/apps/vault/Cargo.toml b/apps/vault/Cargo.toml index 8285e652b..93b68d477 100644 --- a/apps/vault/Cargo.toml +++ b/apps/vault/Cargo.toml @@ -71,5 +71,7 @@ autotest = [] multireset = [] # allows credential reset more than once per boot vaultperf = ["perflib", "xous/v2p", "utralib", "utralib/precursor"] # vault is the performance logging manager. Do not use concurrently with "shellperf", as there can only be one manager. vault-testing = ["random-pick"] +# introduce a slight delay after UX boxes swap, in case of race conditions. Shouldn't be necessary anymore, but kept around in case there's a new edge case we missed. +ux-swap-delay = [] default = ["with_ctap1", "with_ctap2_1"] # testing removed for release tag \ No newline at end of file diff --git a/apps/vault/src/actions.rs b/apps/vault/src/actions.rs index c4209174e..677786231 100644 --- a/apps/vault/src/actions.rs +++ b/apps/vault/src/actions.rs @@ -29,6 +29,7 @@ pub(crate) const VAULT_ALLOC_HINT: usize = 256; const VAULT_PASSWORD_REC_VERSION: u32 = 1; const VAULT_TOTP_REC_VERSION: u32 = 1; /// time allowed between dialog box swaps for background operations to redraw +#[cfg(feature="ux-swap-delay")] const SWAP_DELAY_MS: usize = 300; #[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] @@ -202,6 +203,7 @@ impl<'a> ActionManager<'a> { (*self.mode.lock().unwrap()).clone() }; self.action_active.store(true, Ordering::SeqCst); + #[cfg(feature="ux-swap-delay")] self.tt.sleep_ms(SWAP_DELAY_MS).unwrap(); // allow calling menu to close } pub(crate) fn deactivate(&self) { @@ -226,6 +228,7 @@ impl<'a> ActionManager<'a> { }, _ => {log::error!("Name entry failed"); self.action_active.store(false, Ordering::SeqCst); return} }; + #[cfg(feature="ux-swap-delay")] self.tt.sleep_ms(SWAP_DELAY_MS).unwrap(); let username = match self.modals .alert_builder(t!("vault.newitem.username", xous::LANG)) @@ -235,6 +238,7 @@ impl<'a> ActionManager<'a> { Ok(text) => text.content()[0].content.as_str().unwrap_or("UTF-8 error").to_string(), _ => {log::error!("Name entry failed"); self.action_active.store(false, Ordering::SeqCst); return} }; + #[cfg(feature="ux-swap-delay")] self.tt.sleep_ms(SWAP_DELAY_MS).unwrap(); let mut approved = false; // Security note about PasswordGenerator. This is a 3rd party crate. It relies on `rand`'s implementation @@ -294,6 +298,7 @@ impl<'a> ActionManager<'a> { }, _ => {log::error!("Name entry failed"); self.action_active.store(false, Ordering::SeqCst); return} }; + #[cfg(feature="ux-swap-delay")] self.tt.sleep_ms(SWAP_DELAY_MS).unwrap(); password = if maybe_password.len() == 0 { let length = match self.modals @@ -304,6 +309,7 @@ impl<'a> ActionManager<'a> { Ok(entry) => entry.content()[0].content.as_str().unwrap().parse::().unwrap(), _ => {log::error!("Length entry failed"); self.action_active.store(false, Ordering::SeqCst); return} }; + #[cfg(feature="ux-swap-delay")] self.tt.sleep_ms(SWAP_DELAY_MS).unwrap(); let mut upper = false; let mut number = false; @@ -324,6 +330,7 @@ impl<'a> ActionManager<'a> { } _ => {log::error!("Modal selection error"); self.action_active.store(false, Ordering::SeqCst); return} } + #[cfg(feature="ux-swap-delay")] self.tt.sleep_ms(SWAP_DELAY_MS).unwrap(); let pg2 = PasswordGenerator { length: length as usize, @@ -376,6 +383,7 @@ impl<'a> ActionManager<'a> { _ => {log::error!("Name entry failed"); self.action_active.store(false, Ordering::SeqCst); return} }; + #[cfg(feature="ux-swap-delay")] self.tt.sleep_ms(SWAP_DELAY_MS).unwrap(); self.modals .add_list(vec![ @@ -394,6 +402,7 @@ impl<'a> ActionManager<'a> { _ => {log::error!("Modal selection error"); self.action_active.store(false, Ordering::SeqCst); return} } + #[cfg(feature="ux-swap-delay")] self.tt.sleep_ms(SWAP_DELAY_MS).unwrap(); let secret = match self.modals .alert_builder(t!("vault.newitem.totp_ss", xous::LANG)) @@ -405,6 +414,7 @@ impl<'a> ActionManager<'a> { }, _ => {log::error!("TOTP ss entry failed"); self.action_active.store(false, Ordering::SeqCst); return} }; + #[cfg(feature="ux-swap-delay")] self.tt.sleep_ms(SWAP_DELAY_MS).unwrap(); let ss = secret.to_uppercase(); let ss_vec = if let Some(ss) = base32::decode(base32::Alphabet::RFC4648 { padding: false }, &ss) { @@ -425,6 +435,7 @@ impl<'a> ActionManager<'a> { let timestep = if !is_totp { // get the initial count if it's an HOTP record + #[cfg(feature="ux-swap-delay")] self.tt.sleep_ms(SWAP_DELAY_MS).unwrap(); match self.modals .alert_builder(t!("vault.hotp.count", xous::LANG)) @@ -1032,6 +1043,7 @@ impl<'a> ActionManager<'a> { }, _ => {log::error!("Name entry failed"); self.action_active.store(false, Ordering::SeqCst); return} }; + #[cfg(feature="ux-swap-delay")] self.tt.sleep_ms(SWAP_DELAY_MS).unwrap(); match self.pddb.borrow().unlock_basis(&name, Some(BasisRetentionPolicy::Persist)) { Ok(_) => log::debug!("Basis {} unlocked", name), @@ -1076,6 +1088,7 @@ impl<'a> ActionManager<'a> { }, Err(e) => {self.report_err(t!("vault.error.internal_error", xous::LANG), Some(e)); return} }; + #[cfg(feature="ux-swap-delay")] self.tt.sleep_ms(SWAP_DELAY_MS).unwrap(); match self.pddb.borrow().create_basis(&name) { Ok(_) => {