Ran cargo fix and fmt.

This commit is contained in:
Werner Kroneman 2023-12-10 17:41:58 +01:00
parent 5a33bf2280
commit 74e2cfd6b7
5 changed files with 53 additions and 45 deletions

View File

@ -14,13 +14,11 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
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,11 +36,12 @@ 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,
pub fn store_login_details(
jid: BareJid,
default_nick: String,
password: &Password,
c: &mut Configuration) {
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.");

View File

@ -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;

View File

@ -14,9 +14,9 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
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<Password> {
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.");
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.");
}

View File

@ -14,9 +14,9 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::passwords::Password;
use jid::BareJid;
use std::fmt::Debug;
use crate::passwords::Password;
#[derive(Debug, Clone, PartialEq)]
pub struct Room {

View File

@ -14,6 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
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<LoginCredentials>
}
pub fn App(cx: Scope) -> Element {
let messages = use_ref(cx, || HashMap::new());
let current_room = use_state(cx, || None::<BareJid>);
let connection_status = use_state(cx, || LoginStatus::LoggedOut);
@ -82,7 +81,10 @@ pub fn App(cx: Scope) -> Element {
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);
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.");