refactor view-selection once again
This commit is contained in:
1 parent
72279f02de
commit
49c1e81e1d
2 files changed
+36
-17
No files matched your search
+11
-15
@@ -13,26 +13,22 @@ pub struct CreddyApp {}
|
||||
|
||||
impl Render for CreddyApp {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let session = cx.global::<AppSession>();
|
||||
let screen = match session {
|
||||
// we can't do anything with an empty session, so that takes precedence over everything else
|
||||
AppSession::Empty => window
|
||||
let screen = match Screen::from_context(cx) {
|
||||
Screen::Welcome => window
|
||||
.use_keyed_state("welcome", cx, |window, cx| WelcomeScreen::new(window, cx))
|
||||
.into_any_element(),
|
||||
// If any requests are pending, the approval flow will handle unlocking itself
|
||||
_ if cx.global::<PendingRequests>().0.len() > 0 => todo!(),
|
||||
AppSession::Locked => window
|
||||
Screen::Unlock => window
|
||||
.use_keyed_state("unlock", cx, |window, cx| UnlockScreen::new(window, cx))
|
||||
.into_any_element(),
|
||||
// Otherwise, fall back to "current screen" global
|
||||
AppSession::Unlocked { .. } => match cx.global::<Screen>() {
|
||||
Screen::Home => window
|
||||
.use_keyed_state("home", cx, |_, _| HomeScreen {})
|
||||
.into_any_element(),
|
||||
Screen::Credentials => window
|
||||
.use_keyed_state("credentials", cx, |_, cx| CredentialsScreen::new(cx))
|
||||
.into_any_element(),
|
||||
},
|
||||
Screen::Home => window
|
||||
.use_keyed_state("home", cx, |_, _| HomeScreen {})
|
||||
.into_any_element(),
|
||||
Screen::Credentials => window
|
||||
.use_keyed_state("credentials", cx, |_, cx| CredentialsScreen::new(cx))
|
||||
.into_any_element(),
|
||||
Screen::RequestApproval => todo!(),
|
||||
Screen::ShowApproval => todo!(),
|
||||
};
|
||||
|
||||
let theme = cx.omarchy();
|
||||
|
||||
+25
-2
@@ -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 {}
|
||||
Reference in new issue
Block a user