mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
shuffle around routines to better match original vault code
This commit is contained in:
parent
1e680727a8
commit
10957971bc
1 changed files with 90 additions and 62 deletions
|
|
@ -8,8 +8,7 @@ use ux_api::service::gfx::Gfx;
|
||||||
use ux_api::widgets::ScrollableList;
|
use ux_api::widgets::ScrollableList;
|
||||||
use xous::CID;
|
use xous::CID;
|
||||||
|
|
||||||
use crate::ItemLists;
|
use crate::*;
|
||||||
use crate::VaultMode;
|
|
||||||
|
|
||||||
pub enum NavDir {
|
pub enum NavDir {
|
||||||
Up,
|
Up,
|
||||||
|
|
@ -45,6 +44,7 @@ pub struct VaultUi {
|
||||||
gfx: Gfx,
|
gfx: Gfx,
|
||||||
totp_list: ScrollableList,
|
totp_list: ScrollableList,
|
||||||
item_lists: Arc<Mutex<ItemLists>>,
|
item_lists: Arc<Mutex<ItemLists>>,
|
||||||
|
mode: Arc<Mutex<VaultMode>>,
|
||||||
|
|
||||||
/// totp redraw state
|
/// totp redraw state
|
||||||
totp_code: Option<String>,
|
totp_code: Option<String>,
|
||||||
|
|
@ -52,7 +52,12 @@ pub struct VaultUi {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VaultUi {
|
impl VaultUi {
|
||||||
pub fn new(xns: &xous_names::XousNames, cid: xous::CID, item_lists: Arc<Mutex<ItemLists>>) -> Self {
|
pub fn new(
|
||||||
|
xns: &xous_names::XousNames,
|
||||||
|
cid: xous::CID,
|
||||||
|
item_lists: Arc<Mutex<ItemLists>>,
|
||||||
|
mode: Arc<Mutex<VaultMode>>,
|
||||||
|
) -> Self {
|
||||||
let mut totp_list = ScrollableList::default()
|
let mut totp_list = ScrollableList::default()
|
||||||
.set_margin(TotpLayout::totp_margin())
|
.set_margin(TotpLayout::totp_margin())
|
||||||
.pane_size(TotpLayout::list_box())
|
.pane_size(TotpLayout::list_box())
|
||||||
|
|
@ -65,6 +70,7 @@ impl VaultUi {
|
||||||
gfx: Gfx::new(&xns).unwrap(),
|
gfx: Gfx::new(&xns).unwrap(),
|
||||||
totp_list,
|
totp_list,
|
||||||
item_lists,
|
item_lists,
|
||||||
|
mode,
|
||||||
totp_code: None,
|
totp_code: None,
|
||||||
last_epoch: crate::totp::get_current_unix_time().expect("couldn't get current time") / 30,
|
last_epoch: crate::totp::get_current_unix_time().expect("couldn't get current time") / 30,
|
||||||
}
|
}
|
||||||
|
|
@ -74,9 +80,14 @@ impl VaultUi {
|
||||||
pub fn clear_area(&self) { self.gfx.clear().ok(); }
|
pub fn clear_area(&self) { self.gfx.clear().ok(); }
|
||||||
|
|
||||||
/// Redraw the text view onto the screen.
|
/// Redraw the text view onto the screen.
|
||||||
pub fn redraw_totp(&mut self) {
|
pub fn redraw(&mut self) {
|
||||||
|
// to reduce locking thrash, we cache a copy of the current mode at the top of redraw.
|
||||||
|
let mode_at_entry = (*self.mode.lock().unwrap()).clone();
|
||||||
|
|
||||||
self.gfx.clear().ok();
|
self.gfx.clear().ok();
|
||||||
|
|
||||||
|
match mode_at_entry {
|
||||||
|
VaultMode::Totp => {
|
||||||
// decorative box around code
|
// decorative box around code
|
||||||
let mut totp_box = TotpLayout::totp_box();
|
let mut totp_box = TotpLayout::totp_box();
|
||||||
totp_box.border.style = DrawStyle::new(PixelColor::Dark, PixelColor::Light, 1);
|
totp_box.border.style = DrawStyle::new(PixelColor::Dark, PixelColor::Light, 1);
|
||||||
|
|
@ -139,7 +150,24 @@ impl VaultUi {
|
||||||
timer_remaining.br = Point::new(width - delta_width, timer_remaining.br().y);
|
timer_remaining.br = Point::new(width - delta_width, timer_remaining.br().y);
|
||||||
timer_remaining.style = DrawStyle::new(PixelColor::Light, PixelColor::Light, 1);
|
timer_remaining.style = DrawStyle::new(PixelColor::Light, PixelColor::Light, 1);
|
||||||
self.gfx.draw_rectangle(timer_remaining).ok();
|
self.gfx.draw_rectangle(timer_remaining).ok();
|
||||||
|
}
|
||||||
|
VaultMode::Password => {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
self.gfx.flush().ok();
|
self.gfx.flush().ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn nav(&mut self, dir: NavDir) {
|
||||||
|
self.item_lists.lock().unwrap().nav((*self.mode.lock().unwrap()).clone(), dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn filter(&mut self, criteria: &String) {
|
||||||
|
self.item_lists.lock().unwrap().filter(self.mode.lock().unwrap().clone(), criteria);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn selected_entry(&self) -> Option<SelectedEntry> {
|
||||||
|
let mode = (*self.mode.lock().unwrap()).clone();
|
||||||
|
self.item_lists.lock().unwrap().selected_entry(mode)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue