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 {
|
impl Render for CreddyApp {
|
||||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
let session = cx.global::<AppSession>();
|
let screen = match Screen::from_context(cx) {
|
||||||
let screen = match session {
|
Screen::Welcome => window
|
||||||
// we can't do anything with an empty session, so that takes precedence over everything else
|
|
||||||
AppSession::Empty => window
|
|
||||||
.use_keyed_state("welcome", cx, |window, cx| WelcomeScreen::new(window, cx))
|
.use_keyed_state("welcome", cx, |window, cx| WelcomeScreen::new(window, cx))
|
||||||
.into_any_element(),
|
.into_any_element(),
|
||||||
// If any requests are pending, the approval flow will handle unlocking itself
|
Screen::Unlock => window
|
||||||
_ if cx.global::<PendingRequests>().0.len() > 0 => todo!(),
|
|
||||||
AppSession::Locked => window
|
|
||||||
.use_keyed_state("unlock", cx, |window, cx| UnlockScreen::new(window, cx))
|
.use_keyed_state("unlock", cx, |window, cx| UnlockScreen::new(window, cx))
|
||||||
.into_any_element(),
|
.into_any_element(),
|
||||||
// Otherwise, fall back to "current screen" global
|
// Otherwise, fall back to "current screen" global
|
||||||
AppSession::Unlocked { .. } => match cx.global::<Screen>() {
|
Screen::Home => window
|
||||||
Screen::Home => window
|
.use_keyed_state("home", cx, |_, _| HomeScreen {})
|
||||||
.use_keyed_state("home", cx, |_, _| HomeScreen {})
|
.into_any_element(),
|
||||||
.into_any_element(),
|
Screen::Credentials => window
|
||||||
Screen::Credentials => window
|
.use_keyed_state("credentials", cx, |_, cx| CredentialsScreen::new(cx))
|
||||||
.use_keyed_state("credentials", cx, |_, cx| CredentialsScreen::new(cx))
|
.into_any_element(),
|
||||||
.into_any_element(),
|
Screen::RequestApproval => todo!(),
|
||||||
},
|
Screen::ShowApproval => todo!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let theme = cx.omarchy();
|
let theme = cx.omarchy();
|
||||||
|
|||||||
+25
-2
@@ -1,20 +1,43 @@
|
|||||||
use gpui_kit::Global;
|
use gpui_kit::{Context, Global};
|
||||||
|
|
||||||
mod credentials;
|
mod credentials;
|
||||||
mod home;
|
mod home;
|
||||||
mod unlock;
|
mod unlock;
|
||||||
mod welcome;
|
mod welcome;
|
||||||
|
|
||||||
|
use crate::app::CreddyApp;
|
||||||
pub use credentials::CredentialsScreen;
|
pub use credentials::CredentialsScreen;
|
||||||
pub use home::HomeScreen;
|
pub use home::HomeScreen;
|
||||||
pub use unlock::UnlockScreen;
|
pub use unlock::UnlockScreen;
|
||||||
pub use welcome::WelcomeScreen;
|
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)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum Screen {
|
pub enum Screen {
|
||||||
|
Welcome,
|
||||||
|
Unlock,
|
||||||
Home,
|
Home,
|
||||||
Credentials,
|
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 {}
|
impl Global for Screen {}
|
||||||
Reference in new issue
Block a user