2023-05-04 16:04:06 +00:00
|
|
|
use dioxus::prelude::*;
|
2024-01-31 01:59:57 +00:00
|
|
|
use dioxus_desktop::DesktopContext;
|
2023-05-04 16:04:06 +00:00
|
|
|
|
2024-02-24 01:38:04 +00:00
|
|
|
#[path = "./utils.rs"]
|
|
|
|
mod utils;
|
2023-05-04 16:04:06 +00:00
|
|
|
|
2024-02-24 01:38:04 +00:00
|
|
|
fn main() {
|
2024-04-25 17:36:43 +00:00
|
|
|
#[cfg(not(windows))]
|
2024-02-24 01:38:04 +00:00
|
|
|
utils::check_app_exits(check_html_renders);
|
2023-05-04 16:04:06 +00:00
|
|
|
}
|
|
|
|
|
2024-01-19 00:27:43 +00:00
|
|
|
fn use_inner_html(id: &'static str) -> Option<String> {
|
|
|
|
let mut value = use_signal(|| None as Option<String>);
|
|
|
|
|
|
|
|
use_effect(move || {
|
|
|
|
spawn(async move {
|
2024-03-06 06:38:38 +00:00
|
|
|
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
2024-01-19 00:27:43 +00:00
|
|
|
|
2024-01-31 01:33:14 +00:00
|
|
|
let res = eval(&format!(
|
2024-01-19 00:27:43 +00:00
|
|
|
r#"let element = document.getElementById('{}');
|
2024-04-26 15:55:48 +00:00
|
|
|
return element.innerHTML"#,
|
2024-01-19 00:27:43 +00:00
|
|
|
id
|
|
|
|
))
|
2024-01-31 01:33:14 +00:00
|
|
|
.await
|
|
|
|
.unwrap();
|
2024-01-19 00:27:43 +00:00
|
|
|
|
2024-01-31 01:33:14 +00:00
|
|
|
if let Some(html) = res.as_str() {
|
2024-01-19 00:27:43 +00:00
|
|
|
println!("html: {}", html);
|
2024-01-31 01:33:14 +00:00
|
|
|
value.set(Some(html.to_string()));
|
2024-01-19 00:27:43 +00:00
|
|
|
}
|
|
|
|
});
|
2023-05-04 16:04:06 +00:00
|
|
|
});
|
2024-01-19 00:27:43 +00:00
|
|
|
|
2024-03-08 16:54:02 +00:00
|
|
|
value()
|
2023-05-04 16:04:06 +00:00
|
|
|
}
|
|
|
|
|
2024-01-31 01:33:14 +00:00
|
|
|
const EXPECTED_HTML: &str = r#"<div style="width: 100px; height: 100px; color: rgb(0, 0, 0);" id="5"><input type="checkbox"><h1>text</h1><div><p>hello world</p></div></div>"#;
|
2023-05-04 16:04:06 +00:00
|
|
|
|
2024-01-14 04:51:37 +00:00
|
|
|
fn check_html_renders() -> Element {
|
|
|
|
let inner_html = use_inner_html("main_div");
|
2023-07-21 22:36:25 +00:00
|
|
|
|
2024-01-19 00:27:43 +00:00
|
|
|
let desktop_context: DesktopContext = consume_context();
|
2023-05-04 16:04:06 +00:00
|
|
|
|
2023-07-21 22:36:25 +00:00
|
|
|
if let Some(raw_html) = inner_html {
|
|
|
|
println!("{}", raw_html);
|
2024-01-18 12:07:28 +00:00
|
|
|
let fragment = &raw_html;
|
|
|
|
let expected = EXPECTED_HTML;
|
|
|
|
assert_eq!(raw_html, EXPECTED_HTML);
|
2023-05-04 16:04:06 +00:00
|
|
|
if fragment == expected {
|
|
|
|
println!("html matches");
|
|
|
|
desktop_context.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let dyn_value = 0;
|
2024-04-17 22:08:38 +00:00
|
|
|
let dyn_element = rsx! { div { dangerous_inner_html: "<p>hello world</p>" } };
|
2023-05-04 16:04:06 +00:00
|
|
|
|
2024-01-16 19:18:46 +00:00
|
|
|
rsx! {
|
2024-04-17 22:08:38 +00:00
|
|
|
div { id: "main_div",
|
2023-05-04 16:04:06 +00:00
|
|
|
div {
|
|
|
|
width: "100px",
|
|
|
|
height: "100px",
|
|
|
|
color: "rgb({dyn_value}, {dyn_value}, {dyn_value})",
|
|
|
|
id: 5,
|
2024-04-17 22:08:38 +00:00
|
|
|
input { "type": "checkbox" }
|
|
|
|
h1 { "text" }
|
2024-01-11 03:33:34 +00:00
|
|
|
{dyn_element}
|
2023-05-04 16:04:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|