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 xmpp_interface;
use crate::dioxus_elements::div;
use dioxus::html::button;
use dioxus::prelude::*;
use dioxus_desktop::Config;
use futures_util::stream::StreamExt;
use jid::BareJid;
use std::future::Future;
use std::str::FromStr;
use widgets::App;
const STYLESHEET: &str = r#"

View File

@ -14,15 +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::types::LoginCredentials;
use dioxus::core::{Element, Scope};
use dioxus::hooks::use_state;
use dioxus::prelude::*;
use dioxus_elements::div;
use jid::BareJid;
use std::fmt::Debug;
use std::str::FromStr;
use dioxus::html::style;
#[derive(Debug, Clone, PartialEq)]
pub enum LoginStatus {
@ -58,7 +54,6 @@ pub struct LoginScreenProps<'a> {
}
pub fn LoginScreen<'a>(cx: Scope<'a, LoginScreenProps>) -> Element<'a> {
let username = use_state(cx, || cx.props.cached_username.clone());
let default_nick = use_state(cx, || cx.props.cached_nick.clone());
let password = use_state(cx, || "".to_string());

View File

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

View File

@ -39,7 +39,7 @@ pub fn RoomList<'a>(cx: Scope<'a, RoomListProps>) -> Element<'a> {
display: "flex",
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 {
flex_grow: 1,

View File

@ -30,7 +30,7 @@ pub struct RoomViewProps<'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! {
div {

View File

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