use gpui_kit::{Context, Global}; mod approval; mod credentials; mod home; mod unlock; mod welcome; use crate::app::CreddyApp; pub use approval::ApprovalScreen; pub use credentials::CredentialsScreen; pub use home::HomeScreen; pub use unlock::UnlockScreen; pub use welcome::WelcomeScreen; use crate::session::AppSession; use crate::srv::PendingRequests; /// It's convenient to be able to reference a screen without actually constructing it /// (e.g. when navigating), so this exists to map app state to the name of a screen. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Screen { Welcome, Unlock, Home, Credentials, RequestApproval, ShowApproval, } impl Screen { pub fn from_context(cx: &Context) -> Screen { match cx.global::() { // we can't do anything useful when empty except ask for a passphrase, so this state takes precedence AppSession::Empty => Screen::Welcome, // otherwise if we have a pending request, ask for approval, even if locked (approval flow will handle unlock) _ if cx.global::().0.len() > 0 => Screen::RequestApproval, // therwise if locked, ask for unlock AppSession::Locked => Screen::Unlock, // otherwise, fall back to "current screen" global AppSession::Unlocked(_) => *cx.global::(), } } } impl Global for Screen {}