Skip to content

Commit d277ae9

Browse files
committed
feat: show boot process notifications for PDDB
This commit shows two notifications: 1. as soon as the device boots, a notification greets the user and tells them everything is fine, the device is booting 2. as soon as the user enters (or doesn't) enter the password, a notification tell the user Xous is loading and mounting PDDB I spent too much time on this but I believe it's a nice UX improvement.
1 parent f861af7 commit d277ae9

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

services/pddb/src/main.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ use std::collections::{HashMap, BTreeSet};
394394
use std::io::ErrorKind;
395395
use core::fmt::Write;
396396
use std::sync::atomic::{AtomicBool, Ordering};
397-
use std::sync::Arc;
397+
use std::sync::{Arc, Mutex};
398398

399399
use locales::t;
400400

@@ -490,6 +490,34 @@ fn wrapped_main() -> ! {
490490
}
491491
});
492492

493+
let hide_startingup_notif = Arc::new(Mutex::new(false));
494+
let hide_startingup_notif_clone = hide_startingup_notif.clone();
495+
496+
std::thread::spawn(move || {
497+
// For some weird reason spawning a dynamic notification without waiting 800ms in a separate thread
498+
// makes it impossible to read, because it gets covered by hundreds of those modal security lines (???).
499+
// This thread waits on hide_startingup_notif to become true, then disimsses the dynamic notification that it created
500+
// previously.
501+
// To allow other threads to do work, yield to kernel every time the variable is read as false.
502+
503+
let xns = xous_names::XousNames::new().unwrap();
504+
let modals = modals::Modals::new(&xns).expect("can't connect to Modals server");
505+
506+
std::thread::sleep(std::time::Duration::from_millis(1000));
507+
508+
modals.dynamic_notification(Some("Starting up..."), Some("Precursor is booting up, please wait.")).unwrap();
509+
510+
loop {
511+
if *hide_startingup_notif_clone.lock().unwrap() {
512+
modals.dynamic_notification_close().unwrap();
513+
break;
514+
}
515+
516+
xous::yield_slice();
517+
};
518+
});
519+
520+
493521
// OS-specific PDDB driver
494522
let mut pddb_os = PddbOs::new(Rc::clone(&entropy), pw_cid);
495523
// storage for the basis cache
@@ -656,6 +684,8 @@ fn wrapped_main() -> ! {
656684
// - code = 2 -> mount failed, because too many PINs were retried. `count` is the number of retries.
657685
// If we need more nuance out of this routine, consider creating a custom public enum type to help marshall this.
658686
Opcode::TryMount => xous::msg_blocking_scalar_unpack!(msg, _, _, _, _, {
687+
*hide_startingup_notif.lock().unwrap() = true;
688+
659689
if basis_cache.basis_count() > 0 {
660690
xous::return_scalar2(msg.sender, 0, 0).expect("couldn't return scalar");
661691
} else {
@@ -669,6 +699,8 @@ fn wrapped_main() -> ! {
669699
} else {
670700
match ensure_password(&modals, &mut pddb_os, pw_cid) {
671701
PasswordState::Correct => {
702+
modals.dynamic_notification(Some("Starting up..."), Some("Mounting PDDB, please wait.")).unwrap();
703+
672704
if try_mount_or_format(&modals, &mut pddb_os, &mut basis_cache, PasswordState::Correct, time_resetter) {
673705
is_mounted.store(true, Ordering::SeqCst);
674706
for requester in mount_notifications.drain(..) {
@@ -680,8 +712,12 @@ fn wrapped_main() -> ! {
680712
} else {
681713
xous::return_scalar2(msg.sender, 1, 0).expect("couldn't return scalar");
682714
}
715+
716+
modals.dynamic_notification_close().unwrap();
683717
},
684718
PasswordState::Uninit => {
719+
modals.dynamic_notification(Some("Starting up..."), Some("Mounting PDDB, please wait.")).unwrap();
720+
685721
if try_mount_or_format(&modals, &mut pddb_os, &mut basis_cache, PasswordState::Uninit, time_resetter) {
686722
for requester in mount_notifications.drain(..) {
687723
xous::return_scalar2(requester, 0, 0).expect("couldn't return scalar");
@@ -693,6 +729,8 @@ fn wrapped_main() -> ! {
693729
} else {
694730
xous::return_scalar2(msg.sender, 1, 0).expect("couldn't return scalar");
695731
}
732+
733+
modals.dynamic_notification_close().unwrap();
696734
},
697735
PasswordState::ForcedAbort(failcount) => {
698736
xous::return_scalar2(msg.sender, 2,

0 commit comments

Comments
 (0)