update and format

This commit is contained in:
Miraty 2025-03-06 13:56:00 +01:00
parent 2f078168b4
commit b60ec3c2ad
4 changed files with 1691 additions and 23 deletions

1
.gitignore vendored
View file

@ -1,2 +1 @@
/target
/Cargo.lock

1650
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,16 +1,30 @@
[package]
name = "ashbat"
version = "0.0.0"
edition = "2021"
edition = "2024"
[lints.rust]
unsafe_code = "forbid"
[lints.clippy]
std_instead_of_core = "warn"
str_to_string = "warn"
string_to_string = "warn"
uninlined_format_args = "warn"
semicolon_if_nothing_returned = "warn"
wildcard_imports = "warn"
inefficient_to_string = "warn"
[dependencies]
gtk = { version = "0.6", package = "gtk4"}
html_parser = "0.6"
hyper-rustls = "0.23"
gtk = { version = "0.9.6", package = "gtk4"}
html_parser = "0.7.0"
hyper-rustls = "0.27.1"
hyper = { version = "0.14" }
hyper = { version = "1.3.1" }
tokio = { version = "1.0", features = ["io-std", "macros", "net", "rt-multi-thread"] }
glib = "0.17.3"
glib = "0.20.9"
hyper-util = "0.1.3"
http-body-util = "0.1.1"
[profile.release]
opt-level = "z"

View file

@ -1,13 +1,13 @@
use glib::clone;
use gtk::prelude::*;
use core::str::FromStr;
use gtk::{
Align, Application, ApplicationWindow, Box, Button, Entry, Expander, Label, LinkButton,
Orientation, PasswordEntry, PolicyType, ScrolledWindow, TextView,
Orientation, PasswordEntry, PolicyType, ScrolledWindow, TextView, prelude::*,
};
use html_parser::{Dom, Node};
use hyper::{body::to_bytes, client, Body, Uri};
use http_body_util::{BodyExt, Empty};
use hyper::{Uri, body::Bytes};
use hyper_util::{client::legacy::Client, rt::TokioExecutor};
use std::io;
use std::str::FromStr;
const APP_ID: &str = "org.antopie.AshBat";
@ -23,7 +23,9 @@ fn build_ui(app: &Application) {
let password_entry = PasswordEntry::new();
password_entry.set_show_peek_icon(true);
let text = Label::new(Some("<span size=\"x-large\">text</span> gjero jgier iogrejgoi jriogjiog iorgjoiergoi eroi gjoiergjioregj erjgierojg oierjg ierjiog jreoi gjoierg jiergoirejgoierjoig jreio gjorieg jioerg<a title=\"https://antopie.org/\" href=\"https://antopie.org/\">is</a> <i>cool</i>!"));
let text = Label::new(Some(
"<span size=\"x-large\">text</span> gjero jgier iogrejgoi jriogjiog iorgjoiergoi eroi gjoiergjioregj erjgierojg oierjg ierjiog jreoi gjoierg jiergoirejgoierjoig jreio gjorieg jioerg<a title=\"https://antopie.org/\" href=\"https://antopie.org/\">is</a> <i>cool</i>!",
));
text.set_wrap(true);
text.set_use_markup(true);
@ -32,7 +34,7 @@ fn build_ui(app: &Application) {
let link_button = LinkButton::new("matrix:r/antopie-synapse:matrix.antopie.org");
link_button.connect_activate_link(|link_button| {
println!("Status: {}", link_button.uri());
return gtk::Inhibit(true);
glib::Propagation::Stop
});
let text_view = TextView::new();
@ -97,31 +99,34 @@ fn error(err: String) -> io::Error {
#[tokio::main]
async fn open(address: String) -> String {
let url = Uri::from_str(&address)
.map_err(|e| error(format!("{}", e)))
.map_err(|e| error(format!("{e}")))
.unwrap();
let https = hyper_rustls::HttpsConnectorBuilder::new()
.with_native_roots()
.unwrap()
.https_only()
.enable_http1()
.build();
let client: client::Client<_, hyper::Body> = client::Client::builder().build(https);
let client: Client<_, Empty<Bytes>> = Client::builder(TokioExecutor::new()).build(https);
let fut = async move {
let res = client
.get(url)
.await
.map_err(|e| error(format!("Could not get: {:?}", e)))
.map_err(|e| error(format!("Could not get: {e:?}")))
.unwrap();
println!("Status:\n{}", res.status());
println!("Headers:\n{:#?}", res.headers());
let body: Body = res.into_body();
let body = to_bytes(body)
let body = res
.into_body()
.collect()
.await
.map_err(|e| error(format!("Could not get body: {:?}", e)))
.unwrap();
.map_err(|e| error(format!("Could not get body: {e:?}")))
.unwrap()
.to_bytes();
println!("Body:\n{}", String::from_utf8_lossy(&body));
String::from_utf8_lossy(&body).to_string()
@ -136,8 +141,8 @@ fn parse(html: String) -> String {
Ok(dom) => dom,
Err(_) => panic!("Aaaaaahhhhhh !!!"),
};
let tree = dom_valid.children.get(0).unwrap();
println!("{:#?}", tree);
let tree = dom_valid.children.first().unwrap();
println!("{tree:#?}");
let mut paragraph_string = String::from("");
for i in tree.into_iter() {
match i {