add approval to screen selection

This commit is contained in:
jfmonty2 committed 2026-11-23 12:33:43 -05:00
1 parent d5e7de86cb
commit 72279f02de
3 files changed
+20 -5

No files matched your search

+6 -1
View File
@@ -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<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
.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
.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 {})
@@ -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::<AppConfig>(|cx| cx.refresh_windows())
+13 -3
View File
@@ -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<CredentialRequest>);
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<Full<Bytes>> {
// 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),
+1 -1
View File
@@ -1,3 +1,3 @@
mod creddy_server;
pub use creddy_server::start_creddy_server;
pub use creddy_server::{PendingRequests, start_creddy_server};