From e8bbd370e46191d1d180d73102a41e57c1d92d1e Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 10 Jan 2022 15:06:38 +0100 Subject: [PATCH] Auto-connect to server on startup if credentials are on the keychain --- crates/client/src/client.rs | 4 ++++ crates/zed/src/main.rs | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index a8356bcea0..4f32aa146e 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -356,6 +356,10 @@ impl Client { } } + pub fn has_keychain_credentials(&self, cx: &AsyncAppContext) -> bool { + read_credentials_from_keychain(cx).is_some() + } + #[async_recursion(?Send)] pub async fn authenticate_and_connect( self: &Arc, diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index a06610967e..f34c700c54 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -61,6 +61,16 @@ fn main() { chat_panel::init(cx); project_panel::init(cx); diagnostics::init(cx); + cx.spawn({ + let client = client.clone(); + |cx| async move { + if client.has_keychain_credentials(&cx) { + client.authenticate_and_connect(&cx).await?; + } + Ok::<_, anyhow::Error>(()) + } + }) + .detach_and_log_err(cx); let app_state = Arc::new(AppState { languages: languages.clone(),