Use the user from the CloudUserStore
to drive the user menu (#35375)
This PR updates the user menu in the title bar to base the "signed in" state on the user in the `CloudUserStore` rather than the `UserStore`. This makes it possible to be signed-in—at least, as far as the user menu is concerned—even when disconnected from Collab. Release Notes: - N/A
This commit is contained in:
parent
296bb66b65
commit
fbc784d323
4 changed files with 56 additions and 26 deletions
|
@ -1491,6 +1491,7 @@ impl Client {
|
|||
|
||||
pub async fn sign_out(self: &Arc<Self>, cx: &AsyncApp) {
|
||||
self.state.write().credentials = None;
|
||||
self.cloud_client.clear_credentials();
|
||||
self.disconnect(cx);
|
||||
|
||||
if self.has_credentials(cx).await {
|
||||
|
|
|
@ -7,35 +7,56 @@ use gpui::{Context, Task};
|
|||
use util::{ResultExt as _, maybe};
|
||||
|
||||
pub struct CloudUserStore {
|
||||
authenticated_user: Option<AuthenticatedUser>,
|
||||
_fetch_authenticated_user_task: Task<()>,
|
||||
authenticated_user: Option<Arc<AuthenticatedUser>>,
|
||||
_maintain_authenticated_user_task: Task<()>,
|
||||
}
|
||||
|
||||
impl CloudUserStore {
|
||||
pub fn new(cloud_client: Arc<CloudApiClient>, cx: &mut Context<Self>) -> Self {
|
||||
Self {
|
||||
authenticated_user: None,
|
||||
_fetch_authenticated_user_task: cx.spawn(async move |this, cx| {
|
||||
_maintain_authenticated_user_task: cx.spawn(async move |this, cx| {
|
||||
maybe!(async move {
|
||||
loop {
|
||||
let Some(this) = this.upgrade() else {
|
||||
return anyhow::Ok(());
|
||||
};
|
||||
|
||||
if cloud_client.has_credentials() {
|
||||
break;
|
||||
if let Some(response) = cloud_client
|
||||
.get_authenticated_user()
|
||||
.await
|
||||
.context("failed to fetch authenticated user")
|
||||
.log_err()
|
||||
{
|
||||
this.update(cx, |this, _cx| {
|
||||
this.authenticated_user = Some(Arc::new(response.user));
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
} else {
|
||||
this.update(cx, |this, _cx| {
|
||||
this.authenticated_user = None;
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
|
||||
cx.background_executor()
|
||||
.timer(Duration::from_millis(100))
|
||||
.await;
|
||||
}
|
||||
|
||||
let response = cloud_client.get_authenticated_user().await?;
|
||||
this.update(cx, |this, _cx| {
|
||||
this.authenticated_user = Some(response.user);
|
||||
})
|
||||
})
|
||||
.await
|
||||
.context("failed to fetch authenticated user")
|
||||
.log_err();
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_authenticated(&self) -> bool {
|
||||
self.authenticated_user.is_some()
|
||||
}
|
||||
|
||||
pub fn authenticated_user(&self) -> Option<Arc<AuthenticatedUser>> {
|
||||
self.authenticated_user.clone()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue