From 3d4f689ef5f6867491ae9277de030797276a3909 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 17 Jun 2022 12:42:22 +0800 Subject: [PATCH] lay in the groundwork for the "icontray" this allows the predictor area to serve as hot keys to swap between modes of operation for the vault app. --- Cargo.lock | 1 - apps/vault/Cargo.toml | 1 - apps/vault/src/icontray.rs | 73 ++++++++++++++++++++++++++++++++++++++ apps/vault/src/main.rs | 15 ++++++-- apps/vault/src/repl.rs | 16 +++++---- 5 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 apps/vault/src/icontray.rs diff --git a/Cargo.lock b/Cargo.lock index 7e1518e86..d6fea84ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3755,7 +3755,6 @@ dependencies = [ "graphics-server", "hex 0.4.3", "ime-plugin-api", - "ime-plugin-shell", "locales", "log", "log-server", diff --git a/apps/vault/Cargo.toml b/apps/vault/Cargo.toml index fc28464b8..7cf334524 100644 --- a/apps/vault/Cargo.toml +++ b/apps/vault/Cargo.toml @@ -22,7 +22,6 @@ pddb = {path = "../../services/pddb" } modals = {path = "../../services/modals" } ime-plugin-api = {path = "../../services/ime-plugin-api"} -ime-plugin-shell = {path = "../../services/ime-plugin-shell"} content-plugin-api = {path = "../../services/content-plugin-api"} # all content canvas providers must provide this API ctap-crypto = {path = "libraries/crypto"} cbor = {path = "libraries/cbor"} diff --git a/apps/vault/src/icontray.rs b/apps/vault/src/icontray.rs new file mode 100644 index 000000000..99321a58a --- /dev/null +++ b/apps/vault/src/icontray.rs @@ -0,0 +1,73 @@ +use ime_plugin_api::*; + +use xous_ipc::{String, Buffer}; +use num_traits::FromPrimitive; + +pub(crate) const SERVER_NAME_ICONTRAY: &'static str = "_vault icon tray plugin_"; + +const ICONS: [&'static str; 4] = [ + "\t FIDO", + "\t⏳1234", + "\t🔐****", + "\t🧾🛠", +]; + +pub(crate) fn icontray_server() { + let xns = xous_names::XousNames::new().unwrap(); + // one connection only, should be the GAM + let ime_sh_sid = xns.register_name(SERVER_NAME_ICONTRAY, Some(1)).expect("can't register server"); + + let mytriggers = PredictionTriggers { + newline: false, + punctuation: false, + whitespace: false, + }; + + loop { + let mut msg = xous::receive_message(ime_sh_sid).unwrap(); + log::trace!("received message {:?}", msg); + match FromPrimitive::from_usize(msg.body.id()) { + Some(Opcode::Input) => { + let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; + let s = buffer.as_flat::, _>().unwrap(); + // input is dynamically updated here + log::info!("Input: {}", s.as_str()); + } + Some(Opcode::Picked) => { + let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; + let s = buffer.as_flat::, _>().unwrap(); + // input is dynamically updated here + log::info!("Picked: {}", s.as_str()); + } + Some(Opcode::Prediction) => { + let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) }; + let mut prediction: Prediction = buffer.to_original::().unwrap(); + // every key press, the four slots get queried + prediction.string.clear(); + if prediction.index < ICONS.len() as u32 { + prediction.string.append(ICONS[prediction.index as usize]).ok(); + prediction.valid = true; + } else { + prediction.valid = false; + } + // pack our data back into the buffer to return + buffer.replace(Return::Prediction(prediction)).expect("couldn't return Prediction"); + } + Some(Opcode::Unpick) => { + // ignore + } + Some(Opcode::GetPredictionTriggers) => { + xous::return_scalar(msg.sender, mytriggers.into()).expect("couldn't return GetPredictionTriggers"); + } + Some(Opcode::Quit) => { + log::error!("received quit, goodbye!"); break; + } + None => {log::error!("unknown Opcode");} + } + } + log::trace!("main loop exit, destroying servers"); + xns.unregister_server(ime_sh_sid).unwrap(); + xous::destroy_server(ime_sh_sid).unwrap(); + log::trace!("quitting"); + xous::terminate_process(0) +} diff --git a/apps/vault/src/main.rs b/apps/vault/src/main.rs index a638231c0..24491b708 100644 --- a/apps/vault/src/main.rs +++ b/apps/vault/src/main.rs @@ -15,6 +15,7 @@ use ctap::status_code::Ctap2StatusCode; use ctap::CtapState; mod shims; use shims::*; +mod icontray; // CTAP2 testing notes: // run our branch and use this to forward the prompts on to the device: @@ -85,6 +86,7 @@ fn main() -> ! { let sid = xous::create_server().unwrap(); ux::start_ux_thread(); + // spawn the FIDO2 USB handler let _ = thread::spawn({ move || { let xns = xous_names::XousNames::new().unwrap(); @@ -135,6 +137,13 @@ fn main() -> ! { } }); + // spawn the icontray handler + let _ = thread::spawn({ + move || { + icontray::icontray_server(); + } + }); + let xns = xous_names::XousNames::new().unwrap(); let mut repl = Repl::new(&xns, sid); let mut update_repl = true; @@ -147,7 +156,8 @@ fn main() -> ! { Some(VaultOp::Line) => { let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let s = buffer.as_flat::, _>().unwrap(); - log::trace!("repl got input line: {}", s.as_str()); + log::info!("repl got input line: {}", s.as_str()); + // TODO: decode the input line here to catch F1-F4 keys and select the right app/mode repl.input(s.as_str()).expect("Vault couldn't accept input string"); update_repl = true; // set a flag, instead of calling here, so message can drop and calling server is released was_callback = false; @@ -167,13 +177,14 @@ fn main() -> ! { allow_redraw = true; } } + repl.redraw().ok(); }), Some(VaultOp::Quit) => { log::error!("got Quit"); break; } _ => { - log::trace!("got unknown message, treating as callback"); + log::trace!("got unknown message, passing on to REPL"); repl.msg(msg); update_repl = true; was_callback = true; diff --git a/apps/vault/src/repl.rs b/apps/vault/src/repl.rs index 9df9cbc95..8c09badba 100644 --- a/apps/vault/src/repl.rs +++ b/apps/vault/src/repl.rs @@ -8,14 +8,14 @@ pub(crate) struct Repl { // optional structures that indicate new input to the Repl loop per iteration // an input string input: Option, - // messages from other servers + // messages not handled by the main loop are routed here msg: Option, - // record our input history + /// the content area content: Gid, gam: gam::Gam, - // variables that define our graphical attributes + /// screensize of the content area screensize: Point, margin: Point, // margin to edge of canvas @@ -33,17 +33,19 @@ impl Repl{ let token = gam.register_ux(UxRegistration { app_name: xous_ipc::String::<128>::from_str(app_name_ref), ux_type: gam::UxType::Chat, - predictor: Some(xous_ipc::String::<64>::from_str(ime_plugin_shell::SERVER_NAME_IME_PLUGIN_SHELL)), + predictor: Some(xous_ipc::String::<64>::from_str(icontray::SERVER_NAME_ICONTRAY)), listener: sid.to_array(), // note disclosure of our SID to the GAM -- the secret is now shared with the GAM! redraw_id: VaultOp::Redraw.to_u32().unwrap(), gotinput_id: Some(VaultOp::Line.to_u32().unwrap()), audioframe_id: None, rawkeys_id: None, focuschange_id: Some(VaultOp::ChangeFocus.to_u32().unwrap()), - }).expect("couldn't register Ux context for repl"); + }).expect("couldn't register Ux context for repl").unwrap(); - let content = gam.request_content_canvas(token.unwrap()).expect("couldn't get content canvas"); + let content = gam.request_content_canvas(token).expect("couldn't get content canvas"); let screensize = gam.get_canvas_bounds(content).expect("couldn't get dimensions of content canvas"); + gam.toggle_menu_mode(token).expect("couldnt't toggle menu mode"); + Repl { input: None, msg: None, @@ -51,7 +53,7 @@ impl Repl{ gam, screensize, margin: Point::new(4, 4), - token: token.unwrap(), + token, } }