From b57d5174aac056eec0df9d262fe7b9d574c379e2 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 23 Mar 2023 12:49:52 -0700 Subject: [PATCH] Add copilot theme, start sketching out the auth modal --- crates/copilot/src/auth_modal.rs | 20 ++++++++++++++++++++ crates/copilot/src/copilot.rs | 23 ++++++++++++++++++----- crates/theme/src/theme.rs | 6 ++++++ styles/src/styleTree/app.ts | 2 ++ styles/src/styleTree/copilot.ts | 11 +++++++++++ 5 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 crates/copilot/src/auth_modal.rs create mode 100644 styles/src/styleTree/copilot.ts diff --git a/crates/copilot/src/auth_modal.rs b/crates/copilot/src/auth_modal.rs new file mode 100644 index 0000000000000000000000000000000000000000..4786f1d470f4ce56c28eab35a17fe924bc274839 --- /dev/null +++ b/crates/copilot/src/auth_modal.rs @@ -0,0 +1,20 @@ +use gpui::{elements::Label, Element, Entity, View}; +use settings::Settings; + +pub struct AuthModal {} + +impl Entity for AuthModal { + type Event = (); +} + +impl View for AuthModal { + fn ui_name() -> &'static str { + "AuthModal" + } + + fn render(&mut self, cx: &mut gpui::RenderContext<'_, Self>) -> gpui::ElementBox { + let style = &cx.global::().theme.copilot; + + Label::new("[COPILOT AUTH INFO]", style.auth_modal.clone()).boxed() + } +} diff --git a/crates/copilot/src/copilot.rs b/crates/copilot/src/copilot.rs index 9a24139ad6655a86e55d52332dceb99adb3381c5..2bdcedb2cc05f2cafee41e59b5d8dfd8cdd011d3 100644 --- a/crates/copilot/src/copilot.rs +++ b/crates/copilot/src/copilot.rs @@ -1,7 +1,9 @@ +mod auth_modal; mod request; use anyhow::{anyhow, Result}; use async_compression::futures::bufread::GzipDecoder; +use auth_modal::AuthModal; use client::Client; use gpui::{actions, AppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task}; use language::{point_from_lsp, point_to_lsp, Anchor, Bias, Buffer, BufferSnapshot, ToPointUtf16}; @@ -16,26 +18,36 @@ use std::{ use util::{ fs::remove_matching, github::latest_github_release, http::HttpClient, paths, ResultExt, }; +use workspace::Workspace; -actions!(copilot, [SignIn, SignOut]); +actions!(copilot, [SignIn, SignOut, ToggleAuthStatus]); pub fn init(client: Arc, cx: &mut MutableAppContext) { let copilot = cx.add_model(|cx| Copilot::start(client.http_client(), cx)); - cx.set_global(copilot); - cx.add_global_action(|_: &SignIn, cx: &mut MutableAppContext| { + cx.set_global(copilot.clone()); + cx.add_action(|workspace: &mut Workspace, _: &SignIn, cx| { if let Some(copilot) = Copilot::global(cx) { + if copilot.read(cx).status() == Status::Authorized { + return; + } + copilot .update(cx, |copilot, cx| copilot.sign_in(cx)) .detach_and_log_err(cx); + + workspace.toggle_modal(cx, |_workspace, cx| cx.add_view(|_cx| AuthModal {})); } }); - cx.add_global_action(|_: &SignOut, cx: &mut MutableAppContext| { + cx.add_action(|_: &mut Workspace, _: &SignOut, cx| { if let Some(copilot) = Copilot::global(cx) { copilot .update(cx, |copilot, cx| copilot.sign_out(cx)) .detach_and_log_err(cx); } }); + cx.add_action(|workspace: &mut Workspace, _: &ToggleAuthStatus, cx| { + workspace.toggle_modal(cx, |_workspace, cx| cx.add_view(|_cx| AuthModal {})) + }) } enum CopilotServer { @@ -62,7 +74,7 @@ pub enum Event { }, } -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq)] pub enum Status { Downloading, Error(Arc), @@ -138,6 +150,7 @@ impl Copilot { }) }) .detach(); + Self { server: CopilotServer::Downloading, } diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index d64a1d2499a690e245e16e94b1d76dcdc7327132..98419d1f4cfe3e19e7760756b5d07e7b07f9a38d 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -23,6 +23,7 @@ pub struct Theme { pub context_menu: ContextMenu, pub contacts_popover: ContactsPopover, pub contact_list: ContactList, + pub copilot: Copilot, pub contact_finder: ContactFinder, pub project_panel: ProjectPanel, pub command_palette: CommandPalette, @@ -115,6 +116,11 @@ pub struct AvatarStyle { pub outer_corner_radius: f32, } +#[derive(Deserialize, Default)] +pub struct Copilot { + pub auth_modal: TextStyle, +} + #[derive(Deserialize, Default)] pub struct ContactsPopover { #[serde(flatten)] diff --git a/styles/src/styleTree/app.ts b/styles/src/styleTree/app.ts index 423ce37d481e8f47bf9118ad6134b5c123a4ed31..f3315aa7cd9183c3560aef9388fdcbc62e3809cc 100644 --- a/styles/src/styleTree/app.ts +++ b/styles/src/styleTree/app.ts @@ -21,6 +21,7 @@ import incomingCallNotification from "./incomingCallNotification" import { ColorScheme } from "../themes/common/colorScheme" import feedback from "./feedback" import welcome from "./welcome" +import copilot from "./copilot" export default function app(colorScheme: ColorScheme): Object { return { @@ -34,6 +35,7 @@ export default function app(colorScheme: ColorScheme): Object { incomingCallNotification: incomingCallNotification(colorScheme), picker: picker(colorScheme), workspace: workspace(colorScheme), + copilot: copilot(colorScheme), welcome: welcome(colorScheme), contextMenu: contextMenu(colorScheme), editor: editor(colorScheme), diff --git a/styles/src/styleTree/copilot.ts b/styles/src/styleTree/copilot.ts new file mode 100644 index 0000000000000000000000000000000000000000..2c087da5a0801d6301daa6160deac8e14f116814 --- /dev/null +++ b/styles/src/styleTree/copilot.ts @@ -0,0 +1,11 @@ +import { ColorScheme } from "../themes/common/colorScheme" +import { text } from "./components"; + + +export default function copilot(colorScheme: ColorScheme) { + let layer = colorScheme.highest; + + return { + authModal: text(layer, "sans") + } +}