History

Don't hang the app when signing in offline

Conrad Irwin committed 2 years ago

Commit 78998331 parent 3094cb76 files · +229 −347Browse files

Unified · Split

6 files
  1. Cargo.lock +1 −0
  2. crates/auto_update2/src/auto_update.rs +2 −2
  3. crates/client2/src/client2.rs +101 −76
  4. crates/collab_ui2/Cargo.toml +1 −1
  5. crates/collab_ui2/src/collab_titlebar_item.rs +122 −268
  6. crates/ui2/src/components/icon.rs +2 −0
Cargo.lock+1−0
@@ -1949,6 +1949,7 @@ name = "collab_ui2" · 1948 unmodified lines
19491949 version = "0.1.0"
19501950 dependencies = [
19511951 "anyhow",
1952+ "auto_update2",
19521953 "call2",
19531954 "channel2",
19541955 "client2",
crates/auto_update2/src/auto_update.rs+2−2
@@ -6,7 +6,7 @@ use db::kvp::KEY_VALUE_STORE; · 5 unmodified lines
66 use db::RELEASE_CHANNEL;
77 use gpui::{
88 actions, AppContext, AsyncAppContext, Context as _, Model, ModelContext, SemanticVersion, Task,
9− ViewContext, VisualContext,
9+ ViewContext, VisualContext, WindowContext,
1010 };
1111 use isahc::AsyncBody;
1212 use serde::Deserialize;
@@ -125,7 +125,7 @@ pub fn init(http_client: Arc<dyn HttpClient>, server_url: String, cx: &mut AppCo · 112 unmodified lines
125125 }
126126 }
127127
128−pub fn check(_: &Check, cx: &mut ViewContext<Workspace>) {
128+pub fn check(_: &Check, cx: &mut WindowContext) {
129129 if let Some(updater) = AutoUpdater::get(cx) {
130130 updater.update(cx, |updater, cx| updater.poll(cx));
131131 } else {
crates/client2/src/client2.rs+101−76
@@ -11,8 +11,8 @@ use async_tungstenite::tungstenite::{ · 10 unmodified lines
1111 http::{Request, StatusCode},
1212 };
1313 use futures::{
14− future::LocalBoxFuture, AsyncReadExt, FutureExt, SinkExt, StreamExt, TryFutureExt as _,
15− TryStreamExt,
14+ channel::oneshot, future::LocalBoxFuture, AsyncReadExt, FutureExt, SinkExt, StreamExt,
15+ TryFutureExt as _, TryStreamExt,
1616 };
1717 use gpui::{
1818 actions, serde_json, AnyModel, AnyWeakModel, AppContext, AsyncAppContext, Model,
@@ -1020,91 +1020,116 @@ impl Client { · 1001 unmodified lines
10201020 ) -> Task<Result<Credentials>> {
10211021 let http = self.http.clone();
10221022 cx.spawn(|cx| async move {
1023− // Generate a pair of asymmetric encryption keys. The public key will be used by the
1024− // zed server to encrypt the user's access token, so that it can'be intercepted by
1025− // any other app running on the user's device.
1026− let (public_key, private_key) =
1027− rpc::auth::keypair().expect("failed to generate keypair for auth");
1028− let public_key_string =
1029− String::try_from(public_key).expect("failed to serialize public key for auth");
1030−
1031− if let Some((login, token)) = IMPERSONATE_LOGIN.as_ref().zip(ADMIN_API_TOKEN.as_ref()) {
1032− return Self::authenticate_as_admin(http, login.clone(), token.clone()).await;
1033− }
1034−
1035− // Start an HTTP server to receive the redirect from Zed's sign-in page.
1036− let server = tiny_http::Server::http("127.0.0.1:0").expect("failed to find open port");
1037− let port = server.server_addr().port();
1023+ let background = cx.background_executor().clone();
10381024
1039− // Open the Zed sign-in page in the user's browser, with query parameters that indicate
1040− // that the user is signing in from a Zed app running on the same device.
1041− let mut url = format!(
1042− "{}/native_app_signin?native_app_port={}&native_app_public_key={}",
1043− *ZED_SERVER_URL, port, public_key_string
1044− );
1025+ let (open_url_tx, open_url_rx) = oneshot::channel::<String>();
1026+ cx.update(|cx| {
1027+ cx.spawn(move |cx| async move {
1028+ let url = open_url_rx.await?;
1029+ cx.update(|cx| cx.open_url(&url))
1030+ })
1031+ .detach_and_log_err(cx);
1032+ })
1033+ .log_err();
1034+
1035+ let credentials = background
1036+ .clone()
1037+ .spawn(async move {
1038+ // Generate a pair of asymmetric encryption keys. The public key will be used by the
1039+ // zed server to encrypt the user's access token, so that it can'be intercepted by
1040+ // any other app running on the user's device.
1041+ let (public_key, private_key) =
1042+ rpc::auth::keypair().expect("failed to generate keypair for auth");
1043+ let public_key_string = String::try_from(public_key)
1044+ .expect("failed to serialize public key for auth");
1045+
1046+ if let Some((login, token)) =
1047+ IMPERSONATE_LOGIN.as_ref().zip(ADMIN_API_TOKEN.as_ref())
1048+ {
1049+ return Self::authenticate_as_admin(http, login.clone(), token.clone())
1050+ .await;
1051+ }
10451052
1046− if let Some(impersonate_login) = IMPERSONATE_LOGIN.as_ref() {
1047− log::info!("impersonating user @{}", impersonate_login);
1048− write!(&mut url, "&impersonate={}", impersonate_login).unwrap();
1049− }
1053+ // Start an HTTP server to receive the redirect from Zed's sign-in page.
1054+ let server =
1055+ tiny_http::Server::http("127.0.0.1:0").expect("failed to find open port");
1056+ let port = server.server_addr().port();
1057+
1058+ // Open the Zed sign-in page in the user's browser, with query parameters that indicate
1059+ // that the user is signing in from a Zed app running on the same device.
1060+ let mut url = format!(
1061+ "{}/native_app_signin?native_app_port={}&native_app_public_key={}",
1062+ *ZED_SERVER_URL, port, public_key_string
1063+ );
1064+
1065+ if let Some(impersonate_login) = IMPERSONATE_LOGIN.as_ref() {
1066+ log::info!("impersonating user @{}", impersonate_login);
1067+ write!(&mut url, "&impersonate={}", impersonate_login).unwrap();
1068+ }
10501069
1051− cx.update(|cx| cx.open_url(&url))?;
1052−
1053− // Receive the HTTP request from the user's browser. Retrieve the user id and encrypted
1054− // access token from the query params.
1055− //
1056− // TODO - Avoid ever starting more than one HTTP server. Maybe switch to using a
1057− // custom URL scheme instead of this local HTTP server.
1058− let (user_id, access_token) = cx
1059− .spawn(|_| async move {
1060− for _ in 0..100 {
1061− if let Some(req) = server.recv_timeout(Duration::from_secs(1))? {
1062− let path = req.url();
1063− let mut user_id = None;
1064− let mut access_token = None;
1065− let url = Url::parse(&format!("http://example.com{}", path))
1066− .context("failed to parse login notification url")?;
1067− for (key, value) in url.query_pairs() {
1068− if key == "access_token" {
1069− access_token = Some(value.to_string());
1070− } else if key == "user_id" {
1071− user_id = Some(value.to_string());
1070+ open_url_tx.send(url).log_err();
1071+
1072+ // Receive the HTTP request from the user's browser. Retrieve the user id and encrypted
1073+ // access token from the query params.
1074+ //
1075+ // TODO - Avoid ever starting more than one HTTP server. Maybe switch to using a
1076+ // custom URL scheme instead of this local HTTP server.
1077+ let (user_id, access_token) = background
1078+ .spawn(async move {
1079+ for _ in 0..100 {
1080+ if let Some(req) = server.recv_timeout(Duration::from_secs(1))? {
1081+ let path = req.url();
1082+ let mut user_id = None;
1083+ let mut access_token = None;
1084+ let url = Url::parse(&format!("http://example.com{}", path))
1085+ .context("failed to parse login notification url")?;
1086+ for (key, value) in url.query_pairs() {
1087+ if key == "access_token" {
1088+ access_token = Some(value.to_string());
1089+ } else if key == "user_id" {
1090+ user_id = Some(value.to_string());
1091+ }
1092+ }
1093+
1094+ let post_auth_url =
1095+ format!("{}/native_app_signin_succeeded", *ZED_SERVER_URL);
1096+ req.respond(
1097+ tiny_http::Response::empty(302).with_header(
1098+ tiny_http::Header::from_bytes(
1099+ &b"Location"[..],
1100+ post_auth_url.as_bytes(),
1101+ )
1102+ .unwrap(),
1103+ ),
1104+ )
1105+ .context("failed to respond to login http request")?;
1106+ return Ok((
1107+ user_id
1108+ .ok_or_else(|| anyhow!("missing user_id parameter"))?,
1109+ access_token.ok_or_else(|| {
1110+ anyhow!("missing access_token parameter")
1111+ })?,
1112+ ));
10721113 }
10731114 }
10741115
1075− let post_auth_url =
1076− format!("{}/native_app_signin_succeeded", *ZED_SERVER_URL);
1077− req.respond(
1078− tiny_http::Response::empty(302).with_header(
1079− tiny_http::Header::from_bytes(
1080− &b"Location"[..],
1081− post_auth_url.as_bytes(),
1082− )
1083− .unwrap(),
1084− ),
1085− )
1086− .context("failed to respond to login http request")?;
1087− return Ok((
1088− user_id.ok_or_else(|| anyhow!("missing user_id parameter"))?,
1089− access_token
1090− .ok_or_else(|| anyhow!("missing access_token parameter"))?,
1091− ));
1092− }
1093− }
1116+ Err(anyhow!("didn't receive login redirect"))
1117+ })
1118+ .await?;
10941119
1095− Err(anyhow!("didn't receive login redirect"))
1120+ let access_token = private_key
1121+ .decrypt_string(&access_token)
1122+ .context("failed to decrypt access token")?;
1123+
1124+ Ok(Credentials {
1125+ user_id: user_id.parse()?,
1126+ access_token,
1127+ })
10961128 })
10971129 .await?;
10981130
1099− let access_token = private_key
1100− .decrypt_string(&access_token)
1101− .context("failed to decrypt access token")?;
11021131 cx.update(|cx| cx.activate(true))?;
1103−
1104− Ok(Credentials {
1105− user_id: user_id.parse()?,
1106− access_token,
1107− })
1132+ Ok(credentials)
11081133 })
11091134 }
11101135
crates/collab_ui2/Cargo.toml+1−1
@@ -22,7 +22,7 @@ test-support = [ · 21 unmodified lines
2222 ]
2323
2424 [dependencies]
25−# auto_update = { path = "../auto_update" }
25+auto_update = { package = "auto_update2", path = "../auto_update2" }
2626 db = { package = "db2", path = "../db2" }
2727 call = { package = "call2", path = "../call2" }
2828 client = { package = "client2", path = "../client2" }
crates/collab_ui2/src/collab_titlebar_item.rs+122−268
@@ -1,10 +1,11 @@
11 use crate::face_pile::FacePile;
2+use auto_update::AutoUpdateStatus;
23 use call::{ActiveCall, ParticipantLocation, Room};
3−use client::{proto::PeerId, Client, ParticipantIndex, SignOut, User, UserStore};
4+use client::{proto::PeerId, Client, ParticipantIndex, User, UserStore};
45 use gpui::{
5− actions, canvas, div, overlay, point, px, rems, Action, AppContext, DismissEvent, Div, Element,
6− FocusableView, Hsla, InteractiveElement, IntoElement, Model, ParentElement, Path, Render,
7− Stateful, StatefulInteractiveElement, Styled, Subscription, ViewContext, VisualContext,
6+ actions, canvas, div, overlay, point, px, rems, Action, AnyElement, AppContext, DismissEvent,
7+ Div, Element, FocusableView, Hsla, InteractiveElement, IntoElement, Model, ParentElement, Path,
8+ Render, Stateful, StatefulInteractiveElement, Styled, Subscription, ViewContext, VisualContext,
89 WeakView, WindowBounds,
910 };
1011 use project::{Project, RepositoryEntry};
@@ -16,7 +17,7 @@ use ui::{ · 5 unmodified lines
1617 IconButton, IconElement, KeyBinding, Tooltip,
1718 };
1819 use util::ResultExt;
19−use workspace::{notifications::NotifyResultExt, Feedback, Workspace, WORKSPACE_DB};
20+use workspace::{notifications::NotifyResultExt, Workspace, WORKSPACE_DB};
2021
2122 const MAX_PROJECT_NAME_LENGTH: usize = 40;
2223 const MAX_BRANCH_NAME_LENGTH: usize = 40;
@@ -52,7 +53,6 @@ pub struct CollabTitlebarItem { · 29 unmodified lines
5253 workspace: WeakView<Workspace>,
5354 //branch_popover: Option<ViewHandle<BranchList>>,
5455 project_popover: Option<recent_projects::RecentProjects>,
55− //user_menu: ViewHandle<ContextMenu>,
5656 _subscriptions: Vec<Subscription>,
5757 }
5858
@@ -232,88 +232,17 @@ impl Render for CollabTitlebarItem { · 173 unmodified lines
232232 }),
233233 )
234234 })
235− .child(h_stack().px_1p5().map(|this| {
236− if let Some(user) = current_user {
237− // TODO: Finish implementing user menu popover
238− //
239− this.child(
240− popover_menu("user-menu")
241− .menu(|cx| {
242− ContextMenu::build(cx, |menu, _| {
243− menu.action(
244− "Settings",
245− zed_actions::OpenSettings.boxed_clone(),
246− )
247− .action("Theme", theme_selector::Toggle.boxed_clone())
248− .separator()
249− .action(
250− "Share Feedback",
251− feedback::GiveFeedback.boxed_clone(),
252− )
253− .action("Sign Out", client::SignOut.boxed_clone())
254− })
255− })
256− .trigger(
257− ButtonLike::new("user-menu")
258− .child(
259− h_stack()
260− .gap_0p5()
261− .child(Avatar::new(user.avatar_uri.clone()))
262− .child(
263− IconElement::new(Icon::ChevronDown)
264− .color(Color::Muted),
265− ),
266− )
267− .style(ButtonStyle::Subtle)
268− .tooltip(move |cx| {
269− Tooltip::text("Toggle User Menu", cx)
270− }),
271− )
272− .anchor(gpui::AnchorCorner::TopRight),
273− )
235+ .map(|el| {
236+ let status = self.client.status();
237+ let status = &*status.borrow();
238+ if matches!(status, client::Status::Connected { .. }) {
239+ el.child(self.render_user_menu_button(cx))
274240 } else {
275− this.child(Button::new("sign_in", "Sign in").on_click(move |_, cx| {
276− let client = client.clone();
277− cx.spawn(move |mut cx| async move {
278− client
279− .authenticate_and_connect(true, &cx)
280− .await
281− .notify_async_err(&mut cx);
282− })
283− .detach();
284− }))
285− .child(
286− popover_menu("user-menu")
287− .menu(|cx| {
288− ContextMenu::build(cx, |menu, _| {
289− menu.action(
290− "Settings",
291− zed_actions::OpenSettings.boxed_clone(),
292− )
293− .action("Theme", theme_selector::Toggle.boxed_clone())
294− .separator()
295− .action(
296− "Share Feedback",
297− feedback::GiveFeedback.boxed_clone(),
298− )
299− })
300− })
301− .trigger(
302− ButtonLike::new("user-menu")
303− .child(
304− h_stack().gap_0p5().child(
305− IconElement::new(Icon::ChevronDown)
306− .color(Color::Muted),
307− ),
308− )
309− .style(ButtonStyle::Subtle)
310− .tooltip(move |cx| {
311− Tooltip::text("Toggle User Menu", cx)
312− }),
313− ),
314− )
241+ el.children(self.render_connection_status(status, cx))
242+ .child(self.render_sign_in_button(cx))
243+ .child(self.render_user_menu_button(cx))
315244 }
316− })),
245+ }),
317246 )
318247 }
319248 }
@@ -355,12 +284,6 @@ impl CollabTitlebarItem { · 35 unmodified lines
355284 project,
356285 user_store,
357286 client,
358− // user_menu: cx.add_view(|cx| {
359− // let view_id = cx.view_id();
360− // let mut menu = ContextMenu::new(view_id, cx);
361− // menu.set_position_mode(OverlayPositionMode::Local);
362− // menu
363− // }),
364287 // branch_popover: None,
365288 project_popover: None,
366289 _subscriptions: subscriptions,
@@ -535,34 +458,6 @@ impl CollabTitlebarItem { · 168 unmodified lines
535458 .log_err();
536459 }
537460
538− // pub fn toggle_user_menu(&mut self, _: &ToggleUserMenu, cx: &mut ViewContext<Self>) {
539− // self.user_menu.update(cx, |user_menu, cx| {
540− // let items = if let Some(_) = self.user_store.read(cx).current_user() {
541− // vec![
542− // ContextMenuItem::action("Settings", zed_actions::OpenSettings),
543− // ContextMenuItem::action("Theme", theme_selector::Toggle),
544− // ContextMenuItem::separator(),
545− // ContextMenuItem::action(
546− // "Share Feedback",
547− // feedback::feedback_editor::GiveFeedback,
548− // ),
549− // ContextMenuItem::action("Sign Out", SignOut),
550− // ]
551− // } else {
552− // vec![
553− // ContextMenuItem::action("Settings", zed_actions::OpenSettings),
554− // ContextMenuItem::action("Theme", theme_selector::Toggle),
555− // ContextMenuItem::separator(),
556− // ContextMenuItem::action(
557− // "Share Feedback",
558− // feedback::feedback_editor::GiveFeedback,
559− // ),
560− // ]
561− // };
562− // user_menu.toggle(Default::default(), AnchorCorner::TopRight, items, cx);
563− // });
564− // }
565−
566461 // fn render_branches_popover_host<'a>(
567462 // &'a self,
568463 // _theme: &'a theme::Titlebar,
@@ -696,154 +591,113 @@ impl CollabTitlebarItem { · 127 unmodified lines
696591 cx.notify();
697592 }
698593
699− // fn render_user_menu_button(
700− // &self,
701− // theme: &Theme,
702− // avatar: Option<Arc<ImageData>>,
703− // cx: &mut ViewContext<Self>,
704− // ) -> AnyElement<Self> {
705− // let tooltip = theme.tooltip.clone();
706− // let user_menu_button_style = if avatar.is_some() {
707− // &theme.titlebar.user_menu.user_menu_button_online
708− // } else {
709− // &theme.titlebar.user_menu.user_menu_button_offline
710− // };
711−
712− // let avatar_style = &user_menu_button_style.avatar;
713− // Stack::new()
714− // .with_child(
715− // MouseEventHandler::new::<ToggleUserMenu, _>(0, cx, |state, _| {
716− // let style = user_menu_button_style
717− // .user_menu
718− // .inactive_state()
719− // .style_for(state);
720−
721− // let mut dropdown = Flex::row().align_children_center();
722−
723− // if let Some(avatar_img) = avatar {
724− // dropdown = dropdown.with_child(Self::render_face(
725− // avatar_img,
726− // *avatar_style,
727− // Color::transparent_black(),
728− // None,
729− // ));
730− // };
731−
732− // dropdown
733− // .with_child(
734− // Svg::new("icons/caret_down.svg")
735− // .with_color(user_menu_button_style.icon.color)
736− // .constrained()
737− // .with_width(user_menu_button_style.icon.width)
738− // .contained()
739− // .into_any(),
740− // )
741− // .aligned()
742− // .constrained()
743− // .with_height(style.width)
744− // .contained()
745− // .with_style(style.container)
746− // .into_any()
747− // })
748− // .with_cursor_style(CursorStyle::PointingHand)
749− // .on_down(MouseButton::Left, move |_, this, cx| {
750− // this.user_menu.update(cx, |menu, _| menu.delay_cancel());
751− // })
752− // .on_click(MouseButton::Left, move |_, this, cx| {
753− // this.toggle_user_menu(&Default::default(), cx)
754− // })
755− // .with_tooltip::<ToggleUserMenu>(
756− // 0,
757− // "Toggle User Menu".to_owned(),
758− // Some(Box::new(ToggleUserMenu)),
759− // tooltip,
760− // cx,
761− // )
762− // .contained(),
763− // )
764− // .with_child(
765− // ChildView::new(&self.user_menu, cx)
766− // .aligned()
767− // .bottom()
768− // .right(),
769− // )
770− // .into_any()
771− // }
772−
773− // fn render_sign_in_button(&self, theme: &Theme, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
774− // let titlebar = &theme.titlebar;
775− // MouseEventHandler::new::<SignIn, _>(0, cx, |state, _| {
776− // let style = titlebar.sign_in_button.inactive_state().style_for(state);
777− // Label::new("Sign In", style.text.clone())
778− // .contained()
779− // .with_style(style.container)
780− // })
781− // .with_cursor_style(CursorStyle::PointingHand)
782− // .on_click(MouseButton::Left, move |_, this, cx| {
783− // let client = this.client.clone();
784− // cx.app_context()
785− // .spawn(|cx| async move { client.authenticate_and_connect(true, &cx).await })
786− // .detach_and_log_err(cx);
787− // })
788− // .into_any()
789− // }
594+ fn render_connection_status(
595+ &self,
596+ status: &client::Status,
597+ cx: &mut ViewContext<Self>,
598+ ) -> Option<AnyElement> {
599+ match status {
600+ client::Status::ConnectionError
601+ | client::Status::ConnectionLost
602+ | client::Status::Reauthenticating { .. }
603+ | client::Status::Reconnecting { .. }
604+ | client::Status::ReconnectionError { .. } => Some(
605+ div()
606+ .id("disconnected")
607+ .bg(gpui::red()) // todo!() @nate
608+ .child(IconElement::new(Icon::Disconnected))
609+ .tooltip(|cx| Tooltip::text("Disconnected", cx))
610+ .into_any_element(),
611+ ),
612+ client::Status::UpgradeRequired => {
613+ let auto_updater = auto_update::AutoUpdater::get(cx);
614+ let label = match auto_updater.map(|auto_update| auto_update.read(cx).status()) {
615+ Some(AutoUpdateStatus::Updated) => "Please restart Zed to Collaborate",
616+ Some(AutoUpdateStatus::Installing)
617+ | Some(AutoUpdateStatus::Downloading)
618+ | Some(AutoUpdateStatus::Checking) => "Updating...",
619+ Some(AutoUpdateStatus::Idle) | Some(AutoUpdateStatus::Errored) | None => {
620+ "Please update Zed to Collaborate"
621+ }
622+ };
623+
624+ Some(
625+ div()
626+ .bg(gpui::red()) // todo!() @nate
627+ .child(Button::new("connection-status", label).on_click(|_, cx| {
628+ if let Some(auto_updater) = auto_update::AutoUpdater::get(cx) {
629+ if auto_updater.read(cx).status() == AutoUpdateStatus::Updated {
630+ workspace::restart(&Default::default(), cx);
631+ return;
632+ }
633+ }
634+ auto_update::check(&Default::default(), cx);
635+ }))
636+ .into_any_element(),
637+ )
638+ }
639+ _ => None,
640+ }
641+ }
790642
791− // fn render_connection_status(
792− // &self,
793− // status: &client::Status,
794− // cx: &mut ViewContext<Self>,
795− // ) -> Option<AnyElement<Self>> {
796− // enum ConnectionStatusButton {}
797−
798− // let theme = &theme::current(cx).clone();
799− // match status {
800− // client::Status::ConnectionError
801− // | client::Status::ConnectionLost
802− // | client::Status::Reauthenticating { .. }
803− // | client::Status::Reconnecting { .. }
804− // | client::Status::ReconnectionError { .. } => Some(
805− // Svg::new("icons/disconnected.svg")
806− // .with_color(theme.titlebar.offline_icon.color)
807− // .constrained()
808− // .with_width(theme.titlebar.offline_icon.width)
809− // .aligned()
810− // .contained()
811− // .with_style(theme.titlebar.offline_icon.container)
812− // .into_any(),
813− // ),
814− // client::Status::UpgradeRequired => {
815− // let auto_updater = auto_update::AutoUpdater::get(cx);
816− // let label = match auto_updater.map(|auto_update| auto_update.read(cx).status()) {
817− // Some(AutoUpdateStatus::Updated) => "Please restart Zed to Collaborate",
818− // Some(AutoUpdateStatus::Installing)
819− // | Some(AutoUpdateStatus::Downloading)
820− // | Some(AutoUpdateStatus::Checking) => "Updating...",
821− // Some(AutoUpdateStatus::Idle) | Some(AutoUpdateStatus::Errored) | None => {
822− // "Please update Zed to Collaborate"
823− // }
824− // };
643+ pub fn render_sign_in_button(&mut self, _: &mut ViewContext<Self>) -> Button {
644+ let client = self.client.clone();
645+ Button::new("sign_in", "Sign in").on_click(move |_, cx| {
646+ let client = client.clone();
647+ cx.spawn(move |mut cx| async move {
648+ client
649+ .authenticate_and_connect(true, &cx)
650+ .await
651+ .notify_async_err(&mut cx);
652+ })
653+ .detach();
654+ })
655+ }
825656
826− // Some(
827− // MouseEventHandler::new::<ConnectionStatusButton, _>(0, cx, |_, _| {
828− // Label::new(label, theme.titlebar.outdated_warning.text.clone())
829− // .contained()
830− // .with_style(theme.titlebar.outdated_warning.container)
831− // .aligned()
832− // })
833− // .with_cursor_style(CursorStyle::PointingHand)
834− // .on_click(MouseButton::Left, |_, _, cx| {
835− // if let Some(auto_updater) = auto_update::AutoUpdater::get(cx) {
836− // if auto_updater.read(cx).status() == AutoUpdateStatus::Updated {
837− // workspace::restart(&Default::default(), cx);
838− // return;
839− // }
840− // }
841− // auto_update::check(&Default::default(), cx);
842− // })
843− // .into_any(),
844− // )
845− // }
846− // _ => None,
847− // }
848− // }
657+ pub fn render_user_menu_button(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
658+ if let Some(user) = self.user_store.read(cx).current_user() {
659+ popover_menu("user-menu")
660+ .menu(|cx| {
661+ ContextMenu::build(cx, |menu, _| {
662+ menu.action("Settings", zed_actions::OpenSettings.boxed_clone())
663+ .action("Theme", theme_selector::Toggle.boxed_clone())
664+ .separator()
665+ .action("Share Feedback", feedback::GiveFeedback.boxed_clone())
666+ .action("Sign Out", client::SignOut.boxed_clone())
667+ })
668+ })
669+ .trigger(
670+ ButtonLike::new("user-menu")
671+ .child(
672+ h_stack()
673+ .gap_0p5()
674+ .child(Avatar::new(user.avatar_uri.clone()))
675+ .child(IconElement::new(Icon::ChevronDown).color(Color::Muted)),
676+ )
677+ .style(ButtonStyle::Subtle)
678+ .tooltip(move |cx| Tooltip::text("Toggle User Menu", cx)),
679+ )
680+ .anchor(gpui::AnchorCorner::TopRight)
681+ } else {
682+ popover_menu("user-menu")
683+ .menu(|cx| {
684+ ContextMenu::build(cx, |menu, _| {
685+ menu.action("Settings", zed_actions::OpenSettings.boxed_clone())
686+ .action("Theme", theme_selector::Toggle.boxed_clone())
687+ .separator()
688+ .action("Share Feedback", feedback::GiveFeedback.boxed_clone())
689+ })
690+ })
691+ .trigger(
692+ ButtonLike::new("user-menu")
693+ .child(
694+ h_stack()
695+ .gap_0p5()
696+ .child(IconElement::new(Icon::ChevronDown).color(Color::Muted)),
697+ )
698+ .style(ButtonStyle::Subtle)
699+ .tooltip(move |cx| Tooltip::text("Toggle User Menu", cx)),
700+ )
701+ }
702+ }
849703 }
crates/ui2/src/components/icon.rs+2−0
@@ -50,6 +50,7 @@ pub enum Icon { · 49 unmodified lines
5050 CopilotError,
5151 CopilotDisabled,
5252 Dash,
53+ Disconnected,
5354 Envelope,
5455 ExternalLink,
5556 ExclamationTriangle,
@@ -129,6 +130,7 @@ impl Icon { · 73 unmodified lines
129130 Icon::CopilotError => "icons/copilot_error.svg",
130131 Icon::CopilotDisabled => "icons/copilot_disabled.svg",
131132 Icon::Dash => "icons/dash.svg",
133+ Icon::Disconnected => "icons/disconnected.svg",
132134 Icon::Envelope => "icons/feedback.svg",
133135 Icon::ExclamationTriangle => "icons/warning.svg",
134136 Icon::ExternalLink => "icons/external_link.svg",

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t