mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-21 09:14:34 +00:00
re-introduce a default text to display when going out of busy state
this simplifies the problem of tracking concurrency if multiple threads are requesting a busy-state to be presented. In this case, when the final thread leaves its busy state, the idle-state will be shown.
This commit is contained in:
parent
c3aa1f46cf
commit
d4a934785b
4 changed files with 63 additions and 12 deletions
|
|
@ -85,7 +85,6 @@ pub struct MtxChat<'a> {
|
||||||
modals: Modals,
|
modals: Modals,
|
||||||
new_username: bool,
|
new_username: bool,
|
||||||
new_room: bool,
|
new_room: bool,
|
||||||
status: String,
|
|
||||||
tt: Ticktimer,
|
tt: Ticktimer,
|
||||||
}
|
}
|
||||||
impl<'a> MtxChat<'a> {
|
impl<'a> MtxChat<'a> {
|
||||||
|
|
@ -119,7 +118,6 @@ impl<'a> MtxChat<'a> {
|
||||||
modals: modals,
|
modals: modals,
|
||||||
new_username: false,
|
new_username: false,
|
||||||
new_room: false,
|
new_room: false,
|
||||||
status,
|
|
||||||
tt: ticktimer_server::Ticktimer::new().unwrap(),
|
tt: ticktimer_server::Ticktimer::new().unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -344,7 +342,6 @@ impl<'a> MtxChat<'a> {
|
||||||
self.unset(USER_DOMAIN_KEY)
|
self.unset(USER_DOMAIN_KEY)
|
||||||
.expect("failed to unset user domain");
|
.expect("failed to unset user domain");
|
||||||
}
|
}
|
||||||
self.chat.set_status_text(&self.status);
|
|
||||||
self.chat.set_busy_state(false);
|
self.chat.set_busy_state(false);
|
||||||
self.logged_in
|
self.logged_in
|
||||||
}
|
}
|
||||||
|
|
@ -450,11 +447,9 @@ impl<'a> MtxChat<'a> {
|
||||||
web::get_room_id(&mut url, &room_alias, &token, &mut self.agent)
|
web::get_room_id(&mut url, &room_alias, &token, &mut self.agent)
|
||||||
{
|
{
|
||||||
self.set_debug(ROOM_ID_KEY, &room_id);
|
self.set_debug(ROOM_ID_KEY, &room_id);
|
||||||
self.chat.set_status_text(&self.status);
|
|
||||||
self.chat.set_busy_state(false);
|
self.chat.set_busy_state(false);
|
||||||
return Some(room_id);
|
return Some(room_id);
|
||||||
} else {
|
} else {
|
||||||
self.chat.set_status_text(&self.status);
|
|
||||||
self.chat.set_busy_state(false);
|
self.chat.set_busy_state(false);
|
||||||
"failed to get room_id"
|
"failed to get room_id"
|
||||||
}
|
}
|
||||||
|
|
@ -660,7 +655,6 @@ impl<'a> MtxChat<'a> {
|
||||||
} else {
|
} else {
|
||||||
"FAILED TO SEND"
|
"FAILED TO SEND"
|
||||||
};
|
};
|
||||||
self.chat.set_status_text(&self.status);
|
|
||||||
self.chat.set_busy_state(false);
|
self.chat.set_busy_state(false);
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
@ -697,7 +691,6 @@ impl<'a> MtxChat<'a> {
|
||||||
if let Some(conf) = self.netmgr.get_ipv4_config() {
|
if let Some(conf) = self.netmgr.get_ipv4_config() {
|
||||||
if conf.dhcp == com_rs::DhcpState::Bound {
|
if conf.dhcp == com_rs::DhcpState::Bound {
|
||||||
self.chat.set_busy_state(false);
|
self.chat.set_busy_state(false);
|
||||||
self.chat.set_status_text(&self.status);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,8 @@ pub enum ChatOp {
|
||||||
SetStatusText,
|
SetStatusText,
|
||||||
/// Run or stop the busy animation.
|
/// Run or stop the busy animation.
|
||||||
SetBusyAnimationState,
|
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.
|
/// Update just the state of the busy animation, if any. Internal opcode.
|
||||||
UpdateBusy,
|
UpdateBusy,
|
||||||
/// exit the application
|
/// exit the application
|
||||||
|
|
|
||||||
|
|
@ -265,6 +265,20 @@ impl Chat {
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
.expect("internal error");
|
.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.
|
/// Helper server that pumps the busy animation state until instructed to stop.
|
||||||
|
|
@ -298,7 +312,6 @@ pub fn busy_animator(
|
||||||
ChatOp::UpdateBusy as usize, 0, 0, 0, 0)
|
ChatOp::UpdateBusy as usize, 0, 0, 0, 0)
|
||||||
).ok();
|
).ok();
|
||||||
tt.sleep_ms(crate::BUSY_ANIMATION_RATE_MS).unwrap();
|
tt.sleep_ms(crate::BUSY_ANIMATION_RATE_MS).unwrap();
|
||||||
log::info!("busy!");
|
|
||||||
xous::try_send_message(busy_bumper_cid,
|
xous::try_send_message(busy_bumper_cid,
|
||||||
xous::Message::new_scalar(
|
xous::Message::new_scalar(
|
||||||
BusyAnimOp::Pump as usize, 0, 0, 0, 0)
|
BusyAnimOp::Pump as usize, 0, 0, 0, 0)
|
||||||
|
|
@ -357,6 +370,13 @@ pub fn server(
|
||||||
let s = buffer.to_original::<BusyMessage, _>().unwrap();
|
let s = buffer.to_original::<BusyMessage, _>().unwrap();
|
||||||
ui.set_status_text(s.busy_msg.as_str().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, _, _, _, {
|
Some(ChatOp::SetBusyAnimationState) => msg_scalar_unpack!(msg, state, _, _, _, {
|
||||||
if state != 0 {
|
if state != 0 {
|
||||||
ui.set_busy_state(true);
|
ui.set_busy_state(true);
|
||||||
|
|
@ -368,8 +388,8 @@ pub fn server(
|
||||||
).ok();
|
).ok();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
run_busy_animation.store(false, Ordering::SeqCst);
|
||||||
ui.set_busy_state(false);
|
ui.set_busy_state(false);
|
||||||
run_busy_animation.store(false, Ordering::SeqCst)
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
Some(ChatOp::DialogueSave) => {
|
Some(ChatOp::DialogueSave) => {
|
||||||
|
|
@ -571,3 +591,25 @@ pub fn now() -> u64 {
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap()
|
.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");
|
||||||
|
}
|
||||||
|
|
@ -62,8 +62,10 @@ pub(crate) struct Ui {
|
||||||
status_height: u16,
|
status_height: u16,
|
||||||
/// TextView for the status bar. This encapsulates the state of the busy animation, and the text within.
|
/// TextView for the status bar. This encapsulates the state of the busy animation, and the text within.
|
||||||
status_tv: TextView,
|
status_tv: TextView,
|
||||||
/// track the last time we update the status bar; use this avoid double-updating busy animations
|
/// Track the last time we update the status bar; use this avoid double-updating busy animations
|
||||||
status_last_update_ms: u64,
|
status_last_update_ms: u64,
|
||||||
|
/// The default message to show when we exit a busy state
|
||||||
|
status_idle_text: String,
|
||||||
bubble_width: u16,
|
bubble_width: u16,
|
||||||
margin: Point, // margin to edge of canvas
|
margin: Point, // margin to edge of canvas
|
||||||
bubble_margin: Point, // margin of text in bubbles
|
bubble_margin: Point, // margin of text in bubbles
|
||||||
|
|
@ -173,6 +175,7 @@ impl Ui {
|
||||||
app_menu: app_menu.to_owned(),
|
app_menu: app_menu.to_owned(),
|
||||||
menu_mgr: menu_mgr,
|
menu_mgr: menu_mgr,
|
||||||
token: token,
|
token: token,
|
||||||
|
status_idle_text: t!("chat.status.initial", locales::LANG).to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -627,7 +630,6 @@ impl Ui {
|
||||||
pub(crate) fn redraw_busy(&mut self) -> Result<(), xous::Error> {
|
pub(crate) fn redraw_busy(&mut self) -> Result<(), xous::Error> {
|
||||||
let curtime = self.tt.elapsed_ms();
|
let curtime = self.tt.elapsed_ms();
|
||||||
if curtime - self.status_last_update_ms > BUSY_ANIMATION_RATE_MS as u64 {
|
if curtime - self.status_last_update_ms > BUSY_ANIMATION_RATE_MS as u64 {
|
||||||
log::info!("update!");
|
|
||||||
self.gam.post_textview(&mut self.status_tv)?;
|
self.gam.post_textview(&mut self.status_tv)?;
|
||||||
self.gam.redraw().expect("couldn't redraw screen");
|
self.gam.redraw().expect("couldn't redraw screen");
|
||||||
self.status_last_update_ms = curtime;
|
self.status_last_update_ms = curtime;
|
||||||
|
|
@ -654,9 +656,21 @@ impl Ui {
|
||||||
if run {
|
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
|
self.status_tv.busy_animation_state = Some(0); // the "glitch" to 0 is intentional, gives an indicator that a new op has started
|
||||||
} else {
|
} else {
|
||||||
self.status_tv.busy_animation_state = None;
|
if self.status_tv.busy_animation_state.take().is_some() {
|
||||||
|
self.status_tv.clear_str();
|
||||||
|
write!(self.status_tv, "{}", self.status_idle_text).ok();
|
||||||
|
xous::send_message(self.app_cid.unwrap(),
|
||||||
|
xous::Message::new_scalar(
|
||||||
|
ChatOp::UpdateBusy 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.
|
/// Layout the post bubbles on the screen.
|
||||||
///
|
///
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue