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
1949version = "0.1.0"1949version = "0.1.0"
1950dependencies = [1950dependencies = [
1951 "anyhow",1951 "anyhow",
1952 "auto_update2",
1952 "call2",1953 "call2",
1953 "channel2",1954 "channel2",
1954 "client2",1955 "client2",
crates/auto_update2/src/auto_update.rs+2−2
@@ -6,7 +6,7 @@ use db::kvp::KEY_VALUE_STORE; · 5 unmodified lines
6use db::RELEASE_CHANNEL;6use db::RELEASE_CHANNEL;
7use gpui::{7use gpui::{
8 actions, AppContext, AsyncAppContext, Context as _, Model, ModelContext, SemanticVersion, Task,8 actions, AppContext, AsyncAppContext, Context as _, Model, ModelContext, SemanticVersion, Task,
9 ViewContext, VisualContext,9 ViewContext, VisualContext, WindowContext,
10};10};
11use isahc::AsyncBody;11use isahc::AsyncBody;
12use serde::Deserialize;12use serde::Deserialize;
@@ -125,7 +125,7 @@ pub fn init(http_client: Arc<dyn HttpClient>, server_url: String, cx: &mut AppCo · 112 unmodified lines
125 }125 }
126}126}
127 127
128pub fn check(_: &Check, cx: &mut ViewContext<Workspace>) {128pub fn check(_: &Check, cx: &mut WindowContext) {
129 if let Some(updater) = AutoUpdater::get(cx) {129 if let Some(updater) = AutoUpdater::get(cx) {
130 updater.update(cx, |updater, cx| updater.poll(cx));130 updater.update(cx, |updater, cx| updater.poll(cx));
131 } else {131 } else {
crates/client2/src/client2.rs+101−76
@@ -11,8 +11,8 @@ use async_tungstenite::tungstenite::{ · 10 unmodified lines
11 http::{Request, StatusCode},11 http::{Request, StatusCode},
12};12};
13use futures::{13use futures::{
14 future::LocalBoxFuture, AsyncReadExt, FutureExt, SinkExt, StreamExt, TryFutureExt as _,14 channel::oneshot, future::LocalBoxFuture, AsyncReadExt, FutureExt, SinkExt, StreamExt,
15 TryStreamExt,15 TryFutureExt as _, TryStreamExt,
16};16};
17use gpui::{17use gpui::{
18 actions, serde_json, AnyModel, AnyWeakModel, AppContext, AsyncAppContext, Model,18 actions, serde_json, AnyModel, AnyWeakModel, AppContext, AsyncAppContext, Model,
@@ -1020,91 +1020,116 @@ impl Client { · 1001 unmodified lines
1020 ) -> Task<Result<Credentials>> {1020 ) -> Task<Result<Credentials>> {
1021 let http = self.http.clone();1021 let http = self.http.clone();
1022 cx.spawn(|cx| async move {1022 cx.spawn(|cx| async move {
1023 // Generate a pair of asymmetric encryption keys. The public key will be used by the1023 let background = cx.background_executor().clone();
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();
1038 1024
1039 // Open the Zed sign-in page in the user's browser, with query parameters that indicate1025 let (open_url_tx, open_url_rx) = oneshot::channel::<String>();
1040 // that the user is signing in from a Zed app running on the same device.1026 cx.update(|cx| {
1041 let mut url = format!(1027 cx.spawn(move |cx| async move {
1042 "{}/native_app_signin?native_app_port={}&native_app_public_key={}",1028 let url = open_url_rx.await?;
1043 *ZED_SERVER_URL, port, public_key_string1029 cx.update(|cx| cx.open_url(&url))
1044 );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 }
1045 1052
1046 if let Some(impersonate_login) = IMPERSONATE_LOGIN.as_ref() {1053 // Start an HTTP server to receive the redirect from Zed's sign-in page.
1047 log::info!("impersonating user @{}", impersonate_login);1054 let server =
1048 write!(&mut url, "&impersonate={}", impersonate_login).unwrap();1055 tiny_http::Server::http("127.0.0.1:0").expect("failed to find open port");
1049 }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 }
1050 1069
1051 cx.update(|cx| cx.open_url(&url))?;1070 open_url_tx.send(url).log_err();
1052 1071
1053 // Receive the HTTP request from the user's browser. Retrieve the user id and encrypted1072 // Receive the HTTP request from the user's browser. Retrieve the user id and encrypted
1054 // access token from the query params.1073 // access token from the query params.
1055 //1074 //
1056 // TODO - Avoid ever starting more than one HTTP server. Maybe switch to using a1075 // TODO - Avoid ever starting more than one HTTP server. Maybe switch to using a
1057 // custom URL scheme instead of this local HTTP server.1076 // custom URL scheme instead of this local HTTP server.
1058 let (user_id, access_token) = cx1077 let (user_id, access_token) = background
1059 .spawn(|_| async move {1078 .spawn(async move {
1060 for _ in 0..100 {1079 for _ in 0..100 {
1061 if let Some(req) = server.recv_timeout(Duration::from_secs(1))? {1080 if let Some(req) = server.recv_timeout(Duration::from_secs(1))? {
1062 let path = req.url();1081 let path = req.url();
1063 let mut user_id = None;1082 let mut user_id = None;
1064 let mut access_token = None;1083 let mut access_token = None;
1065 let url = Url::parse(&format!("http://example.com{}", path))1084 let url = Url::parse(&format!("http://example.com{}", path))
1066 .context("failed to parse login notification url")?;1085 .context("failed to parse login notification url")?;
1067 for (key, value) in url.query_pairs() {1086 for (key, value) in url.query_pairs() {
1068 if key == "access_token" {1087 if key == "access_token" {
1069 access_token = Some(value.to_string());1088 access_token = Some(value.to_string());
1070 } else if key == "user_id" {1089 } else if key == "user_id" {
1071 user_id = Some(value.to_string());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 ));
1072 }1113 }
1073 }1114 }
1074 1115
1075 let post_auth_url =1116 Err(anyhow!("didn't receive login redirect"))
1076 format!("{}/native_app_signin_succeeded", *ZED_SERVER_URL);1117 })
1077 req.respond(1118 .await?;
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 }
1094 1119
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 })
1096 })1128 })
1097 .await?;1129 .await?;
1098 1130
1099 let access_token = private_key
1100 .decrypt_string(&access_token)
1101 .context("failed to decrypt access token")?;
1102 cx.update(|cx| cx.activate(true))?;1131 cx.update(|cx| cx.activate(true))?;
1103 1132 Ok(credentials)
1104 Ok(Credentials {
1105 user_id: user_id.parse()?,
1106 access_token,
1107 })
1108 })1133 })
1109 }1134 }
1110 1135
crates/collab_ui2/Cargo.toml+1−1
@@ -22,7 +22,7 @@ test-support = [ · 21 unmodified lines
22]22]
23 23
24[dependencies]24[dependencies]
25# auto_update = { path = "../auto_update" }25auto_update = { package = "auto_update2", path = "../auto_update2" }
26db = { package = "db2", path = "../db2" }26db = { package = "db2", path = "../db2" }
27call = { package = "call2", path = "../call2" }27call = { package = "call2", path = "../call2" }
28client = { package = "client2", path = "../client2" }28client = { package = "client2", path = "../client2" }
crates/collab_ui2/src/collab_titlebar_item.rs+122−268
@@ -1,10 +1,11 @@
1use crate::face_pile::FacePile;1use crate::face_pile::FacePile;
2use auto_update::AutoUpdateStatus;
2use call::{ActiveCall, ParticipantLocation, Room};3use call::{ActiveCall, ParticipantLocation, Room};
3use client::{proto::PeerId, Client, ParticipantIndex, SignOut, User, UserStore};4use client::{proto::PeerId, Client, ParticipantIndex, User, UserStore};
4use gpui::{5use gpui::{
5 actions, canvas, div, overlay, point, px, rems, Action, AppContext, DismissEvent, Div, Element,6 actions, canvas, div, overlay, point, px, rems, Action, AnyElement, AppContext, DismissEvent,
6 FocusableView, Hsla, InteractiveElement, IntoElement, Model, ParentElement, Path, Render,7 Div, Element, FocusableView, Hsla, InteractiveElement, IntoElement, Model, ParentElement, Path,
7 Stateful, StatefulInteractiveElement, Styled, Subscription, ViewContext, VisualContext,8 Render, Stateful, StatefulInteractiveElement, Styled, Subscription, ViewContext, VisualContext,
8 WeakView, WindowBounds,9 WeakView, WindowBounds,
9};10};
10use project::{Project, RepositoryEntry};11use project::{Project, RepositoryEntry};
@@ -16,7 +17,7 @@ use ui::{ · 5 unmodified lines
16 IconButton, IconElement, KeyBinding, Tooltip,17 IconButton, IconElement, KeyBinding, Tooltip,
17};18};
18use util::ResultExt;19use util::ResultExt;
19use workspace::{notifications::NotifyResultExt, Feedback, Workspace, WORKSPACE_DB};20use workspace::{notifications::NotifyResultExt, Workspace, WORKSPACE_DB};
20 21
21const MAX_PROJECT_NAME_LENGTH: usize = 40;22const MAX_PROJECT_NAME_LENGTH: usize = 40;
22const MAX_BRANCH_NAME_LENGTH: usize = 40;23const MAX_BRANCH_NAME_LENGTH: usize = 40;
@@ -52,7 +53,6 @@ pub struct CollabTitlebarItem { · 29 unmodified lines
52 workspace: WeakView<Workspace>,53 workspace: WeakView<Workspace>,
53 //branch_popover: Option<ViewHandle<BranchList>>,54 //branch_popover: Option<ViewHandle<BranchList>>,
54 project_popover: Option<recent_projects::RecentProjects>,55 project_popover: Option<recent_projects::RecentProjects>,
55 //user_menu: ViewHandle<ContextMenu>,
56 _subscriptions: Vec<Subscription>,56 _subscriptions: Vec<Subscription>,
57}57}
58 58
@@ -232,88 +232,17 @@ impl Render for CollabTitlebarItem { · 173 unmodified lines
232 }),232 }),
233 )233 )
234 })234 })
235 .child(h_stack().px_1p5().map(|this| {235 .map(|el| {
236 if let Some(user) = current_user {236 let status = self.client.status();
237 // TODO: Finish implementing user menu popover237 let status = &*status.borrow();
238 //238 if matches!(status, client::Status::Connected { .. }) {
239 this.child(239 el.child(self.render_user_menu_button(cx))
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 )
274 } else {240 } else {
275 this.child(Button::new("sign_in", "Sign in").on_click(move |_, cx| {241 el.children(self.render_connection_status(status, cx))
276 let client = client.clone();242 .child(self.render_sign_in_button(cx))
277 cx.spawn(move |mut cx| async move {243 .child(self.render_user_menu_button(cx))
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 )
315 }244 }
316 })),245 }),
317 )246 )
318 }247 }
319}248}
@@ -355,12 +284,6 @@ impl CollabTitlebarItem { · 35 unmodified lines
355 project,284 project,
356 user_store,285 user_store,
357 client,286 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 // }),
364 // branch_popover: None,287 // branch_popover: None,
365 project_popover: None,288 project_popover: None,
366 _subscriptions: subscriptions,289 _subscriptions: subscriptions,
@@ -535,34 +458,6 @@ impl CollabTitlebarItem { · 168 unmodified lines
535 .log_err();458 .log_err();
536 }459 }
537 460
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
566 // fn render_branches_popover_host<'a>(461 // fn render_branches_popover_host<'a>(
567 // &'a self,462 // &'a self,
568 // _theme: &'a theme::Titlebar,463 // _theme: &'a theme::Titlebar,
@@ -696,154 +591,113 @@ impl CollabTitlebarItem { · 127 unmodified lines
696 cx.notify();591 cx.notify();
697 }592 }
698 593
699 // fn render_user_menu_button(594 fn render_connection_status(
700 // &self,595 &self,
701 // theme: &Theme,596 status: &client::Status,
702 // avatar: Option<Arc<ImageData>>,597 cx: &mut ViewContext<Self>,
703 // cx: &mut ViewContext<Self>,598 ) -> Option<AnyElement> {
704 // ) -> AnyElement<Self> {599 match status {
705 // let tooltip = theme.tooltip.clone();600 client::Status::ConnectionError
706 // let user_menu_button_style = if avatar.is_some() {601 | client::Status::ConnectionLost
707 // &theme.titlebar.user_menu.user_menu_button_online602 | client::Status::Reauthenticating { .. }
708 // } else {603 | client::Status::Reconnecting { .. }
709 // &theme.titlebar.user_menu.user_menu_button_offline604 | client::Status::ReconnectionError { .. } => Some(
710 // };605 div()
711 606 .id("disconnected")
712 // let avatar_style = &user_menu_button_style.avatar;607 .bg(gpui::red()) // todo!() @nate
713 // Stack::new()608 .child(IconElement::new(Icon::Disconnected))
714 // .with_child(609 .tooltip(|cx| Tooltip::text("Disconnected", cx))
715 // MouseEventHandler::new::<ToggleUserMenu, _>(0, cx, |state, _| {610 .into_any_element(),
716 // let style = user_menu_button_style611 ),
717 // .user_menu612 client::Status::UpgradeRequired => {
718 // .inactive_state()613 let auto_updater = auto_update::AutoUpdater::get(cx);
719 // .style_for(state);614 let label = match auto_updater.map(|auto_update| auto_update.read(cx).status()) {
720 615 Some(AutoUpdateStatus::Updated) => "Please restart Zed to Collaborate",
721 // let mut dropdown = Flex::row().align_children_center();616 Some(AutoUpdateStatus::Installing)
722 617 | Some(AutoUpdateStatus::Downloading)
723 // if let Some(avatar_img) = avatar {618 | Some(AutoUpdateStatus::Checking) => "Updating...",
724 // dropdown = dropdown.with_child(Self::render_face(619 Some(AutoUpdateStatus::Idle) | Some(AutoUpdateStatus::Errored) | None => {
725 // avatar_img,620 "Please update Zed to Collaborate"
726 // *avatar_style,621 }
727 // Color::transparent_black(),622 };
728 // None,623
729 // ));624 Some(
730 // };625 div()
731 626 .bg(gpui::red()) // todo!() @nate
732 // dropdown627 .child(Button::new("connection-status", label).on_click(|_, cx| {
733 // .with_child(628 if let Some(auto_updater) = auto_update::AutoUpdater::get(cx) {
734 // Svg::new("icons/caret_down.svg")629 if auto_updater.read(cx).status() == AutoUpdateStatus::Updated {
735 // .with_color(user_menu_button_style.icon.color)630 workspace::restart(&Default::default(), cx);
736 // .constrained()631 return;
737 // .with_width(user_menu_button_style.icon.width)632 }
738 // .contained()633 }
739 // .into_any(),634 auto_update::check(&Default::default(), cx);
740 // )635 }))
741 // .aligned()636 .into_any_element(),
742 // .constrained()637 )
743 // .with_height(style.width)638 }
744 // .contained()639 _ => None,
745 // .with_style(style.container)640 }
746 // .into_any()641 }
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 // }
790 642
791 // fn render_connection_status(643 pub fn render_sign_in_button(&mut self, _: &mut ViewContext<Self>) -> Button {
792 // &self,644 let client = self.client.clone();
793 // status: &client::Status,645 Button::new("sign_in", "Sign in").on_click(move |_, cx| {
794 // cx: &mut ViewContext<Self>,646 let client = client.clone();
795 // ) -> Option<AnyElement<Self>> {647 cx.spawn(move |mut cx| async move {
796 // enum ConnectionStatusButton {}648 client
797 649 .authenticate_and_connect(true, &cx)
798 // let theme = &theme::current(cx).clone();650 .await
799 // match status {651 .notify_async_err(&mut cx);
800 // client::Status::ConnectionError652 })
801 // | client::Status::ConnectionLost653 .detach();
802 // | client::Status::Reauthenticating { .. }654 })
803 // | client::Status::Reconnecting { .. }655 }
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 // };
825 656
826 // Some(657 pub fn render_user_menu_button(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
827 // MouseEventHandler::new::<ConnectionStatusButton, _>(0, cx, |_, _| {658 if let Some(user) = self.user_store.read(cx).current_user() {
828 // Label::new(label, theme.titlebar.outdated_warning.text.clone())659 popover_menu("user-menu")
829 // .contained()660 .menu(|cx| {
830 // .with_style(theme.titlebar.outdated_warning.container)661 ContextMenu::build(cx, |menu, _| {
831 // .aligned()662 menu.action("Settings", zed_actions::OpenSettings.boxed_clone())
832 // })663 .action("Theme", theme_selector::Toggle.boxed_clone())
833 // .with_cursor_style(CursorStyle::PointingHand)664 .separator()
834 // .on_click(MouseButton::Left, |_, _, cx| {665 .action("Share Feedback", feedback::GiveFeedback.boxed_clone())
835 // if let Some(auto_updater) = auto_update::AutoUpdater::get(cx) {666 .action("Sign Out", client::SignOut.boxed_clone())
836 // if auto_updater.read(cx).status() == AutoUpdateStatus::Updated {667 })
837 // workspace::restart(&Default::default(), cx);668 })
838 // return;669 .trigger(
839 // }670 ButtonLike::new("user-menu")
840 // }671 .child(
841 // auto_update::check(&Default::default(), cx);672 h_stack()
842 // })673 .gap_0p5()
843 // .into_any(),674 .child(Avatar::new(user.avatar_uri.clone()))
844 // )675 .child(IconElement::new(Icon::ChevronDown).color(Color::Muted)),
845 // }676 )
846 // _ => None,677 .style(ButtonStyle::Subtle)
847 // }678 .tooltip(move |cx| Tooltip::text("Toggle User Menu", cx)),
848 // }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 }
849}703}
crates/ui2/src/components/icon.rs+2−0
@@ -50,6 +50,7 @@ pub enum Icon { · 49 unmodified lines
50 CopilotError,50 CopilotError,
51 CopilotDisabled,51 CopilotDisabled,
52 Dash,52 Dash,
53 Disconnected,
53 Envelope,54 Envelope,
54 ExternalLink,55 ExternalLink,
55 ExclamationTriangle,56 ExclamationTriangle,
@@ -129,6 +130,7 @@ impl Icon { · 73 unmodified lines
129 Icon::CopilotError => "icons/copilot_error.svg",130 Icon::CopilotError => "icons/copilot_error.svg",
130 Icon::CopilotDisabled => "icons/copilot_disabled.svg",131 Icon::CopilotDisabled => "icons/copilot_disabled.svg",
131 Icon::Dash => "icons/dash.svg",132 Icon::Dash => "icons/dash.svg",
133 Icon::Disconnected => "icons/disconnected.svg",
132 Icon::Envelope => "icons/feedback.svg",134 Icon::Envelope => "icons/feedback.svg",
133 Icon::ExclamationTriangle => "icons/warning.svg",135 Icon::ExclamationTriangle => "icons/warning.svg",
134 Icon::ExternalLink => "icons/external_link.svg",136 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