mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
add customized menu contexts per sub-app
This commit is contained in:
parent
8d4cdb3284
commit
ad92cbe1cb
4 changed files with 82 additions and 12 deletions
|
|
@ -149,6 +149,12 @@
|
||||||
"zh": "自动输入",
|
"zh": "自动输入",
|
||||||
"en-tts": "Autotype"
|
"en-tts": "Autotype"
|
||||||
},
|
},
|
||||||
|
"vault.menu_addnew": {
|
||||||
|
"en": "Add new item",
|
||||||
|
"ja": "新しいアイテムを追加する",
|
||||||
|
"zh": "添加新项目",
|
||||||
|
"en-tts": "Add new item"
|
||||||
|
},
|
||||||
"vault.menu_edit": {
|
"vault.menu_edit": {
|
||||||
"en": "Edit item",
|
"en": "Edit item",
|
||||||
"ja": "アイテムを編集する",
|
"ja": "アイテムを編集する",
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ pub(crate) enum VaultOp {
|
||||||
|
|
||||||
/// Menu items
|
/// Menu items
|
||||||
MenuAutotype,
|
MenuAutotype,
|
||||||
|
MenuAddnew,
|
||||||
MenuEdit,
|
MenuEdit,
|
||||||
MenuDelete,
|
MenuDelete,
|
||||||
MenuChangeFont,
|
MenuChangeFont,
|
||||||
|
|
@ -163,11 +164,11 @@ fn main() -> ! {
|
||||||
});
|
});
|
||||||
|
|
||||||
let menu_sid = xous::create_server().unwrap();
|
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();
|
let xns = xous_names::XousNames::new().unwrap();
|
||||||
// TODO: add a UX loop that indicates we're waiting for a PDDB mount before moving forward
|
// 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);
|
vaultux.set_mode(VaultMode::Fido);
|
||||||
let mut allow_redraw = false;
|
let mut allow_redraw = false;
|
||||||
let modals = modals::Modals::new(&xns).unwrap();
|
let modals = modals::Modals::new(&xns).unwrap();
|
||||||
|
|
@ -229,6 +230,7 @@ fn main() -> ! {
|
||||||
}
|
}
|
||||||
Some(VaultOp::ChangeFocus) => xous::msg_scalar_unpack!(msg, new_state_code, _, _, _, {
|
Some(VaultOp::ChangeFocus) => xous::msg_scalar_unpack!(msg, new_state_code, _, _, _, {
|
||||||
let new_state = gam::FocusState::convert_focus_change(new_state_code);
|
let new_state = gam::FocusState::convert_focus_change(new_state_code);
|
||||||
|
vaultux.change_focus_to(&new_state);
|
||||||
match new_state {
|
match new_state {
|
||||||
gam::FocusState::Background => {
|
gam::FocusState::Background => {
|
||||||
allow_redraw = false;
|
allow_redraw = false;
|
||||||
|
|
@ -247,6 +249,9 @@ fn main() -> ! {
|
||||||
Some(VaultOp::MenuEdit) => {
|
Some(VaultOp::MenuEdit) => {
|
||||||
log::info!("got edit");
|
log::info!("got edit");
|
||||||
}
|
}
|
||||||
|
Some(VaultOp::MenuAddnew) => {
|
||||||
|
log::info!("got add new");
|
||||||
|
}
|
||||||
Some(VaultOp::MenuChangeFont) => {
|
Some(VaultOp::MenuChangeFont) => {
|
||||||
for item in FONT_LIST {
|
for item in FONT_LIST {
|
||||||
modals
|
modals
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,6 @@ use crate::VaultOp;
|
||||||
pub fn create_submenu(vault_conn: xous::CID, menu_mgr: xous::SID) -> MenuMatic {
|
pub fn create_submenu(vault_conn: xous::CID, menu_mgr: xous::SID) -> MenuMatic {
|
||||||
let mut menu_items = Vec::<MenuItem>::new();
|
let mut menu_items = Vec::<MenuItem>::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 {
|
menu_items.push(MenuItem {
|
||||||
name: xous_ipc::String::from_str(t!("vault.menu_edit", xous::LANG)),
|
name: xous_ipc::String::from_str(t!("vault.menu_edit", xous::LANG)),
|
||||||
action_conn: Some(vault_conn),
|
action_conn: Some(vault_conn),
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use gam::{UxRegistration, GlyphStyle};
|
use gam::{UxRegistration, GlyphStyle, MenuMatic, MenuItem, MenuPayload};
|
||||||
use graphics_server::{Gid, Point, Rectangle, DrawStyle, PixelColor, TextView};
|
use graphics_server::{Gid, Point, Rectangle, DrawStyle, PixelColor, TextView};
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use pddb::Pddb;
|
use pddb::Pddb;
|
||||||
|
|
@ -74,6 +74,10 @@ pub(crate) struct VaultUx {
|
||||||
style: GlyphStyle,
|
style: GlyphStyle,
|
||||||
item_height: i16,
|
item_height: i16,
|
||||||
items_per_screen: i16,
|
items_per_screen: i16,
|
||||||
|
|
||||||
|
/// menu manager
|
||||||
|
menu_mgr: MenuMatic,
|
||||||
|
main_conn: xous::CID,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) const DEFAULT_FONT: GlyphStyle = GlyphStyle::Regular;
|
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_DICT: &'static str = "vault.config";
|
||||||
const VAULT_CONFIG_KEY_FONT: &'static str = "fontstyle";
|
const VAULT_CONFIG_KEY_FONT: &'static str = "fontstyle";
|
||||||
impl VaultUx {
|
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 gam = gam::Gam::new(xns).expect("can't connect to GAM");
|
||||||
|
|
||||||
let app_name_ref = gam::APP_NAME_VAULT;
|
let app_name_ref = gam::APP_NAME_VAULT;
|
||||||
|
|
@ -183,6 +187,8 @@ impl VaultUx {
|
||||||
style,
|
style,
|
||||||
item_height,
|
item_height,
|
||||||
items_per_screen,
|
items_per_screen,
|
||||||
|
menu_mgr,
|
||||||
|
main_conn: xous::connect(sid).unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub(crate) fn set_mode(&mut self, mode: VaultMode) {
|
pub(crate) fn set_mode(&mut self, mode: VaultMode) {
|
||||||
|
|
@ -196,8 +202,63 @@ impl VaultUx {
|
||||||
self.item_list.sort();
|
self.item_list.sort();
|
||||||
self.selection_index = 0;
|
self.selection_index = 0;
|
||||||
self.filter("");
|
self.filter("");
|
||||||
|
self.swap_submenu(&mode);
|
||||||
self.mode = 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) {
|
pub(crate) fn set_glyph_style(&mut self, style: GlyphStyle) {
|
||||||
// force redraw of all the items
|
// force redraw of all the items
|
||||||
self.title_dirty = true;
|
self.title_dirty = true;
|
||||||
|
|
@ -281,6 +342,7 @@ impl VaultUx {
|
||||||
}
|
}
|
||||||
/// accept a new input string
|
/// accept a new input string
|
||||||
pub(crate) fn input(&mut self, line: &str) -> Result<(), xous::Error> {
|
pub(crate) fn input(&mut self, line: &str) -> Result<(), xous::Error> {
|
||||||
|
self.title_dirty = true;
|
||||||
self.filter(line);
|
self.filter(line);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -424,9 +486,13 @@ impl VaultUx {
|
||||||
Ok(())
|
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");
|
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) {
|
pub(crate) fn filter(&mut self, criteria: &str) {
|
||||||
self.filtered_list.clear();
|
self.filtered_list.clear();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue