Ran cargo fix and cargo fmt

This commit is contained in:
Werner Kroneman 2023-12-10 13:21:59 +01:00
parent aeb3f0aee8
commit f308f030aa
6 changed files with 33 additions and 41 deletions

View File

@ -20,14 +20,9 @@ mod types;
mod widgets; mod widgets;
mod xmpp_interface; mod xmpp_interface;
use crate::dioxus_elements::div;
use dioxus::html::button;
use dioxus::prelude::*; use dioxus::prelude::*;
use dioxus_desktop::Config; use dioxus_desktop::Config;
use futures_util::stream::StreamExt;
use jid::BareJid;
use std::future::Future;
use std::str::FromStr;
use widgets::App; use widgets::App;
const STYLESHEET: &str = r#" const STYLESHEET: &str = r#"

View File

@ -14,15 +14,11 @@
// You should have received a copy of the GNU Affero General Public License // 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/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::types::LoginCredentials;
use dioxus::core::{Element, Scope}; use dioxus::core::{Element, Scope};
use dioxus::hooks::use_state; use dioxus::hooks::use_state;
use dioxus::prelude::*; use dioxus::prelude::*;
use dioxus_elements::div;
use jid::BareJid;
use std::fmt::Debug; use std::fmt::Debug;
use std::str::FromStr;
use dioxus::html::style;
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub enum LoginStatus { pub enum LoginStatus {
@ -58,7 +54,6 @@ pub struct LoginScreenProps<'a> {
} }
pub fn LoginScreen<'a>(cx: Scope<'a, LoginScreenProps>) -> Element<'a> { pub fn LoginScreen<'a>(cx: Scope<'a, LoginScreenProps>) -> Element<'a> {
let username = use_state(cx, || cx.props.cached_username.clone()); let username = use_state(cx, || cx.props.cached_username.clone());
let default_nick = use_state(cx, || cx.props.cached_nick.clone()); let default_nick = use_state(cx, || cx.props.cached_nick.clone());
let password = use_state(cx, || "".to_string()); let password = use_state(cx, || "".to_string());

View File

@ -17,26 +17,25 @@
use crate::types::{LoginCredentials, Message}; use crate::types::{LoginCredentials, Message};
use crate::widgets::login_screen::LoginAttempt; use crate::widgets::login_screen::LoginAttempt;
use crate::widgets::login_screen::{LoginScreen, LoginStatus}; use crate::widgets::login_screen::{LoginScreen, LoginStatus};
use crate::widgets::room_join_widget::{RoomJoinProps, RoomJoinWidget}; use crate::widgets::room_join_widget::RoomJoinWidget;
use crate::widgets::room_list::{RoomList, RoomListProps}; use crate::widgets::room_list::RoomList;
use crate::widgets::room_view::RoomView; use crate::widgets::room_view::RoomView;
use crate::xmpp_interface::xmpp_mainloop; use crate::xmpp_interface::xmpp_mainloop;
use crate::xmpp_interface::NetworkCommand; use crate::xmpp_interface::NetworkCommand;
use dioxus::core::{Element, Scope}; use dioxus::core::{Element, Scope};
use dioxus::core_macro::Props;
use dioxus::prelude::*; use dioxus::prelude::*;
use futures_util::StreamExt; use futures_util::StreamExt;
use jid::BareJid; use jid::BareJid;
use log::{error, info}; use log::{error, info};
use std::collections::HashMap; use std::collections::HashMap;
use std::fmt::format;
use std::rc::Rc;
use std::str::FromStr; use std::str::FromStr;
use xmpp::{Agent, ClientBuilder, ClientType};
use std::string::String; use std::string::String;
use std::sync::Mutex; use xmpp::{Agent, ClientBuilder, ClientType};
use keyring::Entry; use keyring::Entry;
use serde_derive::{Serialize, Deserialize}; use serde_derive::{Deserialize, Serialize};
mod login_screen; mod login_screen;
mod room_join_widget; mod room_join_widget;
@ -69,7 +68,6 @@ pub async fn run_xmpp_toplevel(
mut messages: UseRef<HashMap<BareJid, Vec<Message>>>, mut messages: UseRef<HashMap<BareJid, Vec<Message>>>,
mut commands: UnboundedReceiver<NetworkCommand>, mut commands: UnboundedReceiver<NetworkCommand>,
) { ) {
// Await a login attempt: // Await a login attempt:
let cmd = commands.next().await; let cmd = commands.next().await;
@ -129,13 +127,13 @@ struct Configuration {
} }
pub fn App(cx: Scope) -> Element { pub fn App(cx: Scope) -> Element {
let messages = use_ref(cx, || HashMap::new()); let messages = use_ref(cx, || HashMap::new());
let current_room = use_state(cx, || None::<BareJid>); let current_room = use_state(cx, || None::<BareJid>);
let connection_status = use_state(cx, || LoginStatus::LoggedOut); let connection_status = use_state(cx, || LoginStatus::LoggedOut);
let coroutine = use_coroutine(cx, |rx: UnboundedReceiver<NetworkCommand>| let coroutine = use_coroutine(cx, |rx: UnboundedReceiver<NetworkCommand>| {
run_xmpp_toplevel(connection_status.to_owned(), messages.to_owned(), rx)); run_xmpp_toplevel(connection_status.to_owned(), messages.to_owned(), rx)
});
let config = use_ref(cx, || match confy::load("dergchat", None) { let config = use_ref(cx, || match confy::load("dergchat", None) {
Ok(x) => x, Ok(x) => x,
@ -147,25 +145,29 @@ pub fn App(cx: Scope) -> Element {
{ {
let config = config.to_owned(); let config = config.to_owned();
let connection_status = connection_status.to_owned(); let _connection_status = connection_status.to_owned();
let coroutine = coroutine.to_owned(); let coroutine = coroutine.to_owned();
use_on_create(cx, move || { use_on_create(cx, move || {
async move { async move {
let entry = Entry::new("dergchat", &config.read().stored_username).expect("Failed to create keyring entry."); let entry = Entry::new("dergchat", &config.read().stored_username)
.expect("Failed to create keyring entry.");
let password = match entry.get_password() { let _password = match entry.get_password() {
Ok(x) => { Ok(_x) => {
info!("Password retrieved from keyring; will try to log in."); info!("Password retrieved from keyring; will try to log in.");
let (username, default_nick) = config.with(|c| (c.stored_username.clone(), c.stored_default_nick.clone())); let (username, default_nick) = config
.with(|c| (c.stored_username.clone(), c.stored_default_nick.clone()));
// If we have a username, nickname and password, immediately try to log in. // If we have a username, nickname and password, immediately try to log in.
if username.len() > 0 && default_nick.len() > 0 { if username.len() > 0 && default_nick.len() > 0 {
let credentials = LoginCredentials { let credentials = LoginCredentials {
username: BareJid::from_str(&username).expect("Invalid JID"), username: BareJid::from_str(&username).expect("Invalid JID"),
default_nick: default_nick, default_nick: default_nick,
password: entry.get_password().expect("Failed to get password from keyring"), password: entry
.get_password()
.expect("Failed to get password from keyring"),
}; };
coroutine.send(NetworkCommand::TryLogin { credentials }); coroutine.send(NetworkCommand::TryLogin { credentials });

View File

@ -39,7 +39,7 @@ pub fn RoomList<'a>(cx: Scope<'a, RoomListProps>) -> Element<'a> {
display: "flex", display: "flex",
flex_direction: "row", flex_direction: "row",
onclick: |evt| cx.props.on_room_picked.call(room.to_owned()), onclick: |_evt| cx.props.on_room_picked.call(room.to_owned()),
div { div {
flex_grow: 1, flex_grow: 1,

View File

@ -30,7 +30,7 @@ pub struct RoomViewProps<'a> {
} }
pub fn RoomView<'a>(cx: Scope<'a, RoomViewProps>) -> Element<'a> { pub fn RoomView<'a>(cx: Scope<'a, RoomViewProps>) -> Element<'a> {
let message = use_state(cx, || "".to_owned()); let _message = use_state(cx, || "".to_owned());
render! { render! {
div { div {

View File

@ -18,13 +18,13 @@ use crate::types::{LoginCredentials, Message};
use dioxus::hooks::{UnboundedReceiver, UseRef}; use dioxus::hooks::{UnboundedReceiver, UseRef};
use futures_util::stream::StreamExt; use futures_util::stream::StreamExt;
use jid::BareJid; use jid::BareJid;
use log::{error, info}; use log::info;
use std::collections::HashMap; use std::collections::HashMap;
use std::future::Future; use std::future::Future;
use std::str::FromStr;
use tokio::select; use tokio::select;
use xmpp::parsers::message::MessageType; use xmpp::parsers::message::MessageType;
use xmpp::{Agent, ClientBuilder, ClientType}; use xmpp::Agent;
async fn handle_event( async fn handle_event(
event: xmpp::Event, event: xmpp::Event,
@ -32,7 +32,7 @@ async fn handle_event(
messages: &mut UseRef<HashMap<BareJid, Vec<Message>>>, messages: &mut UseRef<HashMap<BareJid, Vec<Message>>>,
) { ) {
match event { match event {
xmpp::Event::JoinRoom(jid, conference) => { xmpp::Event::JoinRoom(jid, _conference) => {
println!("Will auto-join room: {}", &jid); println!("Will auto-join room: {}", &jid);
agent.join_room(jid, None, None, "en/us", "online").await; agent.join_room(jid, None, None, "en/us", "online").await;
} }
@ -48,7 +48,7 @@ async fn handle_event(
m.remove(&room_jid); m.remove(&room_jid);
}); });
} }
xmpp::Event::ChatMessage(id, sender, body) => { xmpp::Event::ChatMessage(_id, sender, body) => {
println!("Message from {}: {}", &sender, &body.0); println!("Message from {}: {}", &sender, &body.0);
messages.with_mut(move |m| { messages.with_mut(move |m| {
m.entry(sender.clone()).or_insert(vec![]).push(Message { m.entry(sender.clone()).or_insert(vec![]).push(Message {
@ -57,7 +57,7 @@ async fn handle_event(
}); });
}); });
} }
xmpp::Event::RoomMessage(id, room_jid, sender_nick, body) => { xmpp::Event::RoomMessage(_id, room_jid, sender_nick, body) => {
println!( println!(
"Message in {} from {}: {}", "Message in {} from {}: {}",
&room_jid, &sender_nick, &body.0 &room_jid, &sender_nick, &body.0
@ -69,7 +69,7 @@ async fn handle_event(
}) })
}); });
} }
xmpp::Event::RoomPrivateMessage(id, room_jid, sender_nick, body) => { xmpp::Event::RoomPrivateMessage(_id, room_jid, sender_nick, body) => {
println!( println!(
"Private message in {} from {}: {}", "Private message in {} from {}: {}",
&room_jid, &sender_nick, &body.0 &room_jid, &sender_nick, &body.0
@ -128,7 +128,7 @@ pub fn xmpp_mainloop<'a>(
NetworkCommand::SendMessage { recipient, message } => { NetworkCommand::SendMessage { recipient, message } => {
agent.send_message(recipient.into(), MessageType::Groupchat, "en-us", &message).await; agent.send_message(recipient.into(), MessageType::Groupchat, "en-us", &message).await;
}, },
NetworkCommand::TryLogin { credentials } => { NetworkCommand::TryLogin { credentials: _ } => {
panic!("Already logged in."); panic!("Already logged in.");
}, },
} }