Add copilot theme, start sketching out the auth modal

Mikayla Maki created

Change summary

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(-)

Detailed changes

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::<Settings>().theme.copilot;
+
+        Label::new("[COPILOT AUTH INFO]", style.auth_modal.clone()).boxed()
+    }
+}

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<Client>, 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<str>),
@@ -138,6 +150,7 @@ impl Copilot {
             })
         })
         .detach();
+
         Self {
             server: CopilotServer::Downloading,
         }

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)]

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),

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")
+    }
+}