mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
Merge branch 'main' of github.com:betrusted-io/xous-core into main
This commit is contained in:
commit
4f75cd76a8
13 changed files with 411 additions and 44 deletions
|
|
@ -1,4 +1,32 @@
|
|||
{
|
||||
"mtxchat.busy.connecting": {
|
||||
"en": "Connecting...",
|
||||
"en-tts": "Connecting..."
|
||||
},
|
||||
"mtxchat.busy.updating": {
|
||||
"en": "Updating...",
|
||||
"en-tts": "Updating..."
|
||||
},
|
||||
"mtxchat.busy.sending": {
|
||||
"en": "Sending...",
|
||||
"en-tts": "Sending..."
|
||||
},
|
||||
"mtxchat.busy.room_id": {
|
||||
"en": "Getting room ID...",
|
||||
"en-tts": "Getting room ID..."
|
||||
},
|
||||
"mtxchat.busy.login": {
|
||||
"en": "Logging in...",
|
||||
"en-tts": "Logging in..."
|
||||
},
|
||||
"mtxchat.busy.rx_events": {
|
||||
"en": "Receiving events...",
|
||||
"en-tts": "Receiving events..."
|
||||
},
|
||||
"mtxchat.busy.new_listen": {
|
||||
"en": "Syncing all events from server...",
|
||||
"en-tts": "Syncing all events from server..."
|
||||
},
|
||||
"mtxchat.clock.warning": {
|
||||
"en": "WARNING: clock not set",
|
||||
"en-tts": "WARNING: clock not set",
|
||||
|
|
@ -6,6 +34,10 @@
|
|||
"ja": "WARNING: clock not set *EN*",
|
||||
"zh": "WARNING: clock not set *EN*"
|
||||
},
|
||||
"mtxchat.status.default" : {
|
||||
"en": "Use ← for login menu",
|
||||
"en-tts": "Use ← for login menu"
|
||||
},
|
||||
"mtxchat.filter.failed": {
|
||||
"en": "error: could not create filter",
|
||||
"en-tts": "error: could not create filter",
|
||||
|
|
@ -225,9 +257,9 @@
|
|||
"ja": "WiFi not connected. Entering read-only mode *EN*",
|
||||
"zh": "WiFi not connected. Entering read-only mode *EN*"
|
||||
},
|
||||
"mtxchat.listen.patience": {
|
||||
"en": "It takes a while to get new events from the [matrix] server.\nPlease be patient :-)",
|
||||
"en-tts": "It takes a while to get new events from the [matrix] server.\nPlease be patient."
|
||||
"mtxchat.wifi.warning_status": {
|
||||
"en": "No connection! Read-only.",
|
||||
"en-tts": "No connection! Read-only."
|
||||
},
|
||||
"mtxchat.close.item": {
|
||||
"en": "Close menu",
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use listen::listen;
|
|||
use locales::t;
|
||||
use modals::Modals;
|
||||
use pddb::Pddb;
|
||||
use ticktimer_server::Ticktimer;
|
||||
use std::fmt::Write as _;
|
||||
use std::io::{Error, ErrorKind, Read, Write as StdWrite};
|
||||
use std::sync::Arc;
|
||||
|
|
@ -35,8 +36,9 @@ const USER_DOMAIN_KEY: &str = "user_domain";
|
|||
|
||||
const DOMAIN_MATRIX: &str = "matrix.org";
|
||||
|
||||
const MTX_LONG_TIMEOUT: i32 = 60000; // ms
|
||||
const WIFI_TIMEOUT: u32 = 10; // seconds
|
||||
const MTX_LONG_TIMEOUT_MS: i32 = 60000; // ms
|
||||
const WIFI_TIMEOUT_MS: u32 = 30_000; // ms
|
||||
const SEND_RETRIES: usize = 3;
|
||||
|
||||
pub const CLOCK_NOT_SET_ID: usize = 1;
|
||||
pub const PDDB_NOT_MOUNTED_ID: usize = 2;
|
||||
|
|
@ -83,6 +85,7 @@ pub struct MtxChat<'a> {
|
|||
modals: Modals,
|
||||
new_username: bool,
|
||||
new_room: bool,
|
||||
tt: Ticktimer,
|
||||
}
|
||||
impl<'a> MtxChat<'a> {
|
||||
pub fn new(chat: &Chat) -> MtxChat {
|
||||
|
|
@ -91,6 +94,8 @@ impl<'a> MtxChat<'a> {
|
|||
let trng = Trng::new(&xns).unwrap();
|
||||
let pddb = pddb::Pddb::new();
|
||||
pddb.try_mount();
|
||||
let status = t!("mtxchat.status.default", locales::LANG).to_owned();
|
||||
chat.set_status_text(&status);
|
||||
MtxChat {
|
||||
chat: chat,
|
||||
trng: trng,
|
||||
|
|
@ -113,6 +118,7 @@ impl<'a> MtxChat<'a> {
|
|||
modals: modals,
|
||||
new_username: false,
|
||||
new_room: false,
|
||||
tt: ticktimer_server::Ticktimer::new().unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -248,9 +254,8 @@ impl<'a> MtxChat<'a> {
|
|||
self.listen();
|
||||
if self.new_room {
|
||||
self.new_room = false;
|
||||
self.modals
|
||||
.show_notification(t!("mtxchat.listen.patience", locales::LANG), None)
|
||||
.expect("notification failed");
|
||||
self.chat.set_status_text(t!("mtxchat.busy.new_listen", locales::LANG));
|
||||
self.chat.set_busy_state(true);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
|
|
@ -277,6 +282,8 @@ impl<'a> MtxChat<'a> {
|
|||
}
|
||||
|
||||
pub fn login(&mut self) -> bool {
|
||||
self.chat.set_status_text(t!("mtxchat.busy.login", locales::LANG));
|
||||
self.chat.set_busy_state(true);
|
||||
self.token = self.get(TOKEN_KEY).unwrap_or(None);
|
||||
self.logged_in = false;
|
||||
|
||||
|
|
@ -335,6 +342,7 @@ impl<'a> MtxChat<'a> {
|
|||
self.unset(USER_DOMAIN_KEY)
|
||||
.expect("failed to unset user domain");
|
||||
}
|
||||
self.chat.set_busy_state(false);
|
||||
self.logged_in
|
||||
}
|
||||
|
||||
|
|
@ -433,12 +441,16 @@ impl<'a> MtxChat<'a> {
|
|||
(true, Some(token), Some(user_domain), Some(room_alias)) => {
|
||||
let mut url = Url::parse("https://matrix.org").unwrap();
|
||||
url.set_host(Some(user_domain)).expect("failed to set host");
|
||||
self.chat.set_status_text(t!("mtxchat.busy.room_id", locales::LANG));
|
||||
self.chat.set_busy_state(true);
|
||||
if let Some(room_id) =
|
||||
web::get_room_id(&mut url, &room_alias, &token, &mut self.agent)
|
||||
{
|
||||
self.set_debug(ROOM_ID_KEY, &room_id);
|
||||
self.chat.set_busy_state(false);
|
||||
return Some(room_id);
|
||||
} else {
|
||||
self.chat.set_busy_state(false);
|
||||
"failed to get room_id"
|
||||
}
|
||||
}
|
||||
|
|
@ -626,14 +638,25 @@ impl<'a> MtxChat<'a> {
|
|||
&self.room_id,
|
||||
) {
|
||||
(true, Some(token), Some(user_domain), Some(room_id)) => {
|
||||
self.chat.set_status_text(t!("mtxchat.busy.sending", locales::LANG));
|
||||
self.chat.set_busy_state(true);
|
||||
log::info!("txn_id = {}", txn_id);
|
||||
let mut url = Url::parse("https://matrix.org").unwrap();
|
||||
url.set_host(Some(user_domain)).expect("failed to set host");
|
||||
if web::send_message(&mut url, &room_id, &text, &txn_id, token, &mut self.agent) {
|
||||
let mut success = false;
|
||||
for _ in 0..SEND_RETRIES {
|
||||
if web::send_message(&mut url, &room_id, &text, &txn_id, token, &mut self.agent) {
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
let r = if success {
|
||||
"SENT"
|
||||
} else {
|
||||
"FAILED TO SEND"
|
||||
}
|
||||
};
|
||||
self.chat.set_busy_state(false);
|
||||
r
|
||||
}
|
||||
(false, _, _, _) => "Not logged in",
|
||||
(_, None, _, _) => "No token set",
|
||||
|
|
@ -661,25 +684,22 @@ impl<'a> MtxChat<'a> {
|
|||
|
||||
while self.wifi_try_modal() {
|
||||
self.netmgr.connection_manager_wifi_on_and_run().unwrap();
|
||||
self.modals
|
||||
.start_progress("Connecting ...", 0, 10, 0)
|
||||
.expect("no progress bar");
|
||||
let tt = ticktimer_server::Ticktimer::new().unwrap();
|
||||
for wait in 0..WIFI_TIMEOUT {
|
||||
tt.sleep_ms(1000).unwrap();
|
||||
self.modals
|
||||
.update_progress(wait)
|
||||
.expect("no progress update");
|
||||
self.chat.set_status_text(t!("mtxchat.busy.connecting", locales::LANG));
|
||||
self.chat.set_busy_state(true);
|
||||
let start = self.tt.elapsed_ms();
|
||||
while self.tt.elapsed_ms() - start < WIFI_TIMEOUT_MS as u64 {
|
||||
if let Some(conf) = self.netmgr.get_ipv4_config() {
|
||||
if conf.dhcp == com_rs::DhcpState::Bound {
|
||||
self.modals
|
||||
.finish_progress()
|
||||
.expect("failed progress finish");
|
||||
self.chat.set_busy_state(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
self.tt.sleep_ms(1000).unwrap();
|
||||
}
|
||||
self.modals.show_notification(t!("mtxchat.wifi.warning", locales::LANG), None).unwrap();
|
||||
}
|
||||
self.chat.set_busy_state(false);
|
||||
self.chat.set_status_text(t!("mtxchat.wifi.warning_status", locales::LANG));
|
||||
false
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use crate::{get_username, web, MTX_LONG_TIMEOUT};
|
||||
use crate::{get_username, web, MTX_LONG_TIMEOUT_MS};
|
||||
use chat::ChatOp;
|
||||
use modals::Modals;
|
||||
use std::sync::Arc;
|
||||
use tls::xtls::TlsConnector;
|
||||
use url::Url;
|
||||
use xous::CID;
|
||||
use xous_ipc::Buffer;
|
||||
use locales::t;
|
||||
|
||||
pub fn listen(
|
||||
url: &mut Url,
|
||||
|
|
@ -16,9 +16,7 @@ pub fn listen(
|
|||
dialogue_id: &str,
|
||||
chat_cid: CID,
|
||||
) {
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
let modals = Modals::new(&xns).expect("can't connect to Modals server");
|
||||
log::info!("client_sync for {} ms...", MTX_LONG_TIMEOUT);
|
||||
log::info!("client_sync for {} ms...", MTX_LONG_TIMEOUT_MS);
|
||||
|
||||
let mut agent = ureq::builder()
|
||||
.tls_connector(Arc::new(TlsConnector{}))
|
||||
|
|
@ -27,7 +25,7 @@ pub fn listen(
|
|||
url,
|
||||
filter,
|
||||
since,
|
||||
MTX_LONG_TIMEOUT,
|
||||
MTX_LONG_TIMEOUT_MS,
|
||||
&room_id,
|
||||
&token,
|
||||
&mut agent,
|
||||
|
|
@ -38,9 +36,8 @@ pub fn listen(
|
|||
// TODO resolve suspected race condition
|
||||
// This progress modal is masking a bug by slowing the loop down
|
||||
// Precursor "Guru Mediation" `voilated: nonNull::new_unchecked`
|
||||
modals
|
||||
.start_progress("Receiving events ...", 0, events.len() as u32, 0)
|
||||
.expect("no progress bar");
|
||||
chat::cf_set_status_text(chat_cid, t!("mtxchat.busy.rx_events", locales::LANG));
|
||||
chat::cf_set_busy_state(chat_cid, true);
|
||||
let mut event_count = 0;
|
||||
for event in events {
|
||||
let sender = event.sender.unwrap_or("anon".to_string());
|
||||
|
|
@ -58,12 +55,14 @@ pub fn listen(
|
|||
}
|
||||
.expect("failed to convert post into buffer");
|
||||
event_count += 1;
|
||||
modals
|
||||
.update_progress(event_count)
|
||||
.expect("no progress update");
|
||||
chat::cf_set_status_text(chat_cid,
|
||||
&format!("{} {}",
|
||||
t!("mtxchat.busy.rx_events", locales::LANG),
|
||||
event_count)
|
||||
);
|
||||
}
|
||||
}
|
||||
modals.finish_progress().expect("failed progress finish");
|
||||
chat::cf_set_busy_state(chat_cid, false);
|
||||
// trigger the chat ui to save the dialogue to the pddb
|
||||
xous::send_message(
|
||||
chat_cid,
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@
|
|||
"en": "no dialogues available to read",
|
||||
"en-tts": "no dialogues available to read"
|
||||
},
|
||||
"chat.status.initial" : {
|
||||
"en": "Use ← to raise menu",
|
||||
"en-tts": "Use ← to raise menu"
|
||||
},
|
||||
"chat.help.navigation": {
|
||||
"en": "use ↑ & ↓ to scroll thru old posts\nuse ← & → to show menus\nF1-F4 dont do anything yet.",
|
||||
"en-tts": "use ↑ & ↓ to scroll thru old posts\nuse ← & → to show menus\nF1-F4 dont do anything yet."
|
||||
|
|
|
|||
|
|
@ -36,10 +36,27 @@ pub enum ChatOp {
|
|||
/// Find a Post by timestamp and Author
|
||||
PostFind,
|
||||
PostFlag,
|
||||
/// Set status bar text
|
||||
SetStatusText,
|
||||
/// Run or stop the busy animation.
|
||||
SetBusyAnimationState,
|
||||
/// Set the status idle text (to be shown when exiting all busy states)
|
||||
SetStatusIdleText,
|
||||
/// Update just the state of the busy animation, if any. Internal opcode.
|
||||
/// Will skip the update if called too often.
|
||||
UpdateBusy,
|
||||
/// Force update the busy bar, without rate throttling. Internal opcode.
|
||||
UpdateBusyForced,
|
||||
/// exit the application
|
||||
Quit,
|
||||
}
|
||||
|
||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||
pub(crate) enum BusyAnimOp {
|
||||
Start,
|
||||
Pump,
|
||||
}
|
||||
|
||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||
pub enum IconOp {
|
||||
PostMenu = 0,
|
||||
|
|
@ -120,3 +137,8 @@ pub enum AuthorFlag {
|
|||
Hidden,
|
||||
Right,
|
||||
}
|
||||
|
||||
#[derive(Archive, Serialize, Deserialize, Debug)]
|
||||
pub struct BusyMessage {
|
||||
pub busy_msg: xous_ipc::String<128>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,13 +4,15 @@ pub mod icontray;
|
|||
pub mod ui;
|
||||
|
||||
pub use api::*;
|
||||
pub use ui::BUSY_ANIMATION_RATE_MS;
|
||||
use gam::MenuItem;
|
||||
use num_traits::FromPrimitive;
|
||||
use std::convert::TryInto;
|
||||
use std::thread;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use std::sync::{Arc, atomic::AtomicBool, atomic::Ordering};
|
||||
|
||||
use xous::{Error, CID, SID};
|
||||
use xous::{Error, CID, SID, msg_scalar_unpack};
|
||||
use xous_ipc::Buffer;
|
||||
|
||||
pub struct Chat {
|
||||
|
|
@ -40,6 +42,18 @@ impl Chat {
|
|||
let chat_sid = xous::create_server().unwrap();
|
||||
let chat_cid = xous::connect(chat_sid).unwrap();
|
||||
|
||||
let busy_bumper = xous::create_server().unwrap();
|
||||
let busy_bumper_cid = xous::connect(busy_bumper).unwrap();
|
||||
|
||||
log::info!("starting idle animation runner");
|
||||
let run_busy_animation = Arc::new(AtomicBool::new(false));
|
||||
thread::spawn({
|
||||
let run_busy_animation = run_busy_animation.clone();
|
||||
move || {
|
||||
busy_animator(busy_bumper, busy_bumper_cid, chat_cid, run_busy_animation);
|
||||
}
|
||||
});
|
||||
|
||||
log::info!("Starting chat UI server",);
|
||||
thread::spawn({
|
||||
move || {
|
||||
|
|
@ -51,6 +65,8 @@ impl Chat {
|
|||
opcode_post,
|
||||
opcode_event,
|
||||
opcode_rawkeys,
|
||||
run_busy_animation,
|
||||
busy_bumper_cid,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
@ -222,6 +238,91 @@ impl Chat {
|
|||
.map(|_| ())
|
||||
.expect("failed to Redraw Chat UI");
|
||||
}
|
||||
|
||||
/// Set the status bar text.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// `msg` - the text to show
|
||||
///
|
||||
/// This method implements the latest recommendation of panicing on internal errors.
|
||||
pub fn set_status_text(&self, msg: &str) {
|
||||
let bm = BusyMessage {
|
||||
busy_msg: xous_ipc::String::from_str(msg)
|
||||
};
|
||||
Buffer::into_buf(bm).expect("internal error").send(
|
||||
self.cid, ChatOp::SetStatusText as u32
|
||||
).expect("internal error");
|
||||
}
|
||||
|
||||
pub fn set_busy_state(&self, run: bool) {
|
||||
xous::send_message(
|
||||
self.cid,
|
||||
xous::Message::new_scalar(ChatOp::SetBusyAnimationState as usize,
|
||||
if run { 1 } else { 0 },
|
||||
0, 0, 0),
|
||||
)
|
||||
.map(|_| ())
|
||||
.expect("internal error");
|
||||
}
|
||||
|
||||
/// Set status bar text when system is idle.
|
||||
/// This is a convenience so we don't have to track the ins/outs of busy/idle state
|
||||
/// and update the text, especially when we have multiple potential servers vying
|
||||
/// to set a busy state.
|
||||
pub fn set_status_idle_text(&self, msg: &str) {
|
||||
let bm = BusyMessage {
|
||||
busy_msg: xous_ipc::String::from_str(msg)
|
||||
};
|
||||
Buffer::into_buf(bm).expect("internal error").send(
|
||||
self.cid, ChatOp::SetStatusIdleText as u32
|
||||
).expect("internal error");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Helper server that pumps the busy animation state until instructed to stop.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `busy_bumper` - the server ID to use for the helper server
|
||||
/// * `busy_bumper_cid` - the corresponding connection ID
|
||||
/// * `chat_cid` - the CID to the main chat loop, used to initiate redraw events as necessary
|
||||
/// * `run_busy_animation` - a shared `AtomicBool` which, when `true`, causes the loop to reschedule itself to run.
|
||||
pub fn busy_animator(
|
||||
busy_bumper: SID,
|
||||
busy_bumper_cid : CID,
|
||||
chat_cid: CID,
|
||||
run_busy_animation: Arc<AtomicBool>) {
|
||||
let tt = ticktimer_server::Ticktimer::new().unwrap();
|
||||
loop {
|
||||
let msg = xous::receive_message(busy_bumper).unwrap();
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(BusyAnimOp::Start) => {
|
||||
tt.sleep_ms(crate::BUSY_ANIMATION_RATE_MS).unwrap();
|
||||
xous::try_send_message(busy_bumper_cid,
|
||||
xous::Message::new_scalar(
|
||||
BusyAnimOp::Pump as usize, 0, 0, 0, 0)
|
||||
).ok();
|
||||
}
|
||||
Some(BusyAnimOp::Pump) => {
|
||||
if run_busy_animation.load(Ordering::SeqCst) {
|
||||
xous::try_send_message(chat_cid,
|
||||
xous::Message::new_scalar(
|
||||
ChatOp::UpdateBusy as usize, 0, 0, 0, 0)
|
||||
).ok();
|
||||
tt.sleep_ms(crate::BUSY_ANIMATION_RATE_MS).unwrap();
|
||||
xous::try_send_message(busy_bumper_cid,
|
||||
xous::Message::new_scalar(
|
||||
BusyAnimOp::Pump as usize, 0, 0, 0, 0)
|
||||
).ok();
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
log::warn!("Unexpected message: {:?}", msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The Chat UI server a manages a Chat UI to read a display and navigate a
|
||||
|
|
@ -245,6 +346,8 @@ pub fn server(
|
|||
opcode_post: Option<usize>,
|
||||
opcode_event: Option<usize>,
|
||||
opcode_rawkeys: Option<usize>,
|
||||
run_busy_animation: Arc<AtomicBool>,
|
||||
busy_bumper_cid: CID,
|
||||
) -> ! {
|
||||
//log_server::init_wait().unwrap();
|
||||
log::set_max_level(log::LevelFilter::Info);
|
||||
|
|
@ -257,6 +360,41 @@ pub fn server(
|
|||
let msg = xous::receive_message(sid).unwrap();
|
||||
log::debug!("got message {:?}", msg);
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(ChatOp::UpdateBusy) => {
|
||||
ui.redraw_busy().expect("CHAT couldn't redraw");
|
||||
}
|
||||
Some(ChatOp::UpdateBusyForced) => {
|
||||
ui.redraw_status_forced().expect("CHAT couldn't redraw");
|
||||
}
|
||||
Some(ChatOp::SetStatusText) => {
|
||||
let buffer = unsafe {
|
||||
Buffer::from_memory_message(msg.body.memory_message().unwrap())
|
||||
};
|
||||
let s = buffer.to_original::<BusyMessage, _>().unwrap();
|
||||
ui.set_status_text(s.busy_msg.as_str().unwrap());
|
||||
}
|
||||
Some(ChatOp::SetStatusIdleText) => {
|
||||
let buffer = unsafe {
|
||||
Buffer::from_memory_message(msg.body.memory_message().unwrap())
|
||||
};
|
||||
let s = buffer.to_original::<BusyMessage, _>().unwrap();
|
||||
ui.set_status_idle_text(s.busy_msg.as_str().unwrap());
|
||||
}
|
||||
Some(ChatOp::SetBusyAnimationState) => msg_scalar_unpack!(msg, state, _, _, _, {
|
||||
if state != 0 {
|
||||
ui.set_busy_state(true);
|
||||
if !run_busy_animation.swap(true, Ordering::SeqCst) {
|
||||
// only send off the Pump request on the transition from false->true; this causes the machine to run
|
||||
xous::try_send_message(busy_bumper_cid,
|
||||
xous::Message::new_scalar(
|
||||
BusyAnimOp::Pump as usize, 0, 0, 0, 0)
|
||||
).ok();
|
||||
}
|
||||
} else {
|
||||
run_busy_animation.store(false, Ordering::SeqCst);
|
||||
ui.set_busy_state(false);
|
||||
}
|
||||
}),
|
||||
Some(ChatOp::DialogueSave) => {
|
||||
log::info!("ChatOp::DialogueSave");
|
||||
ui.dialogue_save().expect("failed to save Dialogue");
|
||||
|
|
@ -456,3 +594,25 @@ pub fn now() -> u64 {
|
|||
.try_into()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// "context-free" (cf) communication with the chat object.
|
||||
/// This is accomplished by making a copy of the connection to the chat server.
|
||||
pub fn cf_set_status_text(chat_cid: xous::CID, msg: &str) {
|
||||
let bm = BusyMessage {
|
||||
busy_msg: xous_ipc::String::from_str(msg)
|
||||
};
|
||||
Buffer::into_buf(bm).expect("internal error").send(
|
||||
chat_cid, ChatOp::SetStatusText as u32
|
||||
).expect("internal error");
|
||||
}
|
||||
|
||||
pub fn cf_set_busy_state(chat_cid: xous::CID, run: bool) {
|
||||
xous::send_message(
|
||||
chat_cid,
|
||||
xous::Message::new_scalar(ChatOp::SetBusyAnimationState as usize,
|
||||
if run { 1 } else { 0 },
|
||||
0, 0, 0),
|
||||
)
|
||||
.map(|_| ())
|
||||
.expect("internal error");
|
||||
}
|
||||
|
|
@ -3,9 +3,12 @@
|
|||
|
||||
mod api;
|
||||
use api::*;
|
||||
use num_traits::FromPrimitive;
|
||||
use std::thread;
|
||||
|
||||
use xous::{Error, CID, SID};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub fn main() -> ! {
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
|
|
@ -17,10 +20,21 @@ pub fn main() -> ! {
|
|||
let chat_sid = xous::create_server().unwrap();
|
||||
let chat_cid = xous::connect(chat_sid).unwrap();
|
||||
|
||||
let busy_bumper = xous::create_server().unwrap();
|
||||
let busy_bumper_cid = xous::connect(busy_bumper).unwrap();
|
||||
|
||||
log::info!("starting idle animation runner");
|
||||
let run_busy_animation = Arc::new(AtomicBool::new(false));
|
||||
thread::spawn({
|
||||
let run_busy_animation = run_busy_animation.clone();
|
||||
move || {
|
||||
busy_animator(busy_bumper, busy_bumper_cid, chat_cid, run_busy_animation);
|
||||
}
|
||||
});
|
||||
log::info!("Starting chat server",);
|
||||
thread::spawn({
|
||||
move || {
|
||||
server(chat_sid, None, None);
|
||||
server(chat_sid, None, None, run_busy_animation, busy_bumper_cid);
|
||||
}
|
||||
});
|
||||
xous::terminate_process(0)
|
||||
|
|
|
|||
|
|
@ -4,21 +4,25 @@ use crate::icontray::Icontray;
|
|||
use dialogue::{post::Post, Dialogue};
|
||||
use gam::{menu_matic, MenuMatic, UxRegistration};
|
||||
use graphics_server::api::GlyphStyle;
|
||||
use graphics_server::{DrawStyle, Gid, PixelColor, Point, Rectangle, TextBounds, TextView};
|
||||
use graphics_server::{DrawStyle, Gid, PixelColor, Point, Rectangle, TextBounds, TextView, Line};
|
||||
use locales::t;
|
||||
use modals::Modals;
|
||||
use rkyv::de::deserializers::AllocDeserializer;
|
||||
use rkyv::ser::serializers::WriteSerializer;
|
||||
use rkyv::ser::Serializer;
|
||||
use rkyv::Deserialize;
|
||||
use ticktimer_server::Ticktimer;
|
||||
use std::cmp::min;
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt::Write as TextWrite;
|
||||
|
||||
use std::io::{Error, ErrorKind, Read, Write};
|
||||
use xous::{MessageEnvelope, CID};
|
||||
|
||||
use xous_names::XousNames;
|
||||
|
||||
pub const BUSY_ANIMATION_RATE_MS: usize = 200;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) struct Ui {
|
||||
// optional structures that indicate new input to the Chat loop per iteration
|
||||
|
|
@ -34,6 +38,8 @@ pub(crate) struct Ui {
|
|||
dialogue: Option<Dialogue>,
|
||||
|
||||
// Callbacks:
|
||||
// callback to our own server
|
||||
self_cid: CID,
|
||||
// optional SID of the "Owner" Chat App to receive UI-events
|
||||
app_cid: Option<CID>,
|
||||
// optional opcode ID to process UI-event msgs
|
||||
|
|
@ -42,6 +48,7 @@ pub(crate) struct Ui {
|
|||
canvas: Gid,
|
||||
gam: gam::Gam,
|
||||
modals: Modals,
|
||||
tt: Ticktimer,
|
||||
|
||||
// variables regarding the posts currently onscreen
|
||||
// the selected post is hilighted onscreen and the focus of the msg menu F4
|
||||
|
|
@ -53,6 +60,14 @@ pub(crate) struct Ui {
|
|||
|
||||
// variables that define our graphical attributes
|
||||
screensize: Point,
|
||||
/// height of the status bar. This is subtracted from screensize.
|
||||
status_height: u16,
|
||||
/// TextView for the status bar. This encapsulates the state of the busy animation, and the text within.
|
||||
status_tv: TextView,
|
||||
/// Track the last time we update the status bar; use this avoid double-updating busy animations
|
||||
status_last_update_ms: u64,
|
||||
/// The default message to show when we exit a busy state
|
||||
status_idle_text: String,
|
||||
bubble_width: u16,
|
||||
margin: Point, // margin to edge of canvas
|
||||
bubble_margin: Point, // margin of text in bubbles
|
||||
|
|
@ -114,6 +129,25 @@ impl Ui {
|
|||
.expect("couldn't create MenuMatic manager");
|
||||
let pddb = pddb::Pddb::new();
|
||||
pddb.try_mount();
|
||||
|
||||
// setup the initial status bar contents
|
||||
let margin = Point::new(4, 4);
|
||||
let status_height = gam.glyph_height_hint(
|
||||
GlyphStyle::Regular).unwrap() as u16;
|
||||
let mut status_tv = TextView::new(canvas,
|
||||
TextBounds::BoundingBox(Rectangle::new(
|
||||
Point::new(0, 0),
|
||||
Point::new(screensize.x, status_height as _),
|
||||
))
|
||||
);
|
||||
status_tv.style = GlyphStyle::Regular;
|
||||
status_tv.margin = margin;
|
||||
status_tv.draw_border = false;
|
||||
status_tv.clear_area = true;
|
||||
status_tv.margin = Point::new(0, 0);
|
||||
write!(status_tv, "{}", t!("chat.status.initial", locales::LANG).to_string()).ok();
|
||||
let tt = ticktimer_server::Ticktimer::new().unwrap();
|
||||
let status_last_update_ms = tt.elapsed_ms();
|
||||
Ui {
|
||||
input: None,
|
||||
msg: None,
|
||||
|
|
@ -121,12 +155,17 @@ impl Ui {
|
|||
pddb_dict: None,
|
||||
pddb_key: None,
|
||||
dialogue: None,
|
||||
self_cid: xous::connect(sid).unwrap(),
|
||||
app_cid,
|
||||
opcode_event,
|
||||
canvas,
|
||||
gam,
|
||||
modals,
|
||||
tt,
|
||||
screensize,
|
||||
status_height,
|
||||
status_tv,
|
||||
status_last_update_ms,
|
||||
post_selected: None,
|
||||
post_anchor: None,
|
||||
post_topdown: false,
|
||||
|
|
@ -139,6 +178,7 @@ impl Ui {
|
|||
app_menu: app_menu.to_owned(),
|
||||
menu_mgr: menu_mgr,
|
||||
token: token,
|
||||
status_idle_text: t!("chat.status.initial", locales::LANG).to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -517,6 +557,12 @@ impl Ui {
|
|||
} else {
|
||||
bubble_tv.border_width = 1;
|
||||
}
|
||||
bubble_tv.clip_rect = Some(
|
||||
Rectangle::new(
|
||||
Point::new(0, self.status_height as i16 + self.margin.y),
|
||||
self.screensize
|
||||
)
|
||||
);
|
||||
bubble_tv.draw_border = true;
|
||||
bubble_tv.clear_area = true;
|
||||
bubble_tv.rounded_border = Some(self.bubble_radius);
|
||||
|
|
@ -535,7 +581,7 @@ impl Ui {
|
|||
.draw_rectangle(
|
||||
self.canvas,
|
||||
Rectangle::new_with_style(
|
||||
Point::new(0, 0),
|
||||
Point::new(0, self.status_height as i16),
|
||||
self.screensize,
|
||||
DrawStyle {
|
||||
fill_color: Some(PixelColor::Light),
|
||||
|
|
@ -574,6 +620,7 @@ impl Ui {
|
|||
while !self.layout().unwrap_or(true) && attempt < 3 {
|
||||
attempt += 1;
|
||||
}
|
||||
self.status_last_update_ms = self.tt.elapsed_ms();
|
||||
} else {
|
||||
self.clear_area(); // no dialogue so clear screen
|
||||
}
|
||||
|
|
@ -582,6 +629,62 @@ impl Ui {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Update the busy state. Does not touch any other aspect of the screen layout.
|
||||
pub(crate) fn redraw_busy(&mut self) -> Result<(), xous::Error> {
|
||||
let curtime = self.tt.elapsed_ms();
|
||||
if curtime - self.status_last_update_ms > BUSY_ANIMATION_RATE_MS as u64 {
|
||||
self.gam.post_textview(&mut self.status_tv)?;
|
||||
self.gam.redraw().expect("couldn't redraw screen");
|
||||
self.status_last_update_ms = curtime;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Update the status bar, without any throttling
|
||||
pub(crate) fn redraw_status_forced(&mut self) -> Result<(), xous::Error> {
|
||||
self.gam.post_textview(&mut self.status_tv)?;
|
||||
self.gam.redraw().expect("couldn't redraw screen");
|
||||
let curtime = self.tt.elapsed_ms();
|
||||
self.status_last_update_ms = curtime;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns `true` if the status bar is currently set for the busy animation
|
||||
pub(crate) fn is_busy(&self) -> bool {
|
||||
self.status_tv.busy_animation_state.is_some()
|
||||
}
|
||||
|
||||
/// Set the status bar text
|
||||
pub(crate) fn set_status_text(&mut self, msg: &str) {
|
||||
self.status_tv.clear_str();
|
||||
write!(self.status_tv, "{}", msg).ok();
|
||||
xous::send_message(self.self_cid,
|
||||
xous::Message::new_scalar(
|
||||
ChatOp::UpdateBusy as usize, 0, 0, 0, 0)
|
||||
).ok();
|
||||
}
|
||||
/// Sets the status bar to animate the busy animation
|
||||
pub(crate) fn set_busy_state(&mut self, run: bool) {
|
||||
if run {
|
||||
self.status_tv.busy_animation_state = Some(0); // the "glitch" to 0 is intentional, gives an indicator that a new op has started
|
||||
} else {
|
||||
if self.status_tv.busy_animation_state.take().is_some() {
|
||||
self.status_tv.clear_str();
|
||||
write!(self.status_tv, "{}", self.status_idle_text).ok();
|
||||
// force the update, to ensure the idle state text is actually rendered
|
||||
xous::send_message(self.self_cid,
|
||||
xous::Message::new_scalar(
|
||||
ChatOp::UpdateBusyForced as usize, 0, 0, 0, 0)
|
||||
).ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Set the default idle text. Does *not* cause a redraw. If you need
|
||||
/// an instant re-draw, call `set_status_text()`
|
||||
pub(crate) fn set_status_idle_text(&mut self, msg: &str) {
|
||||
self.status_idle_text = msg.to_owned();
|
||||
}
|
||||
|
||||
/// Layout the post bubbles on the screen.
|
||||
///
|
||||
/// The layout proceeds from top-down or bottom-up (starting with the
|
||||
|
|
@ -599,6 +702,15 @@ impl Ui {
|
|||
///
|
||||
fn layout(&mut self) -> Result<bool, Error> {
|
||||
self.clear_area();
|
||||
self.gam.post_textview(&mut self.status_tv)
|
||||
.expect("couldn't render status bar");
|
||||
let status_border = Line::new(
|
||||
Point::new(0, self.status_height as i16),
|
||||
Point::new(self.screensize.x, self.status_height as i16)
|
||||
);
|
||||
self.gam.draw_line(self.canvas,
|
||||
status_border
|
||||
).expect("couldn't draw status lower border");
|
||||
match (&self.dialogue, &self.post_anchor) {
|
||||
(Some(dialogue), Some(post_anchor)) => {
|
||||
log::info!("redrawing dialogue: {}", dialogue.title);
|
||||
|
|
@ -608,7 +720,7 @@ impl Ui {
|
|||
// initialise the first post index AND the vertical position on the screen
|
||||
let mut post_index = *post_anchor;
|
||||
let mut anchor_y = match self.post_topdown {
|
||||
true => 0,
|
||||
true => self.status_height as i16 + self.margin.y,
|
||||
false => self.screensize.y - self.margin.y,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ use ime_plugin_api::{ImefCallback, ApiToken};
|
|||
|
||||
#[doc = include_str!("../README.md")]
|
||||
|
||||
pub const RATE_LIMIT_MS: usize = 33;
|
||||
pub const SYSTEM_STYLE: GlyphStyle = GlyphStyle::Tall;
|
||||
|
||||
// Add names here and insert them into the EXPECTED_BOOT_CONTEXTS structure below.
|
||||
|
|
@ -154,6 +155,7 @@ impl Gam {
|
|||
tv.bounds_computed = tvr.bounds_computed;
|
||||
tv.cursor = tvr.cursor;
|
||||
tv.overflow = tvr.overflow;
|
||||
tv.busy_animation_state = tvr.busy_animation_state;
|
||||
}
|
||||
api::Return::NotCurrentlyDrawable => {
|
||||
tv.bounds_computed = None;
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ fn wrapped_main() -> ! {
|
|||
continue; // don't allow any redraws if a powerdown is requested
|
||||
}
|
||||
let elapsed_time = ticktimer.elapsed_ms();
|
||||
if elapsed_time - last_time > 33 { // rate limit updates, no point in going faster than the eye can see
|
||||
if elapsed_time - last_time > gam::RATE_LIMIT_MS as u64 { // rate limit updates, no point in going faster than the eye can see
|
||||
last_time = elapsed_time;
|
||||
|
||||
if deface(&gfx, &trng, &mut canvases) {
|
||||
|
|
@ -246,6 +246,7 @@ fn wrapped_main() -> ! {
|
|||
tv.cursor = tv_clone.cursor;
|
||||
tv.bounds_computed = tv_clone.bounds_computed;
|
||||
tv.overflow = tv_clone.overflow;
|
||||
tv.busy_animation_state = tv_clone.busy_animation_state;
|
||||
|
||||
let ret = api::Return::RenderReturn(tv);
|
||||
buffer.replace(ret).unwrap();
|
||||
|
|
@ -287,6 +288,7 @@ fn wrapped_main() -> ! {
|
|||
tv.cursor = tv_clone.cursor;
|
||||
tv.bounds_computed = tv_clone.bounds_computed;
|
||||
tv.overflow = tv_clone.overflow;
|
||||
tv.busy_animation_state = tv_clone.busy_animation_state;
|
||||
|
||||
let ret = api::Return::RenderReturn(tv);
|
||||
buffer.replace(ret).unwrap();
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ impl From<usize> for TextOp {
|
|||
|
||||
// roughly 168 bytes to represent the rest of the struct, and we want to fill out the 4096 byte page with text
|
||||
const TEXTVIEW_LEN: usize = 3072;
|
||||
const TEXTVIEW_DEFAULT_STYLE: GlyphStyle = GlyphStyle::Regular;
|
||||
pub const TEXTVIEW_DEFAULT_STYLE: GlyphStyle = GlyphStyle::Regular;
|
||||
|
||||
#[derive(Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||
pub struct TextView {
|
||||
|
|
|
|||
|
|
@ -275,7 +275,7 @@ pub fn rectangle(fb: &mut LcdFB, rect: Rectangle, clip: Option<Rectangle>, xor:
|
|||
// This is to make it annoying for someone using an XOR rectangle to synthesize inverted
|
||||
// text on an otherwise untrusted dialog box (I suspect it's not impossible, but introduces
|
||||
// a likelihood of drawing artifacts especially across translations and font size selections).
|
||||
if pixel.0.y % 20 < 18 {
|
||||
if pixel.0.y % 25 != 5 {
|
||||
xor_pixel(fb, pixel.0.x, pixel.0.y);
|
||||
} else {
|
||||
// don't allow XOR on some pixels to avoid this being used as a primitive to synthesize secure boxes
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ pub fn tests() {
|
|||
let mut tv = TextView::new(Gid::new([0, 0, 0, 0]),
|
||||
TextBounds::BoundingBox(anim_rect));
|
||||
tv.clip_rect = Some(clipping_area);
|
||||
tv.style = TEST_STYLE;
|
||||
tv.style = GlyphStyle::Small;
|
||||
tv.ellipsis = false;
|
||||
write!(tv, "Test of busy animation").unwrap();
|
||||
tv.insertion = None;
|
||||
|
|
|
|||
Loading…
Reference in a new issue