mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
add an abort option to the initialization flow
This commit is contained in:
parent
29f7cbe53b
commit
352b725f7a
5 changed files with 72 additions and 18 deletions
|
|
@ -397,6 +397,7 @@ pub struct RadioButtons {
|
|||
pub action_payload: RadioButtonPayload, // the current "radio button" selection
|
||||
pub select_index: i16, // the current candidate to be selected
|
||||
pub max_items: i16,
|
||||
pub is_password: bool,
|
||||
}
|
||||
impl RadioButtons {
|
||||
pub fn new(action_conn: xous::CID, action_opcode: u32) -> Self {
|
||||
|
|
@ -407,6 +408,7 @@ impl RadioButtons {
|
|||
action_payload: RadioButtonPayload::new(""),
|
||||
select_index: 0,
|
||||
max_items: 0,
|
||||
is_password: false,
|
||||
}
|
||||
}
|
||||
pub fn add_item(&mut self, new_item: ItemName) -> Option<ItemName> {
|
||||
|
|
@ -423,6 +425,9 @@ impl RadioButtons {
|
|||
}
|
||||
return Some(new_item);
|
||||
}
|
||||
fn is_password(&self) -> bool {
|
||||
self.is_password
|
||||
}
|
||||
}
|
||||
impl ActionApi for RadioButtons {
|
||||
fn set_action_opcode(&mut self, op: u32) {self.action_opcode = op}
|
||||
|
|
@ -432,9 +437,15 @@ impl ActionApi for RadioButtons {
|
|||
for item in self.items.iter() {
|
||||
if item.is_some(){ total_items += 1}
|
||||
}
|
||||
(total_items + 1) * glyph_height + margin * 2 + 5 // +4 for some bottom margin slop
|
||||
(total_items + 1) * glyph_height + margin * 2 + margin * 2 + 5 // +4 for some bottom margin slop
|
||||
}
|
||||
fn redraw(&self, at_height: i16, modal: &Modal) {
|
||||
let color = if self.is_password {
|
||||
PixelColor::Light
|
||||
} else {
|
||||
PixelColor::Dark
|
||||
};
|
||||
|
||||
// prime a textview with the correct general style parameters
|
||||
let mut tv = TextView::new(
|
||||
modal.canvas,
|
||||
|
|
@ -442,7 +453,7 @@ impl ActionApi for RadioButtons {
|
|||
);
|
||||
tv.ellipsis = true;
|
||||
tv.style = modal.style;
|
||||
tv.invert = false;
|
||||
tv.invert = self.is_password;
|
||||
tv.draw_border= false;
|
||||
tv.margin = Point::new(0, 0,);
|
||||
tv.insertion = None;
|
||||
|
|
@ -459,7 +470,7 @@ impl ActionApi for RadioButtons {
|
|||
let mut do_okay = true;
|
||||
for maybe_item in self.items.iter() {
|
||||
if let Some(item) = maybe_item {
|
||||
let cur_y = at_height + cur_line * modal.line_height;
|
||||
let cur_y = at_height + cur_line * modal.line_height + modal.margin * 2;
|
||||
if cur_line == self.select_index {
|
||||
// draw the cursor
|
||||
tv.text.clear();
|
||||
|
|
@ -494,7 +505,7 @@ impl ActionApi for RadioButtons {
|
|||
}
|
||||
}
|
||||
cur_line += 1;
|
||||
let cur_y = at_height + cur_line * modal.line_height;
|
||||
let cur_y = at_height + cur_line * modal.line_height + modal.margin * 2;
|
||||
if do_okay {
|
||||
tv.text.clear();
|
||||
tv.bounds_computed = None;
|
||||
|
|
@ -515,9 +526,9 @@ impl ActionApi for RadioButtons {
|
|||
|
||||
// divider lines
|
||||
modal.gam.draw_line(modal.canvas, Line::new_with_style(
|
||||
Point::new(modal.margin, at_height),
|
||||
Point::new(modal.canvas_width - modal.margin, at_height),
|
||||
DrawStyle::new(PixelColor::Dark, PixelColor::Dark, 1))
|
||||
Point::new(modal.margin, at_height + modal.margin),
|
||||
Point::new(modal.canvas_width - modal.margin, at_height + modal.margin),
|
||||
DrawStyle::new(color, color, 1))
|
||||
).expect("couldn't draw entry line");
|
||||
}
|
||||
fn key_action(&mut self, k: char) -> (Option<xous_ipc::String::<512>>, bool) {
|
||||
|
|
|
|||
|
|
@ -15,10 +15,25 @@
|
|||
"en-audio": "Root keys already initialized."
|
||||
},
|
||||
"rootkeys.setup": {
|
||||
"en": "This will init the root keys.\nI'm going to need two\npasswords:\n 1. Device unlock\n 2. Software update",
|
||||
"en": "This will init the root keys.\nI'm going to need two\npasswords:\n 1. Device unlock\n 2. Software update\nDo not lose them!",
|
||||
"zh": "这将初始化根密钥\n需要两个密码\n1.解锁\n2.软件更新",
|
||||
"en-audio": "This will initialize the root keys. We're going to need two passwords, one for device unlock, and one for software updates."
|
||||
},
|
||||
"rootkeys.confirm": {
|
||||
"en": "You should only proceed\nif you have inspected\nyour device and are ready\nto trust it.",
|
||||
"zh": "仅当您准备好信\n任此设备时才\n应继续",
|
||||
"en-audio": "You should only proceed with this operation if you are ready to trust this device."
|
||||
},
|
||||
"rootkeys.confirm.yes": {
|
||||
"en": "I'm ready!",
|
||||
"zh": "确定",
|
||||
"en-audio": "I'm ready!"
|
||||
},
|
||||
"rootkeys.confirm.no": {
|
||||
"en": "Not yet, maybe later.",
|
||||
"zh": "我先检查一下,稍后再试",
|
||||
"en-audio": "I'll try again after inspecting my device."
|
||||
},
|
||||
"rootkeys.setup_wait": {
|
||||
"en": "Initializing keys.\nThis takes a few minutes.\nDo not reset or sleep!",
|
||||
"zh": "现在正在初始化\n可能还要等一下\n不要重置或睡眠!\n",
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ pub(crate) enum Opcode {
|
|||
|
||||
/// attempt to initialize keys on a brand new system. Does nothing if the keys are already provisioned.
|
||||
UxTryInitKeys,
|
||||
UxConfirmInitKeys,
|
||||
UxConfirmation,
|
||||
UxInitRequestPassword,
|
||||
UxInitPasswordReturn,
|
||||
UxGutter, // NOP for UX calls that require a destination
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ fn xmain() -> ! {
|
|||
Some(t!("rootkeys.bootpass", xous::LANG)),
|
||||
None,
|
||||
GlyphStyle::Small,
|
||||
4
|
||||
8
|
||||
);
|
||||
rootkeys_modal.spawn_helper(keys_sid, rootkeys_modal.sid,
|
||||
Opcode::ModalRedraw.to_u32().unwrap(),
|
||||
|
|
@ -218,22 +218,48 @@ fn xmain() -> ! {
|
|||
None, true, None);
|
||||
keys.set_ux_password_type(None);
|
||||
} else {
|
||||
dismiss_modal_action.set_action_opcode(Opcode::UxInitRequestPassword.to_u32().unwrap());
|
||||
dismiss_modal_action.set_action_opcode(Opcode::UxConfirmInitKeys.to_u32().unwrap());
|
||||
rootkeys_modal.modify(
|
||||
Some(ActionType::Notification(dismiss_modal_action)),
|
||||
Some(t!("rootkeys.setup", xous::LANG)), false,
|
||||
None, true, None);
|
||||
|
||||
////// insert the "are you sure" message at this point in the flow -- don't call setup_key_init() until we're confirmed!
|
||||
|
||||
// setup_key_init() prepares the salt and other items necessary to receive a password safely
|
||||
keys.setup_key_init();
|
||||
// request the boot password first
|
||||
keys.set_ux_password_type(Some(PasswordType::Boot));
|
||||
}
|
||||
rootkeys_modal.activate();
|
||||
rootkeys_modal.redraw();
|
||||
}
|
||||
}),
|
||||
Some(Opcode::UxConfirmInitKeys) => {
|
||||
let mut confirm_radiobox = gam::modal::RadioButtons::new(
|
||||
main_cid,
|
||||
Opcode::UxConfirmation.to_u32().unwrap()
|
||||
);
|
||||
confirm_radiobox.is_password = true;
|
||||
confirm_radiobox.add_item(ItemName::new(t!("rootkeys.confirm.yes", xous::LANG)));
|
||||
confirm_radiobox.add_item(ItemName::new(t!("rootkeys.confirm.no", xous::LANG)));
|
||||
|
||||
////// insert the "are you sure" message at this point in the flow -- don't call setup_key_init() until we're confirmed!
|
||||
rootkeys_modal.modify(
|
||||
Some(ActionType::RadioButtons(confirm_radiobox)),
|
||||
Some(t!("rootkeys.confirm", xous::LANG)), false,
|
||||
None, true, None);
|
||||
rootkeys_modal.activate();
|
||||
},
|
||||
Some(Opcode::UxConfirmation) => {
|
||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let payload = buffer.to_original::<RadioButtonPayload, _>().unwrap();
|
||||
if payload.as_str() == t!("rootkeys.confirm.yes", xous::LANG) {
|
||||
// setup_key_init() prepares the salt and other items necessary to receive a password safely
|
||||
keys.setup_key_init();
|
||||
// request the boot password first
|
||||
keys.set_ux_password_type(Some(PasswordType::Boot));
|
||||
send_message(main_cid,
|
||||
xous::Message::new_scalar(Opcode::UxInitRequestPassword.to_usize().unwrap(), 0, 0, 0, 0)
|
||||
).expect("couldn't send message to kick off the password request process");
|
||||
} else {
|
||||
log::info!("init keys process aborted, no harm no foul");
|
||||
continue;
|
||||
}
|
||||
},
|
||||
Some(Opcode::UxInitRequestPassword) => {
|
||||
password_action.set_action_opcode(Opcode::UxInitPasswordReturn.to_u32().unwrap());
|
||||
if let Some(pwt) = keys.get_ux_password_type() {
|
||||
|
|
|
|||
|
|
@ -444,7 +444,7 @@ pub fn main_menu_thread(keys_init: usize, key_conn: usize, key_op: usize, selfsi
|
|||
};
|
||||
menu.add_item(sleep_item);
|
||||
|
||||
if keys_init == 1 {
|
||||
if keys_init == 0 {
|
||||
let initkeys_item = MenuItem {
|
||||
name: String::<64>::from_str(t!("mainmenu.init_keys", xous::LANG)),
|
||||
action_conn: key_conn as u32,
|
||||
|
|
|
|||
Loading…
Reference in a new issue