chat implement wifi connect modal

This commit is contained in:
nworbnhoj 2023-09-08 18:04:27 +10:00
parent e1f1ac427b
commit 9254163e5a
3 changed files with 55 additions and 28 deletions

View file

@ -26,10 +26,6 @@ Use another device such as a mobile or PC to:
* https://spec.matrix.org/latest/#room-structure * https://spec.matrix.org/latest/#room-structure
* Join the room * Join the room
Before switching to mtxchat app on Precursor, ensure that:
* the PDDB is mounted
* WiFi is connected.
## Functionality ## Functionality
@ -62,17 +58,8 @@ The `mtxchat` servers is set to receive:
## Troubleshooting ## Troubleshooting
Prequisites: it is essential that the PDDB is mounted and WiFi is If you see the message `WARNING: clock not set` that is likely because the Precursor real time clock needs to be set (e.g. if the battery has been completely discharged). Please go to the menu **Preferences | Set Timezone** to set the time zone (and update the time via NTP).
connected before running mtxcli. You can verify these in Shellchat
with `net ping 1.1.1.1`.
If you see the message `WARNING: clock not set` that is likely because If you see the message `authentication failed` it might be because the `user` and `password` variables are not set properly.
the Precursor real time clock needs to be set (e.g. if the battery
has been completely discharged). Please go to the menu
**Preferences | Set Timezone** to set the time zone
(and update the time via NTP).
If you see the message `authentication failed` it might be because
the `user` and `password` variables are not set properly.
Alternatively it could be because TLS certificate validation Alternatively it could be because TLS certificate validation
has failed because the clock has not been set (see above). has failed because the clock has not been set (see above).

View file

@ -219,11 +219,11 @@
"zh": "WiFi connected *EN*" "zh": "WiFi connected *EN*"
}, },
"mtxchat.wifi.warning": { "mtxchat.wifi.warning": {
"en": "WARNING: WiFi not connected", "en": "WiFi not connected. Entering read-only mode",
"en-tts": "WARNING: WiFi not connected", "en-tts": "WiFi not connected Entering read-only mode",
"fr": "AVERTISSEMENT: WiFi pas connecté", "fr": "WiFi pas connecté",
"ja": "WARNING: WiFi not connected *EN*", "ja": "WiFi not connected. Entering read-only mode *EN*",
"zh": "WARNING: WiFi not connected *EN*" "zh": "WiFi not connected. Entering read-only mode *EN*"
}, },
"mtxchat.close.item": { "mtxchat.close.item": {
"en": "Close menu", "en": "Close menu",

View file

@ -35,6 +35,7 @@ const DOMAIN_MATRIX: &str = "matrix.org";
const EMPTY: &str = ""; const EMPTY: &str = "";
const MTX_LONG_TIMEOUT: i32 = 60000; // ms const MTX_LONG_TIMEOUT: i32 = 60000; // ms
const WIFI_TIMEOUT: u32 = 10; // seconds
pub const CLOCK_NOT_SET_ID: usize = 1; pub const CLOCK_NOT_SET_ID: usize = 1;
pub const PDDB_NOT_MOUNTED_ID: usize = 2; pub const PDDB_NOT_MOUNTED_ID: usize = 2;
@ -230,7 +231,7 @@ impl<'a> MtxChat<'a> {
pub fn connect(&mut self) -> bool { pub fn connect(&mut self) -> bool {
log::info!("Attempting connect to Matrix server"); log::info!("Attempting connect to Matrix server");
if self.wifi_connected() { if self.wifi() {
if self.login() { if self.login() {
if let Some(room) = self.get_room_id() { if let Some(room) = self.get_room_id() {
self.dialogue_set(Some(room.as_str())); self.dialogue_set(Some(room.as_str()));
@ -527,7 +528,7 @@ impl<'a> MtxChat<'a> {
if since.len() > 0 { if since.len() > 0 {
self.set_debug(SINCE_KEY, since); self.set_debug(SINCE_KEY, since);
// don't re-start listening if there was an error // don't re-start listening if there was an error
if self.logged_in && self.wifi_connected() { if self.logged_in && self.wifi() {
self.listen(); self.listen();
} }
} }
@ -564,15 +565,54 @@ impl<'a> MtxChat<'a> {
} }
} }
pub fn wifi_connected(&self) -> bool { // returns true is wifi is connected
//
// If wifi is not connected then a modal offers to "Connect to wifi?"
// and tries for 10 seconds before representing.
//
pub fn wifi(&self) -> bool {
if HOSTED_MODE { if HOSTED_MODE {
true return true;
} else { }
match self.netmgr.get_ipv4_config() {
Some(conf) => conf.dhcp == com_rs::DhcpState::Bound, if let Some(conf) = self.netmgr.get_ipv4_config() {
None => false, if conf.dhcp == com_rs::DhcpState::Bound {
return true;
} }
} }
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");
if let Some(conf) = self.netmgr.get_ipv4_config() {
if conf.dhcp == com_rs::DhcpState::Bound {
self.modals.finish_progress().expect("failed progress finish");
return true;
}
}
}
}
false
}
// returns true if "Connect to WiFi?" yes option is chosen
//
fn wifi_try_modal (&self) -> bool {
self.modals.add_list_item("yes").expect("failed radio yes");
self.modals.add_list_item("no").expect("failed radio no");
self.modals.get_radiobutton("Connect to WiFi?").expect("failed radiobutton modal");
match self.modals.get_radio_index() {
Ok(button) => button == 0,
_ => false,
}
} }
} }