diff --git a/Cargo.lock b/Cargo.lock index 06a41f1..455b6c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -362,7 +362,6 @@ dependencies = [ "anyhow", "chrono", "dioxus", - "dioxus-logger", "dioxus-router", "dioxus-std", "dioxus-web", @@ -385,6 +384,7 @@ dependencies = [ "url", "uuid 0.8.2", "wasm-bindgen", + "wasm-logger", "web-sys", ] @@ -814,16 +814,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "dioxus-logger" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d7cbab0b5519060fe9e14b3c21e3f2329b8386cd905618f78c7b929cd00cf54" -dependencies = [ - "log", - "web-sys", -] - [[package]] name = "dioxus-router" version = "0.4.1" @@ -3532,6 +3522,17 @@ version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +[[package]] +name = "wasm-logger" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "074649a66bb306c8f2068c9016395fa65d8e08d2affcbf95acf3c24c3ab19718" +dependencies = [ + "log", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-timer" version = "0.2.5" diff --git a/Cargo.toml b/Cargo.toml index fadb17c..d1bd015 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" [dependencies] dioxus = "0.4" dioxus-web = "0.4" -dioxus-logger = "0.4.0" dioxus-router = "0.4.0" futures-util = "0.3.27" futures = "0.3" @@ -33,3 +32,4 @@ uuid = "0.8" unic-langid = "0.9.1" reqwest = "0.11" http = "0.2" +wasm-logger = "0.2.0" diff --git a/src/hooks/use_auth.rs b/src/hooks/use_auth.rs index a1bb930..5a5a2ad 100644 --- a/src/hooks/use_auth.rs +++ b/src/hooks/use_auth.rs @@ -108,7 +108,7 @@ pub struct UseAuthState { login_cache: UseSharedState>, } -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct UseAuth { pub data: LoginInfoBuilder, pub error: Option, @@ -172,12 +172,18 @@ impl UseAuthState { username_parse = format!("@{}", username_parse); } - if let Some(server) = &self.data.read().server { - if let Some(domain) = server.domain() { - let domain_name = extract_domain_name(domain); - if !username_parse.ends_with(domain_name.as_str()) { - username_parse = format!("{}:{}", username_parse, domain_name); - } + if !username_parse.contains(':') { + let Some(server) = &self.data.read().server else { + return; + }; + + let Some(domain) = server.domain() else { + return; + }; + + let domain_name = extract_domain_name(domain); + if !username_parse.ends_with(domain_name.as_str()) { + username_parse = format!("{}:{}", username_parse, domain_name); } } } diff --git a/src/main.rs b/src/main.rs index ab8044f..704a2c5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,7 @@ use unic_langid::LanguageIdentifier; use web_sys::window; fn main() { - dioxus_logger::init(LevelFilter::Info).expect("failed to init logger"); + wasm_logger::init(wasm_logger::Config::default()); dioxus_web::launch(App); } @@ -98,19 +98,20 @@ fn App(cx: Scope) -> Element { HomeserverError::InvalidUrl => key_main_error_homeserver_invalid_url, })?; - let c = create_client(&homeserver.get_base_url()) - .await - .map_err(|_| { - format!( - "{} {}", - key_chat_common_error_default_server, - homeserver.get_base_url() - ) - })?; + let c = match create_client(&homeserver.get_base_url()).await { + Ok(c) => c, + Err(_) => create_client(&Homeserver::default().get_base_url()) + .await + .map_err(|_| { + format!( + "{} {}", + key_chat_common_error_default_server, + homeserver.get_base_url() + ) + })?, + }; - client.set(MatrixClientState { - client: Some(c.clone()), - }); + client.set(MatrixClientState { client: Some(c) }); let serialized_session: Result = ::get("session_file"); diff --git a/src/pages/login.rs b/src/pages/login.rs index 52df1e7..31de900 100644 --- a/src/pages/login.rs +++ b/src/pages/login.rs @@ -163,9 +163,10 @@ pub fn Login(cx: Scope) -> Element { is_loading_loggedin.set(LoggedInStatus::Start); return; }; + }else { + auth.set_server(homeserver.get()).await; } - auth.set_server(homeserver.get()).await; auth.set_username(username.get(), true); auth.set_password(password.get()); diff --git a/src/utils/get_homeserver.rs b/src/utils/get_homeserver.rs index 1090f60..34e22cb 100644 --- a/src/utils/get_homeserver.rs +++ b/src/utils/get_homeserver.rs @@ -8,6 +8,14 @@ pub struct Homeserver { base_url: String, } +impl Default for Homeserver { + fn default() -> Self { + Self { + base_url: "https://matrix.org".to_string(), + } + } +} + pub enum HomeserverError { InvalidUrl, }