move wifi delay hook to the correct area

- remove modal pop-up for wifi connection, and replace with
busy animation
- specify units of delay in the constants (_MS to indicate milliseconds;
this is a convention I'm trying to adhere to)
- partial progress on debugging why the animation isn't running
(value of animation variable is not being passed back at the GAM layer).

Also a general note on coding styles that probably is going to cause
confusion now that more people are contributing to the code base.

Generally, when a lot of "generic" library functions fail, we've been
passing an error message up the stack. However, these functions are
actually meant to be infalliable, and when you kick the error up the
stack you just end up with a panic at an unhelpful location (because
you finally catch the error only at the main loop or something and
by that point there's nothing you can really do about it but panic,
since it's supposed to be an infalliable operation).

As a result I have been trying to tamp down on needless error propagations
and having them fail with a unwrap or expect at the point where the
abstraction should be infalliable. This helps in debugging the actual
failure root cause because you're closer to the line of code that
actually broke, instead of just some line at a generic error handler.

Of course if you build with stack unwinding the top-level unwraps are more
useful because you can peer down into the call chain, but even then,
with the limited screen real estate I think deeply nested failures
would probably overflow any panic display. So even with panic unwinding
I think we stil want to keep the root cause within a few stack frames,
instead of errors being passed up sixteen levels of abstraction before
finally dying.

This only applies to things that are meant to be truly infalliable,
like syscalls that should not fail, or like unpacking a buffer or
memory message that has already been allocated. In this case the errors
are more like asserts, and are helpful if they fail at the line where
they break instead of being passed up the call stack (which was the
original architecture).

Probably I should add a note about this to the Xous Book.
This commit is contained in:
bunnie 2023-10-29 16:33:03 +08:00
parent 4e027b676c
commit 4423339059
5 changed files with 25 additions and 18 deletions

View file

@ -241,6 +241,10 @@
"ja": "WiFi not connected. Entering read-only mode *EN*",
"zh": "WiFi not connected. Entering read-only mode *EN*"
},
"mtxchat.wifi.warning_status": {
"en": "No connection! Read-only.",
"en-tts": "No connection! Read-only."
},
"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."

View file

@ -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,8 @@ 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
pub const CLOCK_NOT_SET_ID: usize = 1;
pub const PDDB_NOT_MOUNTED_ID: usize = 2;
@ -84,6 +85,7 @@ pub struct MtxChat<'a> {
new_username: bool,
new_room: bool,
status: String,
tt: Ticktimer,
}
impl<'a> MtxChat<'a> {
pub fn new(chat: &Chat) -> MtxChat {
@ -117,6 +119,7 @@ impl<'a> MtxChat<'a> {
new_username: false,
new_room: false,
status,
tt: ticktimer_server::Ticktimer::new().unwrap(),
}
}
@ -674,25 +677,23 @@ 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);
self.chat.set_status_text(&self.status);
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
}

View file

@ -1,4 +1,4 @@
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;
@ -18,7 +18,7 @@ pub fn listen(
) {
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 +27,7 @@ pub fn listen(
url,
filter,
since,
MTX_LONG_TIMEOUT,
MTX_LONG_TIMEOUT_MS,
&room_id,
&token,
&mut agent,

View file

@ -21,7 +21,7 @@ use xous::{MessageEnvelope, CID};
use xous_names::XousNames;
pub const BUSY_ANIMATION_RATE_MS: usize = 50;
pub const BUSY_ANIMATION_RATE_MS: usize = 200;
#[allow(dead_code)]
pub(crate) struct Ui {
@ -627,6 +627,7 @@ impl Ui {
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 {
log::info!("update!");
self.gam.post_textview(&mut self.status_tv)?;
self.gam.redraw().expect("couldn't redraw screen");
self.status_last_update_ms = curtime;

View file

@ -154,6 +154,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;