commit 575150340626833fdf0722934a9c1f4825495e9d
parent 68865cead977121c6f81f2bd6c27ebddde5bc785
Author: triesap <tyson@radroots.org>
Date: Mon, 2 Feb 2026 18:59:11 +0000
app: add setup status model
- add setup status enum and gate helpers
- map setup state into route/nav decisions
- keep ui and init behavior unchanged
- cover gate decisions with unit tests
Diffstat:
2 files changed, 120 insertions(+), 0 deletions(-)
diff --git a/app/src/lib.rs b/app/src/lib.rs
@@ -14,6 +14,7 @@ mod logs;
mod notifications;
mod settings;
mod setup;
+mod setup_status;
mod theme;
mod tangle;
mod ui_demo;
@@ -73,6 +74,11 @@ pub use keystore::{
};
pub use logs::RadrootsAppLogsPage;
pub use settings::RadrootsAppSettingsPage;
+pub use setup_status::{
+ app_setup_gate_from_status,
+ RadrootsAppSetupGate,
+ RadrootsAppSetupStatus,
+};
pub use ui_demo::RadrootsAppUiDemoPage;
pub use theme::{
app_theme_apply_mode,
diff --git a/app/src/setup_status.rs b/app/src/setup_status.rs
@@ -0,0 +1,114 @@
+#![forbid(unsafe_code)]
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum RadrootsAppSetupStatus {
+ Unknown,
+ Required,
+ Configured,
+ Corrupt,
+ Locked,
+}
+
+impl Default for RadrootsAppSetupStatus {
+ fn default() -> Self {
+ RadrootsAppSetupStatus::Unknown
+ }
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct RadrootsAppSetupGate {
+ pub show_app: bool,
+ pub show_setup: bool,
+ pub show_setup_nav: bool,
+ pub show_recovery: bool,
+}
+
+impl RadrootsAppSetupGate {
+ pub const fn splash() -> Self {
+ Self {
+ show_app: false,
+ show_setup: false,
+ show_setup_nav: false,
+ show_recovery: false,
+ }
+ }
+}
+
+pub const fn app_setup_gate_from_status(status: RadrootsAppSetupStatus) -> RadrootsAppSetupGate {
+ match status {
+ RadrootsAppSetupStatus::Unknown => RadrootsAppSetupGate::splash(),
+ RadrootsAppSetupStatus::Required => RadrootsAppSetupGate {
+ show_app: false,
+ show_setup: true,
+ show_setup_nav: false,
+ show_recovery: false,
+ },
+ RadrootsAppSetupStatus::Configured => RadrootsAppSetupGate {
+ show_app: true,
+ show_setup: false,
+ show_setup_nav: false,
+ show_recovery: false,
+ },
+ RadrootsAppSetupStatus::Corrupt => RadrootsAppSetupGate {
+ show_app: false,
+ show_setup: false,
+ show_setup_nav: false,
+ show_recovery: true,
+ },
+ RadrootsAppSetupStatus::Locked => RadrootsAppSetupGate {
+ show_app: false,
+ show_setup: true,
+ show_setup_nav: false,
+ show_recovery: false,
+ },
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::{app_setup_gate_from_status, RadrootsAppSetupGate, RadrootsAppSetupStatus};
+
+ #[test]
+ fn unknown_status_routes_to_splash() {
+ assert_eq!(
+ app_setup_gate_from_status(RadrootsAppSetupStatus::Unknown),
+ RadrootsAppSetupGate::splash()
+ );
+ }
+
+ #[test]
+ fn required_status_shows_setup() {
+ let gate = app_setup_gate_from_status(RadrootsAppSetupStatus::Required);
+ assert!(gate.show_setup);
+ assert!(!gate.show_app);
+ assert!(!gate.show_setup_nav);
+ assert!(!gate.show_recovery);
+ }
+
+ #[test]
+ fn configured_status_shows_app() {
+ let gate = app_setup_gate_from_status(RadrootsAppSetupStatus::Configured);
+ assert!(gate.show_app);
+ assert!(!gate.show_setup);
+ assert!(!gate.show_setup_nav);
+ assert!(!gate.show_recovery);
+ }
+
+ #[test]
+ fn corrupt_status_shows_recovery() {
+ let gate = app_setup_gate_from_status(RadrootsAppSetupStatus::Corrupt);
+ assert!(gate.show_recovery);
+ assert!(!gate.show_app);
+ assert!(!gate.show_setup);
+ assert!(!gate.show_setup_nav);
+ }
+
+ #[test]
+ fn locked_status_shows_setup() {
+ let gate = app_setup_gate_from_status(RadrootsAppSetupStatus::Locked);
+ assert!(gate.show_setup);
+ assert!(!gate.show_app);
+ assert!(!gate.show_setup_nav);
+ assert!(!gate.show_recovery);
+ }
+}