diff --git a/src/app.rs b/src/app.rs index 840be3c..d15d709 100644 --- a/src/app.rs +++ b/src/app.rs @@ -7,7 +7,7 @@ use gpui_omarchy::ActiveTheme; use crate::config::AppConfig; use crate::screens::{CredentialsScreen, HomeScreen, Screen, UnlockScreen, WelcomeScreen}; use crate::session::AppSession; -use crate::srv; +use crate::srv::{self, PendingRequests}; pub struct CreddyApp {} @@ -15,12 +15,16 @@ impl Render for CreddyApp { fn render(&mut self, window: &mut Window, cx: &mut Context) -> impl IntoElement { let session = cx.global::(); let screen = match session { + // 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)) .into_any_element(), + // If any requests are pending, the approval flow will handle unlocking itself + _ if cx.global::().0.len() > 0 => todo!(), AppSession::Locked => 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::Home => window .use_keyed_state("home", cx, |_, _| HomeScreen {}) @@ -52,6 +56,7 @@ pub fn launch(cx: &mut App, config: AppConfig, session: AppSession) -> WindowHan cx.set_global(config); cx.set_global(session); cx.set_global(Screen::Home); + cx.set_global(PendingRequests::new()); // refresh_windows() forces everything to re-render, which is kind of a nuclear solution, // but these values aren't expected to change very frequently, so it shouldn't be a problem cx.observe_global::(|cx| cx.refresh_windows()) diff --git a/src/srv/creddy_server.rs b/src/srv/creddy_server.rs index 97faef3..8586f06 100644 --- a/src/srv/creddy_server.rs +++ b/src/srv/creddy_server.rs @@ -1,6 +1,6 @@ use crate::credentials::{AwsCredential, AwsSessionCredential}; use crate::error::CreddyError; -use gpui_kit::AsyncApp; +use gpui_kit::{AsyncApp, Global}; use http_body_util::Full; use hyper::body::{Bytes, Incoming}; use hyper::http::Uri; @@ -13,6 +13,7 @@ use serde::{Deserialize, Serialize}; use smol::Timer; use smol::net::unix::{UnixListener, UnixStream}; use smol_hyper::rt::FuturesIo; +use std::collections::{HashMap, VecDeque}; use std::convert::Infallible; use std::fs; use std::io; @@ -26,6 +27,16 @@ pub enum CredentialRequest { } } +pub struct PendingRequests(pub VecDeque); + +impl PendingRequests { + pub fn new() -> PendingRequests { + PendingRequests(VecDeque::new()) + } +} + +impl Global for PendingRequests {} + #[derive(Deserialize, Serialize)] pub struct ErrorResponse { @@ -100,9 +111,8 @@ async fn handle( } fn handle_aws_get(uri: Uri) -> Response> { - // let params: std::collections::HashMap<&str, &str> = form_urlencoded::parse(uri.query().unwrap_or("").as_bytes()).collect(); let qs = uri.query().unwrap_or("").as_bytes(); - let params: std::collections::HashMap<_, _> = form_urlencoded::parse(qs).collect(); + let params: HashMap<_, _> = form_urlencoded::parse(qs).collect(); let req = CredentialRequest::AwsGet{ name: params.get("name").map(|n| n.to_string()), session: params.get("session").map(|s| s == "true").unwrap_or(false), diff --git a/src/srv/mod.rs b/src/srv/mod.rs index ddee22e..1dee20c 100644 --- a/src/srv/mod.rs +++ b/src/srv/mod.rs @@ -1,3 +1,3 @@ mod creddy_server; -pub use creddy_server::start_creddy_server; +pub use creddy_server::{PendingRequests, start_creddy_server};