regex search/replace instances of xous_ipc::String to String

This commit is contained in:
bunnie 2024-09-22 14:28:16 +08:00
parent b514d31fed
commit 1fd59f0fc9
8 changed files with 74 additions and 73 deletions

View file

@ -23,8 +23,9 @@ xous-names = { package = "xous-api-names", version = "0.9.61" }
num-derive = { version = "0.3.3", default-features = false } num-derive = { version = "0.3.3", default-features = false }
num-traits = { version = "0.2.14", default-features = false } num-traits = { version = "0.2.14", default-features = false }
rkyv = { version = "0.4.3", default-features = false, features = [ rkyv = { version = "0.8.8", default-features = false, features = [
"const_generics", "std",
"alloc",
] } ] }
susres = { package = "xous-api-susres", version = "0.9.59", optional = true } # used for the sleep now menu item susres = { package = "xous-api-susres", version = "0.9.59", optional = true } # used for the sleep now menu item

View file

@ -4,7 +4,7 @@ mod rkyv_enum;
use graphics_server::api::Tile; use graphics_server::api::Tile;
use graphics_server::api::{Gid, Point}; use graphics_server::api::{Gid, Point};
pub use rkyv_enum::*; pub use rkyv_enum::*;
use xous_ipc::String; use String;
pub(crate) const SERVER_NAME_GAM: &str = "_Graphical Abstraction Manager_"; pub(crate) const SERVER_NAME_GAM: &str = "_Graphical Abstraction Manager_";
@ -69,10 +69,10 @@ pub struct SetAudioOpcode {
pub opcode: u32, pub opcode: u32,
} }
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)] #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone)]
pub struct SwitchToApp { pub struct SwitchToApp {
pub token: [u32; 4], pub token: [u32; 4],
pub app_name: String<128>, pub app_name: String,
} }
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)] #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)]
@ -82,15 +82,15 @@ pub enum UxType {
Modal, Modal,
Framebuffer, Framebuffer,
} }
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)] #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone)]
pub struct UxRegistration { pub struct UxRegistration {
// request specification // request specification
pub app_name: String<128>, /* the putative name of our application - GAM may modify this if a spoof pub app_name: String, /* the putative name of our application - GAM may modify this if a spoof
* attempt is detected */ * attempt is detected */
pub ux_type: UxType, pub ux_type: UxType,
pub predictor: Option<String<64>>, /* optional specification for an IME prediction engine to use. This pub predictor: Option<String>, /* optional specification for an IME prediction engine to use. This
* can be updated later on, or None and a default engine will be * can be updated later on, or None and a default engine will be
* provided. */ * provided. */
// Callbacks: // Callbacks:
/// SID ofserver for callbacks from the GAM. Note this is a disclosure of the SID, which is normally a /// SID ofserver for callbacks from the GAM. Note this is a disclosure of the SID, which is normally a
@ -114,7 +114,7 @@ pub struct UxRegistration {
#[cfg(feature = "unsafe-app-loading")] #[cfg(feature = "unsafe-app-loading")]
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)] #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)]
pub struct NameRegistration { pub struct NameRegistration {
pub name: String<128>, pub name: String,
pub auth_token: [u32; 4], pub auth_token: [u32; 4],
} }
@ -240,7 +240,7 @@ pub enum ActivationResult {
} }
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
pub(crate) struct GamActivation { pub(crate) struct GamActivation {
pub(crate) name: xous_ipc::String<128>, pub(crate) name: String,
pub(crate) result: Option<ActivationResult>, pub(crate) result: Option<ActivationResult>,
} }
@ -250,9 +250,9 @@ pub(crate) struct MenuManagement {
pub(crate) op: MenuMgrOp, pub(crate) op: MenuMgrOp,
} }
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[derive(Debug, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
pub struct MenuItem { pub struct MenuItem {
pub name: String<64>, pub name: String,
/// if action_conn is None, this is a NOP menu item (it just does nothing and closes the menu) /// if action_conn is None, this is a NOP menu item (it just does nothing and closes the menu)
pub action_conn: Option<xous::CID>, pub action_conn: Option<xous::CID>,
pub action_opcode: u32, // this is ignored if action_conn is None pub action_opcode: u32, // this is ignored if action_conn is None
@ -289,9 +289,9 @@ pub struct GidRecord {
pub canvas_type: CanvasType, pub canvas_type: CanvasType,
} }
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Default)] #[derive(Debug, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Default)]
pub struct Bip39Ipc { pub struct Bip39Ipc {
pub data: [u8; 32], pub data: [u8; 32],
pub data_len: u32, pub data_len: u32,
pub words: [Option<xous_ipc::String<8>>; 24], pub words: [Option<String>; 24],
} }

View file

@ -7,7 +7,7 @@ use gam::MAIN_MENU_NAME;
use graphics_server::*; use graphics_server::*;
use ime_plugin_api::{ImeFrontEndApi, ImefDescriptor}; use ime_plugin_api::{ImeFrontEndApi, ImefDescriptor};
use log::info; use log::info;
use xous_ipc::{Buffer, String}; use xous_ipc::Buffer;
use crate::api::Opcode; use crate::api::Opcode;
use crate::*; use crate::*;
@ -67,7 +67,7 @@ pub(crate) struct UxContext {
/// the type of the Ux defined here /// the type of the Ux defined here
pub layout: UxLayout, pub layout: UxLayout,
/// what prediction engine is being used /// what prediction engine is being used
pub predictor: Option<String<64>>, pub predictor: Option<String>,
/// a putative human-readable name given to the context. The name itself is stored in the TokenManager, /// a putative human-readable name given to the context. The name itself is stored in the TokenManager,
/// not in this struct. Passed to the TokenManager to compute a trust level; add the app's name to /// not in this struct. Passed to the TokenManager to compute a trust level; add the app's name to
/// tokens.rs EXPECTED_BOOT_CONTEXTS if you want this to succeed. /// tokens.rs EXPECTED_BOOT_CONTEXTS if you want this to succeed.
@ -166,7 +166,7 @@ impl ContextManager {
canvases: &mut HashMap<Gid, Canvas>, canvases: &mut HashMap<Gid, Canvas>,
registration: UxRegistration, registration: UxRegistration,
) -> Option<[u32; 4]> { ) -> Option<[u32; 4]> {
let maybe_token = self.tm.claim_token(registration.app_name.as_str().unwrap()); let maybe_token = self.tm.claim_token(registration.app_name.as_str());
if let Some(token) = maybe_token { if let Some(token) = maybe_token {
match registration.ux_type { match registration.ux_type {
UxType::Chat => { UxType::Chat => {
@ -224,7 +224,7 @@ impl ContextManager {
pred_token: None, pred_token: None,
}; };
if registration.app_name.as_str().unwrap() == MAIN_MENU_NAME { if registration.app_name.as_str() == MAIN_MENU_NAME {
log::debug!("main menu found and registered!"); log::debug!("main menu found and registered!");
assert!( assert!(
self.main_menu_app_token == None, self.main_menu_app_token == None,
@ -262,8 +262,8 @@ impl ContextManager {
}; };
self.contexts.insert(token, ux_context); self.contexts.insert(token, ux_context);
// this check gives permissions to password boxes to render inverted text // this check gives permissions to password boxes to render inverted text
if registration.app_name.as_str().unwrap() == gam::ROOTKEY_MODAL_NAME if registration.app_name.as_str() == gam::ROOTKEY_MODAL_NAME
|| registration.app_name.as_str().unwrap() == gam::PDDB_MODAL_NAME || registration.app_name.as_str() == gam::PDDB_MODAL_NAME
{ {
if !self.set_context_trust_level(token, BOOT_CONTEXT_TRUSTLEVEL - 1, canvases) { if !self.set_context_trust_level(token, BOOT_CONTEXT_TRUSTLEVEL - 1, canvases) {
log::error!("Couldn't set password box trust levels to fully trusted"); log::error!("Couldn't set password box trust levels to fully trusted");
@ -713,7 +713,7 @@ impl ContextManager {
pub(crate) fn focused_app(&self) -> Option<[u32; 4]> { self.focused_context } pub(crate) fn focused_app(&self) -> Option<[u32; 4]> { self.focused_context }
pub(crate) fn forward_input(&self, input: String<4000>) -> Result<(), xous::Error> { pub(crate) fn forward_input(&self, input: String) -> Result<(), xous::Error> {
if let Some(token) = self.focused_app() { if let Some(token) = self.focused_app() {
if let Some(context) = self.contexts.get(&token) { if let Some(context) = self.contexts.get(&token) {
if let Some(input_op) = context.gotinput_id { if let Some(input_op) = context.gotinput_id {

View file

@ -25,7 +25,7 @@ pub use graphics_server::api::{TextOp, TextView};
use ime_plugin_api::{ApiToken, ImefCallback}; use ime_plugin_api::{ApiToken, ImefCallback};
use num_traits::*; use num_traits::*;
use xous::{send_message, Message, CID}; use xous::{send_message, Message, CID};
use xous_ipc::{Buffer, String}; use xous_ipc::Buffer;
#[doc = include_str!("../README.md")] #[doc = include_str!("../README.md")]
@ -321,7 +321,7 @@ impl Gam {
} }
pub fn claim_token(&self, name: &str) -> Result<Option<[u32; 4]>, xous::Error> { pub fn claim_token(&self, name: &str) -> Result<Option<[u32; 4]>, xous::Error> {
let tokenclaim = TokenClaim { token: None, name: String::<128>::from_str(name) }; let tokenclaim = TokenClaim { token: None, name: String::from(name) };
let mut buf = Buffer::into_buf(tokenclaim).or(Err(xous::Error::InternalError))?; let mut buf = Buffer::into_buf(tokenclaim).or(Err(xous::Error::InternalError))?;
buf.lend_mut(self.conn, Opcode::ClaimToken.to_u32().unwrap()).or(Err(xous::Error::InternalError))?; buf.lend_mut(self.conn, Opcode::ClaimToken.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
let returned_claim = buf.to_original::<TokenClaim, _>().unwrap(); let returned_claim = buf.to_original::<TokenClaim, _>().unwrap();
@ -331,7 +331,7 @@ impl Gam {
#[cfg(feature = "unsafe-app-loading")] #[cfg(feature = "unsafe-app-loading")]
pub fn register_name(&self, name: &str, auth_token: [u32; 4]) -> Result<(), xous::Error> { pub fn register_name(&self, name: &str, auth_token: [u32; 4]) -> Result<(), xous::Error> {
let name_registration = NameRegistration { name: String::<128>::from_str(name), auth_token }; let name_registration = NameRegistration { name: String::from(name), auth_token };
let buf = Buffer::into_buf(name_registration).or(Err(xous::Error::InternalError))?; let buf = Buffer::into_buf(name_registration).or(Err(xous::Error::InternalError))?;
buf.lend(self.conn, Opcode::RegisterName.to_u32().unwrap()).or(Err(xous::Error::InternalError))?; buf.lend(self.conn, Opcode::RegisterName.to_u32().unwrap()).or(Err(xous::Error::InternalError))?;
Ok(()) Ok(())
@ -446,7 +446,7 @@ impl Gam {
/// Failure to switch *is silent* because waiting for an activation to go through and /// Failure to switch *is silent* because waiting for an activation to go through and
/// confirm can cause a deadlock condition. /// confirm can cause a deadlock condition.
pub fn switch_to_app(&self, app_name: &str, token: [u32; 4]) -> Result<(), xous::Error> { pub fn switch_to_app(&self, app_name: &str, token: [u32; 4]) -> Result<(), xous::Error> {
let switchapp = SwitchToApp { token, app_name: String::<128>::from_str(app_name) }; let switchapp = SwitchToApp { token, app_name: String::from(app_name) };
let buf = Buffer::into_buf(switchapp).or(Err(xous::Error::InternalError))?; let buf = Buffer::into_buf(switchapp).or(Err(xous::Error::InternalError))?;
buf.send(self.conn, Opcode::SwitchToApp.to_u32().unwrap()) buf.send(self.conn, Opcode::SwitchToApp.to_u32().unwrap())
.or(Err(xous::Error::InternalError)) .or(Err(xous::Error::InternalError))
@ -454,7 +454,7 @@ impl Gam {
} }
pub fn raise_menu(&self, menu_name_str: &str) -> Result<(), xous::Error> { pub fn raise_menu(&self, menu_name_str: &str) -> Result<(), xous::Error> {
let menu_name = GamActivation { name: String::<128>::from_str(menu_name_str), result: None }; let menu_name = GamActivation { name: String::from(menu_name_str), result: None };
let mut buf = Buffer::into_buf(menu_name).or(Err(xous::Error::InternalError))?; let mut buf = Buffer::into_buf(menu_name).or(Err(xous::Error::InternalError))?;
buf.lend_mut(self.conn, Opcode::RaiseMenu.to_u32().unwrap()) buf.lend_mut(self.conn, Opcode::RaiseMenu.to_u32().unwrap())
.or(Err(xous::Error::InternalError)) .or(Err(xous::Error::InternalError))
@ -519,7 +519,7 @@ impl Gam {
let mut ret = Vec::<std::string::String>::new(); let mut ret = Vec::<std::string::String>::new();
for word in result.words { for word in result.words {
if let Some(w) = word { if let Some(w) = word {
ret.push(w.as_str().unwrap().to_string()); ret.push(w.as_str().to_string());
} }
} }
if ret.len() == 0 { Err(xous::Error::InvalidString) } else { Ok(ret) } if ret.len() == 0 { Err(xous::Error::InvalidString) } else { Ok(ret) }
@ -532,7 +532,7 @@ impl Gam {
} }
let mut ipc = Bip39Ipc::default(); let mut ipc = Bip39Ipc::default();
for (word, slot) in bip39.iter().zip(ipc.words.iter_mut()) { for (word, slot) in bip39.iter().zip(ipc.words.iter_mut()) {
*slot = Some(xous_ipc::String::from_str(word)) *slot = Some(String::from(word))
} }
let mut buf = Buffer::into_buf(ipc).or(Err(xous::Error::InternalError))?; let mut buf = Buffer::into_buf(ipc).or(Err(xous::Error::InternalError))?;
buf.lend_mut(self.conn, Opcode::Bip39toBytes.to_u32().unwrap()) buf.lend_mut(self.conn, Opcode::Bip39toBytes.to_u32().unwrap())
@ -560,7 +560,7 @@ impl Gam {
let mut suggestions = Vec::<std::string::String>::new(); let mut suggestions = Vec::<std::string::String>::new();
for word in result.words { for word in result.words {
if let Some(w) = word { if let Some(w) = word {
suggestions.push(w.as_str().unwrap().to_string()) suggestions.push(w.as_str().to_string())
} }
} }
Ok(suggestions) Ok(suggestions)

View file

@ -22,13 +22,13 @@ use graphics_server::*;
use log::info; use log::info;
use num_traits::*; use num_traits::*;
use xous::{msg_blocking_scalar_unpack, msg_scalar_unpack}; use xous::{msg_blocking_scalar_unpack, msg_scalar_unpack};
use xous_ipc::{Buffer, String}; use xous_ipc::Buffer;
/// This sets the initial app focus on boot /// This sets the initial app focus on boot
const INITIAL_APP_FOCUS: &'static str = gam::APP_NAME_SHELLCHAT; const INITIAL_APP_FOCUS: &'static str = gam::APP_NAME_SHELLCHAT;
static CB_TO_MAIN_CONN: AtomicU32 = AtomicU32::new(0); static CB_TO_MAIN_CONN: AtomicU32 = AtomicU32::new(0);
fn imef_cb(s: String<4000>) { fn imef_cb(s: String) {
if CB_TO_MAIN_CONN.load(Ordering::Relaxed) != 0 { if CB_TO_MAIN_CONN.load(Ordering::Relaxed) != 0 {
let cb_to_main_conn = CB_TO_MAIN_CONN.load(Ordering::Relaxed); let cb_to_main_conn = CB_TO_MAIN_CONN.load(Ordering::Relaxed);
let buf = xous_ipc::Buffer::into_buf(s).or(Err(xous::Error::InternalError)).unwrap(); let buf = xous_ipc::Buffer::into_buf(s).or(Err(xous::Error::InternalError)).unwrap();
@ -532,7 +532,7 @@ fn wrapped_main() -> ! {
let mut buffer = let mut buffer =
unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) }; unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
let mut tokenclaim = buffer.to_original::<TokenClaim, _>().unwrap(); let mut tokenclaim = buffer.to_original::<TokenClaim, _>().unwrap();
tokenclaim.token = context_mgr.claim_token(tokenclaim.name.as_str().unwrap()); tokenclaim.token = context_mgr.claim_token(tokenclaim.name.as_str());
buffer.replace(tokenclaim).unwrap(); buffer.replace(tokenclaim).unwrap();
} }
Some(Opcode::PredictorApiToken) => { Some(Opcode::PredictorApiToken) => {
@ -579,7 +579,7 @@ fn wrapped_main() -> ! {
move || { move || {
let switchapp = SwitchToApp { let switchapp = SwitchToApp {
token: gam_token, token: gam_token,
app_name: String::<128>::from_str(INITIAL_APP_FOCUS), app_name: String::from(INITIAL_APP_FOCUS),
}; };
let buf = Buffer::into_buf(switchapp).or(Err(xous::Error::InternalError))?; let buf = Buffer::into_buf(switchapp).or(Err(xous::Error::InternalError))?;
buf.send(conn, Opcode::SwitchToApp.to_u32().unwrap()) buf.send(conn, Opcode::SwitchToApp.to_u32().unwrap())
@ -597,7 +597,7 @@ fn wrapped_main() -> ! {
Some(Opcode::InputLine) => { Some(Opcode::InputLine) => {
// receive the keyboard input and pass it on to the context with focus // receive the keyboard input and pass it on to the context with focus
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let inputline = buffer.to_original::<String<4000>, _>().unwrap(); let inputline = buffer.to_original::<String, _>().unwrap();
log::debug!("received input line, forwarding on... {}", inputline); log::debug!("received input line, forwarding on... {}", inputline);
match context_mgr.forward_input(inputline) { match context_mgr.forward_input(inputline) {
Err(e) => log::warn!("InputLine missed its target {:?}; input ignored", e), Err(e) => log::warn!("InputLine missed its target {:?}; input ignored", e),
@ -643,12 +643,12 @@ fn wrapped_main() -> ! {
let switchapp = buffer.to_original::<SwitchToApp, _>().unwrap(); let switchapp = buffer.to_original::<SwitchToApp, _>().unwrap();
log::debug!( log::debug!(
"trying to switch to {:?} with token {:?}", "trying to switch to {:?} with token {:?}",
switchapp.app_name.as_str().unwrap(), switchapp.app_name.as_str(),
switchapp.token switchapp.token
); );
if let Some(new_app_token) = if let Some(new_app_token) =
context_mgr.find_app_token_by_name(switchapp.app_name.as_str().unwrap()) context_mgr.find_app_token_by_name(switchapp.app_name.as_str())
{ {
if new_app_token != context_mgr.focused_app().unwrap_or([0, 0, 0, 0]) { if new_app_token != context_mgr.focused_app().unwrap_or([0, 0, 0, 0]) {
// two things: // two things:
@ -683,7 +683,7 @@ fn wrapped_main() -> ! {
Ok(_) => (), Ok(_) => (),
Err(_) => log::warn!( Err(_) => log::warn!(
"failed to switch to {}, silent error!", "failed to switch to {}, silent error!",
switchapp.app_name.as_str().unwrap() switchapp.app_name.as_str()
), ),
} }
continue; continue;
@ -696,7 +696,7 @@ fn wrapped_main() -> ! {
Ok(_) => (), Ok(_) => (),
Err(_) => log::warn!( Err(_) => log::warn!(
"failed to switch to {}, silent error!", "failed to switch to {}, silent error!",
switchapp.app_name.as_str().unwrap() switchapp.app_name.as_str()
), ),
} }
} }
@ -708,7 +708,7 @@ fn wrapped_main() -> ! {
unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) }; unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
let mut activation = buffer.to_original::<GamActivation, _>().unwrap(); let mut activation = buffer.to_original::<GamActivation, _>().unwrap();
log::debug!("got request to raise context {}", activation.name); log::debug!("got request to raise context {}", activation.name);
let result = context_mgr.raise_menu(activation.name.as_str().unwrap(), &gfx, &mut canvases); let result = context_mgr.raise_menu(activation.name.as_str(), &gfx, &mut canvases);
activation.result = Some(match result { activation.result = Some(match result {
Ok(_) => ActivationResult::Success, Ok(_) => ActivationResult::Success,
Err(_) => ActivationResult::Failure, Err(_) => ActivationResult::Failure,
@ -737,7 +737,7 @@ fn wrapped_main() -> ! {
let mut phrase = Vec::<std::string::String>::new(); let mut phrase = Vec::<std::string::String>::new();
for maybe_word in spec.words { for maybe_word in spec.words {
if let Some(word) = maybe_word { if let Some(word) = maybe_word {
phrase.push(word.as_str().unwrap().to_string()); phrase.push(word.as_str().to_string());
} }
} }
match bip39::bip39_to_bytes(&phrase) { match bip39::bip39_to_bytes(&phrase) {
@ -760,7 +760,7 @@ fn wrapped_main() -> ! {
match bip39::bytes_to_bip39(&data) { match bip39::bytes_to_bip39(&data) {
Ok(phrase) => { Ok(phrase) => {
for (word, returned) in phrase.iter().zip(spec.words.iter_mut()) { for (word, returned) in phrase.iter().zip(spec.words.iter_mut()) {
*returned = Some(xous_ipc::String::from_str(word)); *returned = Some(String::from(word));
} }
} }
Err(_) => { Err(_) => {
@ -778,7 +778,7 @@ fn wrapped_main() -> ! {
let start = std::str::from_utf8(&spec.data[..spec.data_len as usize]).unwrap_or(""); let start = std::str::from_utf8(&spec.data[..spec.data_len as usize]).unwrap_or("");
let suggestions = bip39::suggest_bip39(start); let suggestions = bip39::suggest_bip39(start);
for (word, returned) in suggestions.iter().zip(spec.words.iter_mut()) { for (word, returned) in suggestions.iter().zip(spec.words.iter_mut()) {
*returned = Some(xous_ipc::String::from_str(word)); *returned = Some(String::from(word));
} }
buffer.replace(spec).unwrap(); buffer.replace(spec).unwrap();
} }

View file

@ -5,7 +5,7 @@ pub use graphics_server::*;
use num_traits::*; use num_traits::*;
#[cfg(feature = "tts")] #[cfg(feature = "tts")]
use tts_frontend::TtsFrontend; use tts_frontend::TtsFrontend;
use xous_ipc::{Buffer, String}; use xous_ipc::Buffer;
use crate::api::*; use crate::api::*;
use crate::Gam; use crate::Gam;
@ -45,7 +45,7 @@ impl<'a> Menu<'a> {
let gam = Gam::new(&xns).expect("can't connect to GAM"); let gam = Gam::new(&xns).expect("can't connect to GAM");
let authtoken = gam let authtoken = gam
.register_ux(UxRegistration { .register_ux(UxRegistration {
app_name: String::<128>::from_str(name), app_name: String::from(name),
ux_type: UxType::Menu, ux_type: UxType::Menu,
predictor: None, predictor: None,
listener: sid.to_array(), listener: sid.to_array(),
@ -117,7 +117,7 @@ impl<'a> Menu<'a> {
/// Appends a menu item to the end of the current Menu /// Appends a menu item to the end of the current Menu
pub fn add_item(&mut self, new_item: MenuItem) { pub fn add_item(&mut self, new_item: MenuItem) {
if new_item.name.as_str().unwrap() == "🔇" { if new_item.name.as_str() == "🔇" {
// suppress the addition of menu items that are not applicable for a given locale // suppress the addition of menu items that are not applicable for a given locale
return; return;
} }
@ -146,7 +146,7 @@ impl<'a> Menu<'a> {
// Attempts to insert a MenuItem at the index given. This displaces the item at that index down // Attempts to insert a MenuItem at the index given. This displaces the item at that index down
// by one slot. Returns false if the index is invalid. // by one slot. Returns false if the index is invalid.
pub fn insert_item(&mut self, new_item: MenuItem, at: usize) -> bool { pub fn insert_item(&mut self, new_item: MenuItem, at: usize) -> bool {
if new_item.name.as_str().unwrap() == "🔇" { if new_item.name.as_str() == "🔇" {
// suppress the addition of menu items that are not applicable for a given locale // suppress the addition of menu items that are not applicable for a given locale
return false; return false;
} }
@ -184,7 +184,7 @@ impl<'a> Menu<'a> {
// something) // something)
pub fn delete_item(&mut self, item: &str) -> bool { pub fn delete_item(&mut self, item: &str) -> bool {
let len_before = self.items.len(); let len_before = self.items.len();
self.items.retain(|&candidate| candidate.name.as_str().unwrap() != item); self.items.retain(|&candidate| candidate.name.as_str() != item);
// now, recompute the height // now, recompute the height
let mut total_items = self.num_items(); let mut total_items = self.num_items();
@ -220,11 +220,11 @@ impl<'a> Menu<'a> {
if with_marker { if with_marker {
write!(item_tv.text, "\u{25B6}").unwrap(); write!(item_tv.text, "\u{25B6}").unwrap();
#[cfg(feature = "tts")] #[cfg(feature = "tts")]
self.tts.tts_simple(item.name.as_str().unwrap()).unwrap(); self.tts.tts_simple(item.name.as_str()).unwrap();
} else { } else {
write!(item_tv.text, "\t").unwrap(); write!(item_tv.text, "\t").unwrap();
} }
write!(item_tv.text, "{}", item.name.as_str().unwrap()).unwrap(); write!(item_tv.text, "{}", item.name.as_str()).unwrap();
item_tv.draw_border = false; item_tv.draw_border = false;
item_tv.style = crate::SYSTEM_STYLE; item_tv.style = crate::SYSTEM_STYLE;
item_tv.margin = Point::new(0, 0); item_tv.margin = Point::new(0, 0);
@ -371,7 +371,7 @@ impl<'a> Menu<'a> {
#[cfg(feature = "tts")] #[cfg(feature = "tts")]
{ {
let mut phrase = "select ".to_string(); let mut phrase = "select ".to_string();
phrase.push_str(mi.name.as_str().unwrap()); phrase.push_str(mi.name.as_str());
self.tts.tts_blocking(&phrase).unwrap(); self.tts.tts_blocking(&phrase).unwrap();
} }
match mi.action_payload { match mi.action_payload {
@ -449,7 +449,7 @@ impl MenuMatic {
pub fn delete_item(&self, item_name: &str) -> bool { pub fn delete_item(&self, item_name: &str) -> bool {
let mm = MenuManagement { let mm = MenuManagement {
item: MenuItem { item: MenuItem {
name: String::from_str(item_name), name: String::from(item_name),
// the rest are ignored // the rest are ignored
action_conn: None, action_conn: None,
action_opcode: 0, action_opcode: 0,
@ -468,7 +468,7 @@ impl MenuMatic {
let op = MenuManagement { let op = MenuManagement {
item: MenuItem { item: MenuItem {
// dummy item, not used // dummy item, not used
name: xous_ipc::String::<64>::new(), name: String::new(),
action_conn: None, action_conn: None,
action_opcode: 0, action_opcode: 0,
action_payload: MenuPayload::Scalar([0, 0, 0, 0]), action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
@ -576,7 +576,7 @@ pub fn menu_matic(
} }
} }
MenuMgrOp::DeleteItem => { MenuMgrOp::DeleteItem => {
if !menu.lock().unwrap().delete_item(mgmt.item.name.as_str().unwrap()) { if !menu.lock().unwrap().delete_item(mgmt.item.name.as_str()) {
mgmt.op = MenuMgrOp::Err; mgmt.op = MenuMgrOp::Err;
} else { } else {
mgmt.op = MenuMgrOp::Ok; mgmt.op = MenuMgrOp::Ok;

View file

@ -26,7 +26,7 @@ use enum_dispatch::enum_dispatch;
pub use graphics_server::api::GlyphStyle; pub use graphics_server::api::GlyphStyle;
use graphics_server::api::*; use graphics_server::api::*;
use num_traits::*; use num_traits::*;
use xous_ipc::{Buffer, String}; use xous_ipc::Buffer;
use crate::api::*; use crate::api::*;
use crate::Gam; use crate::Gam;
@ -69,11 +69,11 @@ pub enum ModalOpcode {
/// We use a new type for item names, so that it's easy to resize this as needed. /// We use a new type for item names, so that it's easy to resize this as needed.
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
pub struct ItemName(String<128>); pub struct ItemName(String);
impl ItemName { impl ItemName {
pub fn new(name: &str) -> Self { ItemName(String::<128>::from_str(name)) } pub fn new(name: &str) -> Self { ItemName(String::from(name)) }
pub fn as_str(&self) -> &str { self.0.as_str().expect("couldn't convert item into string") } pub fn as_str(&self) -> &str { self.0.as_str() }
} }
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone, Eq, PartialEq, Default)] #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone, Eq, PartialEq, Default)]
@ -87,8 +87,8 @@ pub struct Bip39EntryPayload {
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone, Eq, PartialEq, Default)] #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone, Eq, PartialEq, Default)]
pub struct TextEntryPayload { pub struct TextEntryPayload {
dirty: bool, dirty: bool,
pub content: String<256>, pub content: String,
pub placeholder: Option<String<256>>, pub placeholder: Option<String>,
pub placeholder_persist: bool, pub placeholder_persist: bool,
pub insertion_point: Option<usize>, pub insertion_point: Option<usize>,
} }
@ -104,7 +104,7 @@ impl TextEntryPayload {
} }
} }
pub fn new_with_fields(content: String<256>, placeholder: Option<String<256>>) -> Self { pub fn new_with_fields(content: String, placeholder: Option<String>) -> Self {
TextEntryPayload { TextEntryPayload {
dirty: false, dirty: false,
content, content,
@ -118,7 +118,7 @@ impl TextEntryPayload {
/// password fields. /// password fields.
pub fn volatile_clear(&mut self) { self.content.volatile_clear(); } pub fn volatile_clear(&mut self) { self.content.volatile_clear(); }
pub fn as_str(&self) -> &str { self.content.as_str().expect("couldn't convert textentry string") } pub fn as_str(&self) -> &str { self.content.as_str() }
} }
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] #[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
@ -207,7 +207,7 @@ pub struct Modal<'a> {
pub inverted: bool, pub inverted: bool,
pub style: GlyphStyle, pub style: GlyphStyle,
pub helper_data: Option<Buffer<'a>>, pub helper_data: Option<Buffer<'a>>,
pub name: String<128>, pub name: String,
// optimize draw time // optimize draw time
top_dirty: bool, top_dirty: bool,
@ -337,7 +337,7 @@ impl<'a> Modal<'a> {
let gam = Gam::new(&xns).expect("can't connect to GAM"); let gam = Gam::new(&xns).expect("can't connect to GAM");
let authtoken = gam let authtoken = gam
.register_ux(UxRegistration { .register_ux(UxRegistration {
app_name: String::<128>::from_str(name), app_name: String::from(name),
ux_type: UxType::Modal, ux_type: UxType::Modal,
predictor: None, predictor: None,
listener: sid.to_array(), listener: sid.to_array(),
@ -391,7 +391,7 @@ impl<'a> Modal<'a> {
inverted, inverted,
style, style,
helper_data: None, helper_data: None,
name: String::<128>::from_str(name), name: String::from(name),
top_dirty: true, top_dirty: true,
bot_dirty: true, bot_dirty: true,
top_memoized_height: None, top_memoized_height: None,
@ -597,7 +597,7 @@ impl<'a> Modal<'a> {
self.bot_dirty = true; self.bot_dirty = true;
} }
let mut top_tv_temp = String::<3072>::new(); // size matches that used in TextView let mut top_tv_temp = String::new(); // size matches that used in TextView
if let Some(top_text) = update_top_text { if let Some(top_text) = update_top_text {
write!(top_tv_temp, "{}", top_text).unwrap(); write!(top_tv_temp, "{}", top_text).unwrap();
} else { } else {
@ -611,7 +611,7 @@ impl<'a> Modal<'a> {
Some(top_tv_temp.to_str()) Some(top_tv_temp.to_str())
}; };
let mut bot_tv_temp = String::<3072>::new(); // size matches that used in TextView let mut bot_tv_temp = String::new(); // size matches that used in TextView
if let Some(bot_text) = update_bot_text { if let Some(bot_text) = update_bot_text {
write!(bot_tv_temp, "{}", bot_text).unwrap(); write!(bot_tv_temp, "{}", bot_text).unwrap();
} else { } else {

View file

@ -19,7 +19,7 @@ pub struct Slider {
pub is_progressbar: bool, pub is_progressbar: bool,
pub is_password: bool, pub is_password: bool,
pub show_legend: bool, pub show_legend: bool,
pub units: xous_ipc::String<8>, pub units: String,
} }
impl Slider { impl Slider {
pub fn new( pub fn new(
@ -35,16 +35,16 @@ impl Slider {
) -> Self { ) -> Self {
let checked_units = if let Some(unit_str) = units { let checked_units = if let Some(unit_str) = units {
if unit_str.len() < 8 { if unit_str.len() < 8 {
String::<8>::from_str(unit_str) String::from(unit_str)
} else { } else {
log::error!( log::error!(
"Unit string must be less than 8 *bytes* long (are you using unicode?), ignoring length {} string", "Unit string must be less than 8 *bytes* long (are you using unicode?), ignoring length {} string",
unit_str.len() unit_str.len()
); );
String::<8>::new() String::new()
} }
} else { } else {
String::<8>::new() // just populate with a blank string, easier than checking Some/None later on everywhere String::new() // just populate with a blank string, easier than checking Some/None later on everywhere
}; };
Slider { Slider {