refactor view-selection once again

This commit is contained in:
jfmonty2 committed 2026-11-23 12:51:08 -05:00
1 parent 72279f02de
commit 49c1e81e1d
2 files changed
+36 -17

No files matched your search

+25 -2
View File
@@ -1,20 +1,43 @@
use gpui_kit::Global;
use gpui_kit::{Context, Global};
mod credentials;
mod home;
mod unlock;
mod welcome;
use crate::app::CreddyApp;
pub use credentials::CredentialsScreen;
pub use home::HomeScreen;
pub use unlock::UnlockScreen;
pub use welcome::WelcomeScreen;
use crate::session::AppSession;
use crate::srv::PendingRequests;
/// Which screen to show while the app is unlocked.
/// 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<CreddyApp>) -> Screen {
match cx.global::<AppSession>() {
// 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::<PendingRequests>().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::<Screen>(),
}
}
}
impl Global for Screen {}