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.
This commit is contained in:
bunnie 2022-06-17 12:42:22 +08:00
parent 6e0d025dea
commit 3d4f689ef5
5 changed files with 95 additions and 11 deletions

1
Cargo.lock generated
View file

@ -3755,7 +3755,6 @@ dependencies = [
"graphics-server",
"hex 0.4.3",
"ime-plugin-api",
"ime-plugin-shell",
"locales",
"log",
"log-server",

View file

@ -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"}

View file

@ -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::<String::<4000>, _>().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::<String::<4000>, _>().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::<Prediction, _>().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)
}

View file

@ -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::<xous_ipc::String<4000>, _>().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;

View file

@ -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<String>,
// messages from other servers
// messages not handled by the main loop are routed here
msg: Option<MessageEnvelope>,
// 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,
}
}