diff --git a/src/configuration.rs b/src/configuration.rs
index 8e4368d..1565d2e 100644
--- a/src/configuration.rs
+++ b/src/configuration.rs
@@ -14,13 +14,11 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
-use crate::widgets::login_screen::LoginAttempt;
-use dioxus::prelude::*;
+use crate::passwords::Password;
use jid::BareJid;
use keyring::Entry;
use log::error;
use serde_derive::{Deserialize, Serialize};
-use crate::passwords::Password;
/// The configuration struct containing all the configuration options.
#[derive(Default, Debug, Serialize, Deserialize)]
@@ -38,25 +36,26 @@ pub struct Configuration {
/// # Arguments
/// * `attempt` - The login attempt to store.
/// * `config` - The current app configuration; UseState should prevent race conditions in writing.
-pub fn store_login_details(jid: BareJid,
- default_nick: String,
- password: &Password,
- c: &mut Configuration) {
-
+pub fn store_login_details(
+ jid: BareJid,
+ default_nick: String,
+ password: &Password,
+ c: &mut Configuration,
+) {
// Open the config state and store the username and default nick.
- // Open the keyring and store the password.
- let entry = Entry::new("dergchat", &jid.to_string()).expect("Failed to create keyring entry.");
- entry
- .set_password(&password.0)
- .expect("Failed to set password in keyring.");
+ // Open the keyring and store the password.
+ let entry = Entry::new("dergchat", &jid.to_string()).expect("Failed to create keyring entry.");
+ entry
+ .set_password(&password.0)
+ .expect("Failed to set password in keyring.");
- // Store the username and default nick in the config.
- c.stored_username = Some(jid);
- c.stored_default_nick = Some(default_nick);
+ // Store the username and default nick in the config.
+ c.stored_username = Some(jid);
+ c.stored_default_nick = Some(default_nick);
- if let Err(e) = confy::store("dergchat", None, c) {
- error!("Failed to store the config file: {}", e);
- }
+ if let Err(e) = confy::store("dergchat", None, c) {
+ error!("Failed to store the config file: {}", e);
+ }
}
/// Load the configuration from the config file.
diff --git a/src/main.rs b/src/main.rs
index bd0e17e..211c1b0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -17,10 +17,10 @@
#![allow(non_snake_case)]
mod configuration;
+mod passwords;
mod types;
mod widgets;
mod xmpp_interface;
-mod passwords;
use dioxus::prelude::*;
use dioxus_desktop::Config;
diff --git a/src/passwords.rs b/src/passwords.rs
index 356a2c8..918cc53 100644
--- a/src/passwords.rs
+++ b/src/passwords.rs
@@ -14,9 +14,9 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
-use std::fmt::Debug;
use jid::BareJid;
use keyring::Entry;
+use std::fmt::Debug;
pub struct Password(pub String);
@@ -30,11 +30,18 @@ impl Debug for Password {
/// Retrieve the password for the given username from the keyring, if it exists.
pub fn try_retrieve_password_from_keyring(username: &BareJid) -> Option {
- Entry::new("dergchat", &username.to_string()).expect("Failed to create keyring entry.").get_password().ok().map(|p| Password(p))
+ Entry::new("dergchat", &username.to_string())
+ .expect("Failed to create keyring entry.")
+ .get_password()
+ .ok()
+ .map(|p| Password(p))
}
/// Store the password for the given username in the keyring.
pub fn store_keyring_password(username: &BareJid, password: &Password) {
- let entry = Entry::new("dergchat", &username.to_string()).expect("Failed to create keyring entry.");
- entry.set_password(&*password.0).expect("Failed to set password in keyring.");
-}
\ No newline at end of file
+ let entry =
+ Entry::new("dergchat", &username.to_string()).expect("Failed to create keyring entry.");
+ entry
+ .set_password(&*password.0)
+ .expect("Failed to set password in keyring.");
+}
diff --git a/src/types.rs b/src/types.rs
index 83ab5f6..779686d 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -14,9 +14,9 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
+use crate::passwords::Password;
use jid::BareJid;
use std::fmt::Debug;
-use crate::passwords::Password;
#[derive(Debug, Clone, PartialEq)]
pub struct Room {
@@ -34,4 +34,4 @@ pub struct LoginCredentials {
pub username: BareJid,
pub default_nick: String,
pub password: Password,
-}
\ No newline at end of file
+}
diff --git a/src/widgets/mod.rs b/src/widgets/mod.rs
index c11cc7a..fd11da8 100644
--- a/src/widgets/mod.rs
+++ b/src/widgets/mod.rs
@@ -14,6 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
+use crate::passwords::Password;
use crate::types::LoginCredentials;
use crate::widgets::login_screen::LoginAttempt;
use crate::widgets::login_screen::{LoginScreen, LoginStatus};
@@ -22,7 +23,6 @@ use crate::widgets::room_view::RoomView;
use crate::widgets::sidebar::SideBar;
use crate::xmpp_interface::NetworkCommand;
use dioxus::core::{Element, Scope};
-use crate::passwords::Password;
use dioxus::prelude::*;
use futures_util::StreamExt;
@@ -30,13 +30,13 @@ use jid::BareJid;
use log::{error, info};
use std::collections::HashMap;
-use crate::configuration::{Configuration, load_config};
+use crate::configuration::{load_config, Configuration};
use crate::xmpp_interface;
-use keyring::Entry;
+
+use crate::configuration::store_login_details;
+use crate::passwords::try_retrieve_password_from_keyring;
use std::str::FromStr;
use std::string::String;
-use crate::passwords::try_retrieve_password_from_keyring;
-use crate::configuration::store_login_details;
pub mod login_screen;
pub mod no_room_open;
@@ -65,7 +65,6 @@ fn try_retrieve_credentials(config: &Configuration) -> Option
}
pub fn App(cx: Scope) -> Element {
-
let messages = use_ref(cx, || HashMap::new());
let current_room = use_state(cx, || None::);
let connection_status = use_state(cx, || LoginStatus::LoggedOut);
@@ -76,19 +75,22 @@ pub fn App(cx: Scope) -> Element {
let config = use_ref(cx, load_config);
- use_on_create(cx, || {
- let config = config.to_owned();
- let _connection_status = connection_status.to_owned();
- let coroutine = coroutine.to_owned();
- async move {
- if let Some(credentials) = try_retrieve_credentials(&*config.read()) {
- info!("Will try to log in as {} with default nick {}", credentials.username, credentials.default_nick);
- coroutine.send(NetworkCommand::TryLogin { credentials });
- } else {
- info!("No stored credentials found; will not try to automatically log in.");
- }
+ use_on_create(cx, || {
+ let config = config.to_owned();
+ let _connection_status = connection_status.to_owned();
+ let coroutine = coroutine.to_owned();
+ async move {
+ if let Some(credentials) = try_retrieve_credentials(&*config.read()) {
+ info!(
+ "Will try to log in as {} with default nick {}",
+ credentials.username, credentials.default_nick
+ );
+ coroutine.send(NetworkCommand::TryLogin { credentials });
+ } else {
+ info!("No stored credentials found; will not try to automatically log in.");
}
- });
+ }
+ });
render! {