mirror of
https://gitea.mizah.xyz/mizah/dergchat
synced 2024-11-21 13:35:01 -05:00
Ran cargo fix and fmt.
This commit is contained in:
parent
5a33bf2280
commit
74e2cfd6b7
@ -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,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.
|
||||
|
@ -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;
|
||||
|
@ -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.");
|
||||
}
|
@ -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 {
|
||||
|
@ -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);
|
||||
@ -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! {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user