[fractal] Make all requests async
- From: Alexandre Franke <afranke src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] Make all requests async
- Date: Tue, 1 Dec 2020 20:22:01 +0000 (UTC)
commit a7e19bc585f63a70e06d536ba9cdad846f2d134f
Author: Alejandro DomÃnguez <adomu net-c com>
Date: Wed Sep 30 21:38:06 2020 +0200
Make all requests async
Cargo.lock | 51 ---------------
fractal-gtk/Cargo.toml | 2 +-
.../identity/association/msisdn/submit_token.rs | 4 +-
fractal-gtk/src/api/r0/account/deactivate.rs | 4 +-
fractal-gtk/src/api/r0/account/login.rs | 4 +-
fractal-gtk/src/api/r0/account/logout.rs | 4 +-
fractal-gtk/src/api/r0/contact/create.rs | 4 +-
fractal-gtk/src/api/r0/contact/delete.rs | 4 +-
fractal-gtk/src/api/r0/server/domain_info.rs | 4 +-
fractal-gtk/src/appop/account.rs | 32 ++++++----
fractal-gtk/src/appop/login.rs | 23 ++++---
fractal-gtk/src/backend/mod.rs | 4 +-
fractal-gtk/src/backend/register.rs | 19 ++++--
fractal-gtk/src/backend/user.rs | 21 +++---
fractal-gtk/src/client.rs | 74 ----------------------
fractal-gtk/src/main.rs | 2 +-
fractal-gtk/src/widgets/address.rs | 28 ++++----
fractal-gtk/src/widgets/login.rs | 58 +++++++++--------
18 files changed, 120 insertions(+), 222 deletions(-)
---
diff --git a/Cargo.lock b/Cargo.lock
index 0190dbad..0f942936 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,11 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
-[[package]]
-name = "adler"
-version = "0.2.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e"
-
[[package]]
name = "aes"
version = "0.4.0"
@@ -145,19 +139,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4af5687fe33aec5e70ef14caac5e0d363e335e5e5d6385fb75978d0c241b1d67"
-[[package]]
-name = "async-compression"
-version = "0.3.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fb1ff21a63d3262af46b9f33a826a8d134e2d0d9b2179c86034948b732ea8b2a"
-dependencies = [
- "bytes 0.5.6",
- "flate2",
- "futures-core",
- "memchr",
- "pin-project-lite 0.1.11",
-]
-
[[package]]
name = "async-native-tls"
version = "0.3.3"
@@ -577,15 +558,6 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634"
-[[package]]
-name = "crc32fast"
-version = "1.2.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a"
-dependencies = [
- "cfg-if 1.0.0",
-]
-
[[package]]
name = "crossbeam-queue"
version = "0.2.3"
@@ -770,18 +742,6 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
-[[package]]
-name = "flate2"
-version = "1.0.19"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7411863d55df97a419aa64cb4d2f167103ea9d767e2c54a1868b7ac3f6b47129"
-dependencies = [
- "cfg-if 1.0.0",
- "crc32fast",
- "libc",
- "miniz_oxide",
-]
-
[[package]]
name = "fnv"
version = "1.0.7"
@@ -2110,16 +2070,6 @@ dependencies = [
"unicase",
]
-[[package]]
-name = "miniz_oxide"
-version = "0.4.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0f2d26ec3309788e423cfbf68ad1800f061638098d76a83681af979dc4eda19d"
-dependencies = [
- "adler",
- "autocfg 1.0.1",
-]
-
[[package]]
name = "mio"
version = "0.6.22"
@@ -2859,7 +2809,6 @@ version = "0.10.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb15d6255c792356a0f578d8a645c677904dc02e862bebe2ecc18e0c01b9a0ce"
dependencies = [
- "async-compression",
"base64",
"bytes 0.5.6",
"encoding_rs",
diff --git a/fractal-gtk/Cargo.toml b/fractal-gtk/Cargo.toml
index a8a4aa47..2e20b849 100644
--- a/fractal-gtk/Cargo.toml
+++ b/fractal-gtk/Cargo.toml
@@ -81,7 +81,7 @@ features = ["rt-threaded", "time"]
[dependencies.reqwest]
version = "0.10.3"
-features = ["blocking", "json", "gzip", "socks"]
+features = ["json", "socks"]
[dependencies.url]
version = "2.1.1"
diff --git a/fractal-gtk/src/api/identity/association/msisdn/submit_token.rs
b/fractal-gtk/src/api/identity/association/msisdn/submit_token.rs
index 80e9b2cc..1b89d662 100644
--- a/fractal-gtk/src/api/identity/association/msisdn/submit_token.rs
+++ b/fractal-gtk/src/api/identity/association/msisdn/submit_token.rs
@@ -1,6 +1,6 @@
-use reqwest::blocking::Client;
-use reqwest::blocking::Request;
+use reqwest::Client;
use reqwest::Error;
+use reqwest::Request;
use serde::{Deserialize, Serialize};
use url::Url;
diff --git a/fractal-gtk/src/api/r0/account/deactivate.rs b/fractal-gtk/src/api/r0/account/deactivate.rs
index 7d378b55..dc7486df 100644
--- a/fractal-gtk/src/api/r0/account/deactivate.rs
+++ b/fractal-gtk/src/api/r0/account/deactivate.rs
@@ -1,8 +1,8 @@
use super::AuthenticationData;
use crate::api::r0::AccessToken;
-use reqwest::blocking::Client;
-use reqwest::blocking::Request;
+use reqwest::Client;
use reqwest::Error;
+use reqwest::Request;
use serde::Serialize;
use url::Url;
diff --git a/fractal-gtk/src/api/r0/account/login.rs b/fractal-gtk/src/api/r0/account/login.rs
index 1a0db1fb..3795581c 100644
--- a/fractal-gtk/src/api/r0/account/login.rs
+++ b/fractal-gtk/src/api/r0/account/login.rs
@@ -2,9 +2,9 @@ use super::Identifier;
use crate::api::r0::AccessToken;
use matrix_sdk::identifiers::DeviceId;
use matrix_sdk::identifiers::UserId;
-use reqwest::blocking::Client;
-use reqwest::blocking::Request;
+use reqwest::Client;
use reqwest::Error;
+use reqwest::Request;
use serde::{Deserialize, Serialize};
use url::Url;
diff --git a/fractal-gtk/src/api/r0/account/logout.rs b/fractal-gtk/src/api/r0/account/logout.rs
index 7598aaf0..4b13bd62 100644
--- a/fractal-gtk/src/api/r0/account/logout.rs
+++ b/fractal-gtk/src/api/r0/account/logout.rs
@@ -1,7 +1,7 @@
use crate::api::r0::AccessToken;
-use reqwest::blocking::Client;
-use reqwest::blocking::Request;
+use reqwest::Client;
use reqwest::Error;
+use reqwest::Request;
use serde::Serialize;
use url::Url;
diff --git a/fractal-gtk/src/api/r0/contact/create.rs b/fractal-gtk/src/api/r0/contact/create.rs
index 32d9ba01..79ded7ae 100644
--- a/fractal-gtk/src/api/r0/contact/create.rs
+++ b/fractal-gtk/src/api/r0/contact/create.rs
@@ -1,8 +1,8 @@
use crate::api::r0::AccessToken;
use crate::api::r0::ThreePIDCredentials;
-use reqwest::blocking::Client;
-use reqwest::blocking::Request;
+use reqwest::Client;
use reqwest::Error;
+use reqwest::Request;
use serde::Serialize;
use std::ops::Not;
use url::Url;
diff --git a/fractal-gtk/src/api/r0/contact/delete.rs b/fractal-gtk/src/api/r0/contact/delete.rs
index 014834a7..968d775f 100644
--- a/fractal-gtk/src/api/r0/contact/delete.rs
+++ b/fractal-gtk/src/api/r0/contact/delete.rs
@@ -1,8 +1,8 @@
use crate::api::r0::AccessToken;
use crate::api::r0::Medium;
-use reqwest::blocking::Client;
-use reqwest::blocking::Request;
+use reqwest::Client;
use reqwest::Error;
+use reqwest::Request;
use serde::Serialize;
use url::Url;
diff --git a/fractal-gtk/src/api/r0/server/domain_info.rs b/fractal-gtk/src/api/r0/server/domain_info.rs
index ccde3d0a..155d8d43 100644
--- a/fractal-gtk/src/api/r0/server/domain_info.rs
+++ b/fractal-gtk/src/api/r0/server/domain_info.rs
@@ -1,6 +1,6 @@
-use reqwest::blocking::Client;
-use reqwest::blocking::Request;
+use reqwest::Client;
use reqwest::Error;
+use reqwest::Request;
use serde::Deserialize;
use url::Url;
diff --git a/fractal-gtk/src/appop/account.rs b/fractal-gtk/src/appop/account.rs
index 9624eba5..917f5afb 100644
--- a/fractal-gtk/src/appop/account.rs
+++ b/fractal-gtk/src/appop/account.rs
@@ -2,7 +2,6 @@ use crate::backend::user;
use gtk::prelude::*;
use log::info;
use std::path::PathBuf;
-use std::thread;
use crate::app::{App, RUNTIME};
use crate::appop::AppOp;
@@ -48,14 +47,17 @@ impl AppOp {
let login_data = unwrap_or_unit_return!(self.login_data.clone());
if let Some(sid) = sid {
if let Some(secret) = secret {
- thread::spawn(move || {
- match user::add_threepid(
+ RUNTIME.spawn(async move {
+ let query = user::add_threepid(
login_data.session_client.homeserver().clone(),
login_data.access_token,
login_data.identity_url,
secret,
sid,
- ) {
+ )
+ .await;
+
+ match query {
Ok(_) => {
APPOP!(added_three_pid);
}
@@ -119,8 +121,8 @@ impl AppOp {
let server_url = login_data.session_client.homeserver().clone();
let secret = secret.clone();
let sid = sid.clone();
- thread::spawn(move || {
- match user::submit_phone_token(server_url, secret, sid, token) {
+ RUNTIME.spawn(async move {
+ match user::submit_phone_token(server_url, secret, sid, token).await {
Ok((sid, secret)) => {
let secret = Some(secret);
APPOP!(valid_phone_token, (sid, secret));
@@ -161,14 +163,17 @@ impl AppOp {
let login_data = login_data.clone();
let secret = secret.clone();
let sid = sid.clone();
- thread::spawn(move || {
- match user::add_threepid(
+ RUNTIME.spawn(async move {
+ let query = user::add_threepid(
login_data.session_client.homeserver().clone(),
login_data.access_token,
login_data.identity_url,
secret,
sid,
- ) {
+ )
+ .await;
+
+ match query {
Ok(_) => {
APPOP!(added_three_pid);
}
@@ -788,13 +793,16 @@ impl AppOp {
if let gtk::ResponseType::Ok = r {
let password = password.clone();
let login_data = login_data.clone();
- thread::spawn(move || {
- match user::account_destruction(
+ RUNTIME.spawn(async move {
+ let query = user::account_destruction(
login_data.session_client.homeserver().clone(),
login_data.access_token.clone(),
login_data.uid.localpart().into(),
password,
- ) {
+ )
+ .await;
+
+ match query {
Ok(_) => {
APPOP!(account_destruction_logoff);
}
diff --git a/fractal-gtk/src/appop/login.rs b/fractal-gtk/src/appop/login.rs
index 4bf69354..cce49b4f 100644
--- a/fractal-gtk/src/appop/login.rs
+++ b/fractal-gtk/src/appop/login.rs
@@ -14,8 +14,6 @@ use crate::backend::HandleError;
use crate::cache;
use crate::client::get_matrix_client;
-use std::thread;
-
use crate::passwd::PasswordStorage;
use crate::actions::AppState;
@@ -90,29 +88,30 @@ impl AppOp {
error!("Can't store the password using libsecret");
});
- thread::spawn(
- move || match register::login(username, password, server.clone()) {
+ RUNTIME.spawn(async move {
+ match register::login(username, password, server.clone()).await {
Ok((uid, tk, dev)) => {
APPOP!(bk_login, (uid, tk, dev, server, identity));
}
Err(err) => {
err.handle_error();
}
- },
- );
+ }
+ });
}
// TODO: Remove function
pub fn disconnect(&self) {}
pub fn logout(&mut self) {
- let login_data = unwrap_or_unit_return!(self.login_data.clone());
+ let (homeserver, access_token) =
+ unwrap_or_unit_return!(self.login_data.as_ref().map(|ld| (
+ ld.session_client.homeserver().clone(),
+ ld.access_token.clone()
+ )));
let _ = self.delete_pass("fractal");
- thread::spawn(move || {
- match register::logout(
- login_data.session_client.homeserver().clone(),
- login_data.access_token,
- ) {
+ RUNTIME.spawn(async move {
+ match register::logout(homeserver, access_token).await {
Ok(_) => {
APPOP!(bk_logout);
}
diff --git a/fractal-gtk/src/backend/mod.rs b/fractal-gtk/src/backend/mod.rs
index 1d3b75b4..a13bf3ab 100644
--- a/fractal-gtk/src/backend/mod.rs
+++ b/fractal-gtk/src/backend/mod.rs
@@ -13,7 +13,7 @@ use std::io::Error as IoError;
use std::path::PathBuf;
use url::Url;
-use crate::client::ClientBlocking;
+use crate::client::Client;
use crate::util::cache_dir_path;
use matrix_sdk::api::r0::context::get_context::Request as GetContextRequest;
use matrix_sdk::api::r0::media::get_content::Request as GetContentRequest;
@@ -29,7 +29,7 @@ pub mod sync;
pub mod user;
lazy_static! {
- pub static ref HTTP_CLIENT: ClientBlocking = ClientBlocking::new();
+ pub static ref HTTP_CLIENT: Client = Client::new();
}
pub enum ContentType {
diff --git a/fractal-gtk/src/backend/register.rs b/fractal-gtk/src/backend/register.rs
index f80c7646..650a6338 100644
--- a/fractal-gtk/src/backend/register.rs
+++ b/fractal-gtk/src/backend/register.rs
@@ -42,7 +42,7 @@ impl HandleError for LoginError {
}
}
-pub fn login(
+pub async fn login(
user: String,
password: String,
server: Url,
@@ -67,7 +67,12 @@ pub fn login(
};
let request = login_req(server, &body)?;
- let response: LoginResponse = HTTP_CLIENT.get_client().execute(request)?.json()?;
+ let response: LoginResponse = HTTP_CLIENT
+ .get_client()
+ .execute(request)
+ .await?
+ .json()
+ .await?;
if let (Some(tk), Some(uid)) = (response.access_token, response.user_id) {
Ok((uid, tk, response.device_id))
@@ -87,11 +92,11 @@ impl From<ReqwestError> for LogoutError {
impl HandleError for LogoutError {}
-pub fn logout(server: Url, access_token: AccessToken) -> Result<(), LogoutError> {
+pub async fn logout(server: Url, access_token: AccessToken) -> Result<(), LogoutError> {
let params = LogoutParameters { access_token };
let request = logout_req(server, ¶ms)?;
- HTTP_CLIENT.get_client().execute(request)?;
+ HTTP_CLIENT.get_client().execute(request).await?;
Ok(())
}
@@ -114,12 +119,14 @@ impl From<UrlError> for GetWellKnownError {
}
}
-pub fn get_well_known(domain: Url) -> Result<DomainInfoResponse, GetWellKnownError> {
+pub async fn get_well_known(domain: Url) -> Result<DomainInfoResponse, GetWellKnownError> {
let request = domain_info(domain)?;
HTTP_CLIENT
.get_client()
- .execute(request)?
+ .execute(request)
+ .await?
.json()
+ .await
.map_err(Into::into)
}
diff --git a/fractal-gtk/src/backend/user.rs b/fractal-gtk/src/backend/user.rs
index 04948a5c..33bab1aa 100644
--- a/fractal-gtk/src/backend/user.rs
+++ b/fractal-gtk/src/backend/user.rs
@@ -231,7 +231,7 @@ impl From<ReqwestError> for AddedToFavError {
impl HandleError for AddedToFavError {}
-pub fn add_threepid(
+pub async fn add_threepid(
base: Url,
access_token: AccessToken,
identity: Url,
@@ -251,7 +251,7 @@ pub fn add_threepid(
};
let request = create_contact(base, ¶ms, &body)?;
- HTTP_CLIENT.get_client().execute(request)?;
+ HTTP_CLIENT.get_client().execute(request).await?;
Ok(())
}
@@ -267,7 +267,7 @@ impl From<ReqwestError> for SubmitPhoneTokenError {
impl HandleError for SubmitPhoneTokenError {}
-pub fn submit_phone_token(
+pub async fn submit_phone_token(
base: Url,
client_secret: String,
sid: String,
@@ -280,7 +280,12 @@ pub fn submit_phone_token(
};
let request = submit_phone_token_req(base, &body)?;
- let response: SubmitPhoneTokenResponse = HTTP_CLIENT.get_client().execute(request)?.json()?;
+ let response: SubmitPhoneTokenResponse = HTTP_CLIENT
+ .get_client()
+ .execute(request)
+ .await?
+ .json()
+ .await?;
Ok((Some(sid).filter(|_| response.success), client_secret))
}
@@ -296,7 +301,7 @@ impl From<ReqwestError> for DeleteThreePIDError {
impl HandleError for DeleteThreePIDError {}
-pub fn delete_three_pid(
+pub async fn delete_three_pid(
base: Url,
access_token: AccessToken,
medium: Medium,
@@ -306,7 +311,7 @@ pub fn delete_three_pid(
let body = DeleteThreePIDBody { address, medium };
let request = delete_contact(base, ¶ms, &body)?;
- HTTP_CLIENT.get_client().execute(request)?;
+ HTTP_CLIENT.get_client().execute(request).await?;
Ok(())
}
@@ -385,7 +390,7 @@ impl HandleError for AccountDestructionError {
}
}
-pub fn account_destruction(
+pub async fn account_destruction(
base: Url,
access_token: AccessToken,
user: String,
@@ -401,7 +406,7 @@ pub fn account_destruction(
};
let request = deactivate(base, ¶ms, &body)?;
- HTTP_CLIENT.get_client().execute(request)?;
+ HTTP_CLIENT.get_client().execute(request).await?;
Ok(())
}
diff --git a/fractal-gtk/src/client.rs b/fractal-gtk/src/client.rs
index f67c5a75..c918172e 100644
--- a/fractal-gtk/src/client.rs
+++ b/fractal-gtk/src/client.rs
@@ -47,31 +47,6 @@ impl ProxySettings {
))
}
- pub fn apply_to_blocking_client_builder(
- &self,
- mut builder: reqwest::blocking::ClientBuilder,
- ) -> reqwest::blocking::ClientBuilder {
- // Reqwest only supports one proxy for each type
- if let Some(http_proxy) = self
- .http_proxy
- .get(0)
- .map(reqwest::Proxy::http)
- .and_then(Result::ok)
- {
- builder = builder.proxy(http_proxy);
- }
- if let Some(https_proxy) = self
- .https_proxy
- .get(0)
- .map(reqwest::Proxy::https)
- .and_then(Result::ok)
- {
- builder = builder.proxy(https_proxy);
- }
-
- builder
- }
-
pub fn apply_to_client_builder(
&self,
mut builder: matrix_sdk::reqwest::ClientBuilder,
@@ -145,7 +120,6 @@ impl Client {
fn build(builder: matrix_sdk::reqwest::ClientBuilder) -> matrix_sdk::reqwest::Client {
builder
- .gzip(true)
.timeout(globals::TIMEOUT)
.build()
.expect("Couldn't create a http client")
@@ -170,51 +144,3 @@ where
let config = MatrixClientConfig::new().client(client);
MatrixClient::new_with_config(homeserver_url, config)
}
-
-#[derive(Debug)]
-struct ClientInnerBlocking {
- client: reqwest::blocking::Client,
- proxy_settings: ProxySettings,
-}
-
-#[derive(Debug)]
-pub struct ClientBlocking {
- inner: Mutex<ClientInnerBlocking>,
-}
-
-impl ClientBlocking {
- pub fn new() -> Self {
- Self {
- inner: Mutex::new(ClientInnerBlocking {
- client: Self::build(reqwest::blocking::Client::builder()),
- proxy_settings: Default::default(),
- }),
- }
- }
-
- pub fn get_client(&self) -> reqwest::blocking::Client {
- // Lock first so we don't overwrite proxy settings with outdated information
- let mut inner = self.inner.lock().unwrap();
-
- let new_proxy_settings = ProxySettings::current().unwrap_or_default();
-
- if inner.proxy_settings != new_proxy_settings {
- let mut builder = reqwest::blocking::Client::builder();
- builder = new_proxy_settings.apply_to_blocking_client_builder(builder);
- let client = Self::build(builder);
-
- inner.client = client;
- inner.proxy_settings = new_proxy_settings;
- }
-
- inner.client.clone()
- }
-
- fn build(builder: reqwest::blocking::ClientBuilder) -> reqwest::blocking::Client {
- builder
- .gzip(true)
- .timeout(globals::TIMEOUT)
- .build()
- .expect("Couldn't create a http client")
- }
-}
diff --git a/fractal-gtk/src/main.rs b/fractal-gtk/src/main.rs
index 5159ad63..d7e8feb1 100644
--- a/fractal-gtk/src/main.rs
+++ b/fractal-gtk/src/main.rs
@@ -1,4 +1,4 @@
-#![deny(dead_code, unused_imports, unused_variables)]
+#![deny(dead_code, unused_imports, unused_must_use, unused_variables)]
#[macro_use]
extern crate glib;
diff --git a/fractal-gtk/src/widgets/address.rs b/fractal-gtk/src/widgets/address.rs
index 0c1f7dd4..8dace7cc 100644
--- a/fractal-gtk/src/widgets/address.rs
+++ b/fractal-gtk/src/widgets/address.rs
@@ -6,7 +6,6 @@ use gtk::prelude::*;
use matrix_sdk::Client as MatrixClient;
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
-use std::thread;
use url::Url;
use crate::app::{App, RUNTIME};
@@ -182,12 +181,12 @@ impl<'a> Address<'a> {
match action {
Some(AddressAction::Delete) => {
if let Some(address) = address.clone() {
- delete_address(
+ RUNTIME.handle().block_on(delete_address(
medium,
address,
session_client.homeserver().clone(),
access_token.clone(),
- );
+ ));
}
}
Some(AddressAction::Add) => {
@@ -200,17 +199,20 @@ impl<'a> Address<'a> {
}
}
-fn delete_address(medium: Medium, address: String, server_url: Url, access_token: AccessToken) {
- thread::spawn(move || {
- match user::delete_three_pid(server_url, access_token, medium, address) {
- Ok(_) => {
- APPOP!(get_three_pid);
- }
- Err(err) => {
- err.handle_error();
- }
+async fn delete_address(
+ medium: Medium,
+ address: String,
+ server_url: Url,
+ access_token: AccessToken,
+) {
+ match user::delete_three_pid(server_url, access_token, medium, address).await {
+ Ok(_) => {
+ APPOP!(get_three_pid);
}
- });
+ Err(err) => {
+ err.handle_error();
+ }
+ }
}
fn add_address(session_client: MatrixClient, medium: Medium, address: String) {
diff --git a/fractal-gtk/src/widgets/login.rs b/fractal-gtk/src/widgets/login.rs
index 382eaf12..7292d708 100644
--- a/fractal-gtk/src/widgets/login.rs
+++ b/fractal-gtk/src/widgets/login.rs
@@ -8,6 +8,7 @@ use url::Url;
use crate::actions;
use crate::actions::global::AppState;
use crate::actions::login::LoginState;
+use crate::app::RUNTIME;
use crate::appop::AppOp;
use crate::globals;
use crate::util::i18n::i18n;
@@ -89,34 +90,35 @@ impl LoginWidget {
let txt = if !txt.ends_with('/') { txt + "/" } else { txt };
if !password.is_empty() && !username.is_empty() {
- // take the user's homeserver value if the
- // well-known request fails
- let homeserver_url = if let Ok(hs_url) = Url::parse(&txt) {
- hs_url
- } else {
- let msg = i18n("Malformed server URL");
- ErrorDialog::new(false, &msg);
- return;
- };
-
- let (homeserver_url, idserver) = get_well_known(homeserver_url.clone())
- .and_then(|response| {
- let hs_url = Url::parse(&response.homeserver.base_url)?;
- let ids = response
- .identity_server
- .as_ref()
- .map(|ids| Url::parse(&ids.base_url))
- .transpose()?
- .unwrap_or_else(|| globals::DEFAULT_IDENTITYSERVER.clone());
- info!("Got well-known response from {}: {:#?}", &txt, response);
-
- Ok((hs_url, ids))
- })
- .map_err(|e| {
- info!("Failed to .well-known request: {:#?}", e);
- e
- })
- .unwrap_or((homeserver_url, globals::DEFAULT_IDENTITYSERVER.clone()));
+ // take the user's homeserver value if the
+ // well-known request fails
+ let homeserver_url = if let Ok(hs_url) = Url::parse(&txt) {
+ hs_url
+ } else {
+ let msg = i18n("Malformed server URL");
+ ErrorDialog::new(false, &msg);
+ return;
+ };
+
+ let query = get_well_known(homeserver_url.clone());
+ let (homeserver_url, idserver) = RUNTIME.handle().block_on(query)
+ .and_then(|response| {
+ let hs_url = Url::parse(&response.homeserver.base_url)?;
+ let ids = response
+ .identity_server
+ .as_ref()
+ .map(|ids| Url::parse(&ids.base_url))
+ .transpose()?
+ .unwrap_or(globals::DEFAULT_IDENTITYSERVER.clone());
+ info!("Got well-known response from {}: {:#?}", &txt, response);
+
+ Ok((hs_url, ids))
+ })
+ .map_err(|e| {
+ info!("Failed to .well-known request: {:#?}", e);
+ e
+ })
+ .unwrap_or((homeserver_url, globals::DEFAULT_IDENTITYSERVER.clone()));
err_label.hide();
op.lock().unwrap().set_state(AppState::Loading);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]