Ran cargo fmt and fix.

This commit is contained in:
Werner Kroneman 2023-12-10 16:30:29 +01:00
parent f8bb6f1fbd
commit cbb307e8a2
7 changed files with 16 additions and 24 deletions

View File

@ -14,11 +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 keyring::Entry;
use log::error;
use serde_derive::{Deserialize, Serialize};
use crate::widgets::login_screen::LoginAttempt;
/// The configuration struct containing all the configuration options.
#[derive(Serialize, Deserialize, Default)]
@ -37,7 +37,6 @@ pub struct Configuration {
/// * `attempt` - The login attempt to store.
/// * `config` - The current app configuration; UseState should prevent race conditions in writing.
pub fn store_login_details(attempt: LoginAttempt, config: &mut UseRef<Configuration>) {
// Extract the fields from the login attempt.
let LoginAttempt {
username,
@ -47,10 +46,11 @@ pub fn store_login_details(attempt: LoginAttempt, config: &mut UseRef<Configurat
// Open the config state and store the username and default nick.
config.with_mut(|c| {
// Open the keyring and store the password.
let entry = Entry::new("dergchat", &username).expect("Failed to create keyring entry.");
entry.set_password(&password).expect("Failed to set password in keyring.");
entry
.set_password(&password)
.expect("Failed to set password in keyring.");
// Store the username and default nick in the config.
c.stored_username = username;
@ -73,4 +73,4 @@ pub fn load_config() -> Configuration {
Configuration::default()
}
}
}
}

View File

@ -16,10 +16,10 @@
#![allow(non_snake_case)]
mod configuration;
mod types;
mod widgets;
mod xmpp_interface;
mod configuration;
use dioxus::prelude::*;
use dioxus_desktop::Config;

View File

@ -17,8 +17,8 @@
use crate::types::LoginCredentials;
use crate::widgets::login_screen::LoginAttempt;
use crate::widgets::login_screen::{LoginScreen, LoginStatus};
use crate::widgets::room_view::RoomView;
use crate::widgets::no_room_open::NoRoomPlaceholder;
use crate::widgets::room_view::RoomView;
use crate::widgets::sidebar::SideBar;
use crate::xmpp_interface::NetworkCommand;
use dioxus::core::{Element, Scope};
@ -29,22 +29,21 @@ use jid::BareJid;
use log::{error, info};
use std::collections::HashMap;
use std::str::FromStr;
use std::string::String;
use keyring::Entry;
use crate::configuration::load_config;
use crate::xmpp_interface;
use keyring::Entry;
use std::str::FromStr;
use std::string::String;
pub mod login_screen;
mod no_room_open;
pub mod room_join_widget;
pub mod room_list;
pub mod room_view;
pub mod send_message;
pub mod sidebar;
mod no_room_open;
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);
@ -174,4 +173,4 @@ pub fn App(cx: Scope) -> Element {
}
}
}
}
}

View File

@ -33,7 +33,6 @@ pub struct RoomJoinProps<'a> {
///
/// Also validates the room name, and displays an error message if the room name is invalid.
pub fn RoomJoinWidget<'a>(cx: Scope<'a, RoomJoinProps>) -> Element<'a> {
// Store the current room name and error message in state.
let room = use_state(cx, || "".to_owned());
let error = use_state(cx, || "".to_owned());

View File

@ -26,7 +26,6 @@ pub struct SendMessageProps<'a> {
/// A simple widget that allows the user to compose a message and a button to send it.
pub fn SendMessage<'a>(cx: Scope<'a, SendMessageProps>) -> Element<'a> {
// The message body being written.
let message = use_state(cx, || "".to_owned());

View File

@ -14,12 +14,12 @@
// 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::room_join_widget::RoomJoinWidget;
use crate::widgets::room_list::RoomList;
use dioxus::core::{Element, Scope};
use dioxus::core_macro::Props;
use jid::BareJid;
use dioxus::prelude::*;
use crate::widgets::room_list::RoomList;
use crate::widgets::room_join_widget::RoomJoinWidget;
use jid::BareJid;
#[derive(Props)]
pub struct SideBarProps<'a> {

View File

@ -22,17 +22,16 @@ use log::{error, info};
use std::collections::HashMap;
use std::future::Future;
use crate::widgets::login_screen::LoginStatus;
use tokio::select;
use xmpp::parsers::message::MessageType;
use xmpp::{Agent, ClientBuilder, ClientType};
use crate::widgets::login_screen::LoginStatus;
/// An enum of commands that can be sent to the XMPP interface.
///
/// These very loosely correspond to XMPP stanzas, but are more high level.
#[derive(Debug)]
pub enum NetworkCommand {
/// Start a new login attempt, resulting in either a successful login or an error.
TryLogin { credentials: LoginCredentials },
@ -44,7 +43,6 @@ pub enum NetworkCommand {
/// Send a message to a recipient.
SendMessage { recipient: BareJid, message: String },
}
async fn handle_event(
@ -108,8 +106,6 @@ async fn handle_event(
}
}
pub fn xmpp_mainloop<'a>(
agent: &'a mut Agent,
mut room_data: &'a mut UseRef<HashMap<BareJid, Vec<Message>>>,
@ -163,7 +159,6 @@ pub fn xmpp_mainloop<'a>(
///
/// The future resolves to Ok(()) if the agent went online, or Err(String) if the agent disconnected.
async fn await_online(agent: &mut Agent) -> Result<(), String> {
// Wait for the next batch of events.
let events = agent
.wait_for_events()