diff --git a/apps/vault/locales/i18n.json b/apps/vault/locales/i18n.json index ee766f124..103752845 100644 --- a/apps/vault/locales/i18n.json +++ b/apps/vault/locales/i18n.json @@ -149,6 +149,12 @@ "zh": "自动输入", "en-tts": "Autotype" }, + "vault.menu_addnew": { + "en": "Add new item", + "ja": "新しいアイテムを追加する", + "zh": "添加新项目", + "en-tts": "Add new item" + }, "vault.menu_edit": { "en": "Edit item", "ja": "アイテムを編集する", diff --git a/apps/vault/src/main.rs b/apps/vault/src/main.rs index f6f24c2e1..f1b1ee78b 100644 --- a/apps/vault/src/main.rs +++ b/apps/vault/src/main.rs @@ -80,6 +80,7 @@ pub(crate) enum VaultOp { /// Menu items MenuAutotype, + MenuAddnew, MenuEdit, MenuDelete, MenuChangeFont, @@ -163,11 +164,11 @@ fn main() -> ! { }); let menu_sid = xous::create_server().unwrap(); - let _menu_mgr = submenu::create_submenu(conn, menu_sid); + let menu_mgr = submenu::create_submenu(conn, menu_sid); let xns = xous_names::XousNames::new().unwrap(); // TODO: add a UX loop that indicates we're waiting for a PDDB mount before moving forward - let mut vaultux = VaultUx::new(&xns, sid); + let mut vaultux = VaultUx::new(&xns, sid, menu_mgr); vaultux.set_mode(VaultMode::Fido); let mut allow_redraw = false; let modals = modals::Modals::new(&xns).unwrap(); @@ -229,6 +230,7 @@ fn main() -> ! { } Some(VaultOp::ChangeFocus) => xous::msg_scalar_unpack!(msg, new_state_code, _, _, _, { let new_state = gam::FocusState::convert_focus_change(new_state_code); + vaultux.change_focus_to(&new_state); match new_state { gam::FocusState::Background => { allow_redraw = false; @@ -247,6 +249,9 @@ fn main() -> ! { Some(VaultOp::MenuEdit) => { log::info!("got edit"); } + Some(VaultOp::MenuAddnew) => { + log::info!("got add new"); + } Some(VaultOp::MenuChangeFont) => { for item in FONT_LIST { modals diff --git a/apps/vault/src/submenu.rs b/apps/vault/src/submenu.rs index ffdac9463..98851c846 100644 --- a/apps/vault/src/submenu.rs +++ b/apps/vault/src/submenu.rs @@ -7,13 +7,6 @@ use crate::VaultOp; pub fn create_submenu(vault_conn: xous::CID, menu_mgr: xous::SID) -> MenuMatic { let mut menu_items = Vec::::new(); - /* menu_items.push(MenuItem { - name: xous_ipc::String::from_str(t!("vault.menu_autotype", xous::LANG)), - action_conn: Some(vault_conn), - action_opcode: VaultOp::MenuAutotype.to_u32().unwrap(), - action_payload: MenuPayload::Scalar([0, 0, 0, 0]), - close_on_select: true, - }); */ menu_items.push(MenuItem { name: xous_ipc::String::from_str(t!("vault.menu_edit", xous::LANG)), action_conn: Some(vault_conn), diff --git a/apps/vault/src/ux/framework.rs b/apps/vault/src/ux/framework.rs index 5806d62e6..e30880bca 100644 --- a/apps/vault/src/ux/framework.rs +++ b/apps/vault/src/ux/framework.rs @@ -1,5 +1,5 @@ use crate::*; -use gam::{UxRegistration, GlyphStyle}; +use gam::{UxRegistration, GlyphStyle, MenuMatic, MenuItem, MenuPayload}; use graphics_server::{Gid, Point, Rectangle, DrawStyle, PixelColor, TextView}; use std::fmt::Write; use pddb::Pddb; @@ -74,6 +74,10 @@ pub(crate) struct VaultUx { style: GlyphStyle, item_height: i16, items_per_screen: i16, + + /// menu manager + menu_mgr: MenuMatic, + main_conn: xous::CID, } pub(crate) const DEFAULT_FONT: GlyphStyle = GlyphStyle::Regular; @@ -108,7 +112,7 @@ const TITLE_HEIGHT: i16 = 26; const VAULT_CONFIG_DICT: &'static str = "vault.config"; const VAULT_CONFIG_KEY_FONT: &'static str = "fontstyle"; impl VaultUx { - pub(crate) fn new(xns: &xous_names::XousNames, sid: xous::SID) -> Self { + pub(crate) fn new(xns: &xous_names::XousNames, sid: xous::SID, menu_mgr: MenuMatic) -> Self { let gam = gam::Gam::new(xns).expect("can't connect to GAM"); let app_name_ref = gam::APP_NAME_VAULT; @@ -183,6 +187,8 @@ impl VaultUx { style, item_height, items_per_screen, + menu_mgr, + main_conn: xous::connect(sid).unwrap(), } } pub(crate) fn set_mode(&mut self, mode: VaultMode) { @@ -196,8 +202,63 @@ impl VaultUx { self.item_list.sort(); self.selection_index = 0; self.filter(""); + self.swap_submenu(&mode); self.mode = mode; } + + /* + Entry Users + ------------------------------------- + - autotype pw + - add new pw totp + - edit pw totp fido + - delete pw totp fido + - change font pw totp fido + - close pw totp fido + */ + pub fn swap_submenu(&mut self, mode: &VaultMode) { + // always call delete on the potential optional items, to return us to a known state + self.menu_mgr.delete_item(t!("vault.menu_autotype", xous::LANG)); + self.menu_mgr.delete_item(t!("vault.menu_addnew", xous::LANG)); + match mode { + VaultMode::Fido => (), + VaultMode::Totp => { + self.menu_mgr.insert_item( + MenuItem { + name: xous_ipc::String::from_str(t!("vault.menu_addnew", xous::LANG)), + action_conn: Some(self.main_conn), + action_opcode: VaultOp::MenuAddnew.to_u32().unwrap(), + action_payload: MenuPayload::Scalar([0, 0, 0, 0]), + close_on_select: true, + }, + 0 + ); + }, + VaultMode::Password => { + self.menu_mgr.insert_item( + MenuItem { + name: xous_ipc::String::from_str(t!("vault.menu_addnew", xous::LANG)), + action_conn: Some(self.main_conn), + action_opcode: VaultOp::MenuAddnew.to_u32().unwrap(), + action_payload: MenuPayload::Scalar([0, 0, 0, 0]), + close_on_select: true, + }, + 0 + ); + self.menu_mgr.insert_item( + MenuItem { + name: xous_ipc::String::from_str(t!("vault.menu_autotype", xous::LANG)), + action_conn: Some(self.main_conn), + action_opcode: VaultOp::MenuAutotype.to_u32().unwrap(), + action_payload: MenuPayload::Scalar([0, 0, 0, 0]), + close_on_select: true, + }, + 0 + ); + } + } + } + pub(crate) fn set_glyph_style(&mut self, style: GlyphStyle) { // force redraw of all the items self.title_dirty = true; @@ -281,6 +342,7 @@ impl VaultUx { } /// accept a new input string pub(crate) fn input(&mut self, line: &str) -> Result<(), xous::Error> { + self.title_dirty = true; self.filter(line); Ok(()) } @@ -424,9 +486,13 @@ impl VaultUx { Ok(()) } - pub(crate) fn raise_menu(&self) { + pub(crate) fn raise_menu(&mut self) { + self.title_dirty = true; self.gam.raise_menu(gam::APP_MENU_0_VAULT).expect("couldn't raise our submenu"); } + pub (crate) fn change_focus_to(&mut self, _state: &gam::FocusState) { + self.title_dirty = true; + } pub(crate) fn filter(&mut self, criteria: &str) { self.filtered_list.clear();