10 Commits

Author SHA1 Message Date
4261e24cd2 ♻️ Clean Cargo.toml file and add target specific dependencies 2024-04-06 12:18:48 +02:00
9cfc0841df 💄 Fix some rendering inconsistencies 2024-04-06 12:16:18 +02:00
39ff4122c9 🐛 Svg generated using dicebear shall use unique ids 2024-04-06 12:13:10 +02:00
46ce890718 ♻️ Make random_svg_generators able to get placeholder according to the target 2024-04-06 12:07:29 +02:00
82b15a5509 💄 Manage config per target and remove menu bar from the desktop one 2024-04-06 12:02:43 +02:00
912b67ed23 🐛 Remove unused tokio::time import 2024-04-06 11:55:32 +02:00
0ec1187fc3 ♻️ Replace tracing dependency with dioxus-logger
tracing package doesn't support web platform when dioxus-logger `will eventually support every target that Dioxus
does. Currently only web and desktop platforms are supported.`
2024-04-06 11:51:46 +02:00
f78765e553 ⬆️ Bump dioxus-sdk version (0.5.0)
The dioxus-std has been renamed to dioxus-sdk
2024-04-06 11:37:43 +02:00
b26cb1d982 Use async-std to sleep asynchronously (previously done with tokio) 2024-04-05 17:23:48 +02:00
fc9411376c Remove dioxus-desktop dependency 2024-04-05 17:14:37 +02:00
17 changed files with 118 additions and 66 deletions

View File

@@ -3,13 +3,16 @@ name = "beau-gosse-du-92"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features]
default = []
desktop = ["dioxus/desktop"]
web = ["dioxus/web"]
[dependencies] [dependencies]
dioxus = "0.5.0" dioxus = "0.5.0"
dioxus-desktop = "0.5.0"
dioxus-free-icons = { version = "0.8", features = ["material-design-icons-navigation", "ionicons"] } dioxus-free-icons = { version = "0.8", features = ["material-design-icons-navigation", "ionicons"] }
dioxus-std = { git = "https://github.com/DioxusLabs/dioxus-std.git", branch = "master", features = ["utils"] } dioxus-sdk = { version = "0.5.0", features = ["utils"] }
dioxus-logger = { version = "0.4.1", features = ["timestamps"] }
matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk.git", branch = "main", default-features = false, features = ["js", "rustls-tls"] } matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk.git", branch = "main", default-features = false, features = ["js", "rustls-tls"] }
@@ -17,12 +20,10 @@ anyhow = "1.0.75"
url = "2.5.0" url = "2.5.0"
dirs = "5.0.1" dirs = "5.0.1"
ctrlc-async = "3.2.2" ctrlc-async = "3.2.2"
tracing-subscriber = "0.3.18"
thiserror = "1.0.50" thiserror = "1.0.50"
turf = "0.7.0" turf = "0.7.0"
tokio = "1.34.0" tokio = "1.34.0"
log = "0.4.20" log = "0.4.20"
tracing = "0.1.40"
futures-util = "0.3.29" futures-util = "0.3.29"
futures = "0.3.29" futures = "0.3.29"
rand = "0.8.5" rand = "0.8.5"
@@ -30,17 +31,13 @@ reqwest = "0.11.24"
validator = { version = "0.17.0", features = ["derive"] } validator = { version = "0.17.0", features = ["derive"] }
const_format = "0.2.32" const_format = "0.2.32"
zxcvbn = "2.2.2" zxcvbn = "2.2.2"
async-std = "1.12.0"
[build] [target.'cfg(target_family = "wasm")'.dependencies]
target = "x86_64-unknown-linux-gnu" web-sys = { version = "0.3.69" }
[build-dependencies] [build-dependencies]
regex = "1.10.3" regex = "1.10.3"
[package.metadata.turf.class_names] [package.metadata.turf.class_names]
template = "<original_name>--<id>" template = "<original_name>--<id>"
[features]
default = []
desktop = ["dioxus/desktop"]
web = ["dioxus/web"]

View File

@@ -15,7 +15,7 @@ use matrix_sdk::{
ruma::{OwnedRoomId, OwnedUserId}, ruma::{OwnedRoomId, OwnedUserId},
}; };
use tokio::select; use tokio::select;
use tracing::{debug, error, warn}; use log::{debug, error, warn};
use crate::ui::components::chats_window::interface::Interface as ChatsWinInterface; use crate::ui::components::chats_window::interface::Interface as ChatsWinInterface;

View File

@@ -1,11 +1,11 @@
use std::cell::RefCell; use std::cell::RefCell;
use std::sync::Arc; use std::sync::Arc;
use log::{debug, error};
use tokio::sync::broadcast; use tokio::sync::broadcast;
use tokio::sync::broadcast::Sender; use tokio::sync::broadcast::Sender;
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver}; use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver};
use tokio::task::JoinHandle; use tokio::task::JoinHandle;
use tracing::{debug, error};
use matrix_sdk::{ use matrix_sdk::{
config::SyncSettings, config::SyncSettings,

View File

@@ -1,12 +1,17 @@
use std::collections::HashMap;
use std::fmt; use std::fmt;
use std::io::Result as IoResult; use std::future::Future;
use std::sync::OnceLock; use std::sync::OnceLock;
use std::{collections::HashMap, future::IntoFuture};
use log::error;
use rand::distributions::{Alphanumeric, DistString}; use rand::distributions::{Alphanumeric, DistString};
use reqwest::Result as RequestResult; use reqwest::Result as RequestResult;
#[cfg(feature = "desktop")]
use tokio::fs::read_to_string; use tokio::fs::read_to_string;
use tracing::error;
#[cfg(feature = "web")]
use web_sys;
#[derive(Eq, PartialEq, Hash)] #[derive(Eq, PartialEq, Hash)]
pub enum AvatarFeeling { pub enum AvatarFeeling {
@@ -59,9 +64,9 @@ struct DicebearConfig<'a> {
lips: Vec<u32>, lips: Vec<u32>,
} }
fn dicebear_variants() -> &'static HashMap<AvatarFeeling, DicebearConfig<'static>> { fn avatar_variants() -> &'static HashMap<AvatarFeeling, DicebearConfig<'static>> {
static HASHMAP: OnceLock<HashMap<AvatarFeeling, DicebearConfig>> = OnceLock::new(); static VARIANTS: OnceLock<HashMap<AvatarFeeling, DicebearConfig>> = OnceLock::new();
HASHMAP.get_or_init(|| { VARIANTS.get_or_init(|| {
let mut variants = HashMap::new(); let mut variants = HashMap::new();
variants.insert( variants.insert(
AvatarFeeling::Alerting, AvatarFeeling::Alerting,
@@ -103,17 +108,16 @@ fn render_dicebear_variants(values: &[u32]) -> String {
} }
async fn fetch_text(req: String) -> RequestResult<String> { async fn fetch_text(req: String) -> RequestResult<String> {
reqwest::get(req).await?.text().await match reqwest::get(req).await?.error_for_status() {
} Ok(res) => res.text().await,
Err(err) => Err(err),
async fn read_file(path: &str) -> IoResult<String> { }
read_to_string(path).await
} }
async fn fetch_dicebear_svg( async fn fetch_dicebear_svg(
r#type: &DicebearType, r#type: &DicebearType,
req_fields: &Vec<String>, req_fields: &Vec<String>,
placeholder_path: Option<&str>, placeholder_fetcher: Option<Box<impl Future<Output = Option<String>>>>,
) -> String { ) -> String {
// TODO: Use configuration file // TODO: Use configuration file
let url = "dicebear.tools.adrien.run"; let url = "dicebear.tools.adrien.run";
@@ -121,7 +125,7 @@ async fn fetch_dicebear_svg(
let seed = Alphanumeric.sample_string(&mut rand::thread_rng(), 16); let seed = Alphanumeric.sample_string(&mut rand::thread_rng(), 16);
let type_str = r#type.to_string(); let type_str = r#type.to_string();
let url = format!( let url = format!(
"https://{url}/7.x/{type_str}/svg?seed={seed}{}{}", "https://{url}/8.x/{type_str}/svg?seed={seed}&randomizeIds=true{}{}",
if !req_fields.is_empty() { "&" } else { " " }, if !req_fields.is_empty() { "&" } else { " " },
req_fields.join("&") req_fields.join("&")
); );
@@ -130,29 +134,55 @@ async fn fetch_dicebear_svg(
Ok(text) => Some(text), Ok(text) => Some(text),
Err(err) => { Err(err) => {
error!("Error during placeholder loading: {}", err); error!("Error during placeholder loading: {}", err);
if let Some(placeholder_fetcher) = placeholder_fetcher {
match placeholder_path { placeholder_fetcher.into_future().await
Some(placeholder_path) => match read_file(placeholder_path).await { } else {
Ok(content) => Some(content),
Err(err) => {
error!(
"Error during to read {placeholder_path} file: {}",
err.to_string()
);
None None
} }
},
None => None,
}
} }
}; };
text.unwrap_or("".to_string()) text.unwrap_or("".to_string())
} }
#[cfg(feature = "desktop")]
fn gen_placeholder_fetcher<'a>(path: &'static str) -> Box<impl Future<Output = Option<String>>> {
let path = format!(".{}", &path);
Box::new(async move {
match read_to_string(&path).await {
Ok(content) => Some(content),
Err(err) => {
error!(
"Error during the access to the {path} file: {}",
err.to_string()
);
None
}
}
})
}
#[cfg(feature = "web")]
fn gen_placeholder_fetcher<'a>(path: &'static str) -> Box<impl Future<Output = Option<String>>> {
Box::new(async move {
let url = format!("{}{}", web_sys::window().unwrap().origin(), path);
match fetch_text(url).await {
Ok(content) => Some(content),
Err(err) => {
error!("Error during {path} fetching: {}", err.to_string());
None
}
}
})
}
#[cfg(not(any(feature = "desktop", feature = "web")))]
fn gen_placeholder_fetcher<'a>(_path: &'static str) -> Box<impl Future<Output = Option<String>>> {
Box::new(async move { None })
}
pub async fn generate_random_svg_avatar<'a>(config: Option<&'a AvatarConfig<'a>>) -> String { pub async fn generate_random_svg_avatar<'a>(config: Option<&'a AvatarConfig<'a>>) -> String {
let (variant, feeling) = match config { let (variant, feeling) = match config {
Some(config) => (dicebear_variants().get(&config.feeling), &config.feeling), Some(config) => (avatar_variants().get(&config.feeling), &config.feeling),
None => (None, &AvatarFeeling::Alerting), None => (None, &AvatarFeeling::Alerting),
}; };
@@ -182,15 +212,15 @@ pub async fn generate_random_svg_avatar<'a>(config: Option<&'a AvatarConfig<'a>>
} }
let placeholder_path = match feeling { let placeholder_path = match feeling {
AvatarFeeling::Ok => "./images/modal-default-ok-icon.svg", AvatarFeeling::Ok => "/images/modal-default-ok-icon.svg",
AvatarFeeling::Warning => "./images/modal-default-warning-icon.svg", AvatarFeeling::Warning => "/images/modal-default-warning-icon.svg",
AvatarFeeling::Alerting => "./images/modal-default-critical-icon.svg", AvatarFeeling::Alerting => "/images/modal-default-critical-icon.svg",
}; };
fetch_dicebear_svg( fetch_dicebear_svg(
&DicebearType::Notionists, &DicebearType::Notionists,
&req_fields, &req_fields,
Some(placeholder_path), Some(gen_placeholder_fetcher(placeholder_path)),
) )
.await .await
} }
@@ -227,5 +257,11 @@ pub async fn generate_random_svg_shape<'a>(config: Option<&'a ShapeConfig<'a>>)
req_fields.push(format!("shape3Color={}", config.shape_3_color)); req_fields.push(format!("shape3Color={}", config.shape_3_color));
} }
fetch_dicebear_svg(&DicebearType::Shapes, &req_fields, None).await let placeholder_path = "/images/login-profile-placeholder.svg";
fetch_dicebear_svg(
&DicebearType::Shapes,
&req_fields,
Some(gen_placeholder_fetcher(placeholder_path)),
)
.await
} }

View File

@@ -4,9 +4,14 @@ mod infrastructure;
mod ui; mod ui;
mod utils; mod utils;
use std::time::Duration;
use async_std::task;
use dioxus::prelude::*; use dioxus::prelude::*;
use tokio::time::{sleep, Duration}; use log::{debug, LevelFilter};
use tracing::{debug, Level};
#[cfg(feature = "desktop")]
use dioxus::desktop::Config;
use crate::base::{login, sync_rooms}; use crate::base::{login, sync_rooms};
use crate::base::{APP_SETTINGS, ROOMS, SESSION}; use crate::base::{APP_SETTINGS, ROOMS, SESSION};
@@ -24,8 +29,8 @@ fn app() -> Element {
// Dummy timer simulating the loading of the application // Dummy timer simulating the loading of the application
let _: Coroutine<()> = use_coroutine(|_: UnboundedReceiver<_>| async move { let _: Coroutine<()> = use_coroutine(|_: UnboundedReceiver<_>| async move {
debug!("Not ready"); debug!("Not ready");
sleep(Duration::from_secs(3)).await; task::sleep(Duration::from_secs(3)).await;
// sleep(Duration::from_secs(0)).await; // task::sleep(Duration::from_secs(0)).await;
debug!("Ready"); debug!("Ready");
ready.set(true); ready.set(true);
}); });
@@ -108,10 +113,17 @@ fn app() -> Element {
} }
fn main() { fn main() {
tracing_subscriber::fmt() dioxus_logger::init(LevelFilter::Info).expect("failed to init logger");
// .pretty()
.with_max_level(Level::DEBUG)
.init();
launch(app); #[cfg(feature = "desktop")]
{
let config = Config::new().with_menu(None);
let builder = LaunchBuilder::new().with_cfg(config);
builder.launch(app);
}
#[cfg(feature = "web")]
{
let builder = LaunchBuilder::new();
builder.launch(app);
}
} }

View File

@@ -186,6 +186,12 @@ $geist-font-path: "../fonts/Geist";
$transition-duration: 300ms; $transition-duration: 300ms;
@font-face {
src: url("#{$geist-font-path}/Geist-Medium.woff2") format("woff2");
font-family: "Geist";
font-weight: normal;
}
@font-face { @font-face {
src: url("#{$geist-font-path}/Geist-Bold.woff2") format("woff2"); src: url("#{$geist-font-path}/Geist-Bold.woff2") format("woff2");
font-family: "Geist"; font-family: "Geist";
@@ -205,6 +211,7 @@ body {
width: 100%; width: 100%;
font-family: "Geist"; font-family: "Geist";
font-weight: normal;
} }
::selection { ::selection {

View File

@@ -1,6 +1,6 @@
use dioxus::prelude::*; use dioxus::prelude::*;
use log::error;
use matrix_sdk::ruma::OwnedRoomId; use matrix_sdk::ruma::OwnedRoomId;
use tracing::error;
use super::edit_section::EditSection; use super::edit_section::EditSection;
use crate::base::{sync_messages, ROOMS}; use crate::base::{sync_messages, ROOMS};

View File

@@ -8,9 +8,9 @@ use std::cell::RefCell;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use dioxus::prelude::*; use dioxus::prelude::*;
use log::{debug, error};
use matrix_sdk::ruma::OwnedRoomId; use matrix_sdk::ruma::OwnedRoomId;
use tokio::sync::broadcast::Receiver; use tokio::sync::broadcast::Receiver;
use tracing::{debug, error};
use crate::base::{sync_rooms, Room, ROOMS}; use crate::base::{sync_rooms, Room, ROOMS};
use crate::infrastructure::messaging::matrix::requester::Receivers; use crate::infrastructure::messaging::matrix::requester::Receivers;

View File

@@ -1,5 +1,5 @@
use dioxus::prelude::*; use dioxus::prelude::*;
use tracing::debug; use log::debug;
turf::style_sheet!("src/ui/components/chats_window/navbar.scss"); turf::style_sheet!("src/ui/components/chats_window/navbar.scss");

View File

@@ -1,7 +1,7 @@
use std::rc::Rc; use std::rc::Rc;
use dioxus::prelude::*; use dioxus::prelude::*;
use tracing::debug; use log::debug;
use crate::ui::components::contacts_window::contacts_section::{ use crate::ui::components::contacts_window::contacts_section::{
filter_people_conversations, filter_room_conversations, ContactsSection, filter_people_conversations, filter_room_conversations, ContactsSection,

View File

@@ -4,8 +4,8 @@ use std::rc::Rc;
use dioxus::prelude::*; use dioxus::prelude::*;
use dioxus_free_icons::icons::io_icons::IoChevronDown; use dioxus_free_icons::icons::io_icons::IoChevronDown;
use dioxus_free_icons::Icon; use dioxus_free_icons::Icon;
use log::debug;
use matrix_sdk::{ruma::OwnedRoomId, RoomState}; use matrix_sdk::{ruma::OwnedRoomId, RoomState};
use tracing::debug;
use crate::base::{ByIdRooms, Room, CHATS_WIN_INTERFACE, ROOMS}; use crate::base::{ByIdRooms, Room, CHATS_WIN_INTERFACE, ROOMS};
use crate::ui::components::chats_window::interface::Interface as ChatsWindowInterface; use crate::ui::components::chats_window::interface::Interface as ChatsWindowInterface;

View File

@@ -3,7 +3,7 @@ mod contacts_section;
mod user_infos; mod user_infos;
use dioxus::prelude::*; use dioxus::prelude::*;
use tracing::debug; use log::debug;
use crate::ui::components::contacts_window::contacts::Contacts; use crate::ui::components::contacts_window::contacts::Contacts;
use crate::ui::components::contacts_window::user_infos::UserInfos; use crate::ui::components::contacts_window::user_infos::UserInfos;

View File

@@ -1,5 +1,5 @@
use dioxus::prelude::*; use dioxus::prelude::*;
use tracing::debug; use log::debug;
use crate::ui::components::avatar_selector::AvatarSelector; use crate::ui::components::avatar_selector::AvatarSelector;
use crate::ui::components::icons::DownArrowIcon; use crate::ui::components::icons::DownArrowIcon;

View File

@@ -1,5 +1,5 @@
use dioxus::prelude::*; use dioxus::prelude::*;
use tracing::debug; use log::debug;
use super::spinner::Spinner; use super::spinner::Spinner;
use super::wallpaper::Wallpaper; use super::wallpaper::Wallpaper;

View File

@@ -5,7 +5,7 @@ use std::rc::Rc;
use const_format::formatcp; use const_format::formatcp;
use dioxus::prelude::*; use dioxus::prelude::*;
use tracing::{debug, error, warn}; use log::{debug, error, warn};
use validator::{Validate, ValidateArgs, ValidateEmail, ValidationError, ValidationErrors}; use validator::{Validate, ValidateArgs, ValidateEmail, ValidationError, ValidationErrors};
use zxcvbn::zxcvbn; use zxcvbn::zxcvbn;

View File

@@ -1,5 +1,5 @@
use dioxus::prelude::*; use dioxus::prelude::*;
use tracing::debug; use log::debug;
use crate::base::SESSION; use crate::base::SESSION;
use crate::ui::components::contacts_window::ContactsWindow; use crate::ui::components::contacts_window::ContactsWindow;

View File

@@ -68,7 +68,7 @@ $modal-max-height: 55vh;
&__placeholder { &__placeholder {
width: calc(100% + (2 * $border-normal-width)); width: calc(100% + (2 * $border-normal-width));
height: calc(100% - (2 * $border-normal-width)); height: 100%;
} }
svg { svg {