2022-03-19 02:11:30 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
|
|
fn main() {
|
2022-07-09 19:15:20 +00:00
|
|
|
dioxus_desktop::launch(app);
|
2022-03-19 02:11:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn app(cx: Scope) -> Element {
|
2023-07-21 22:36:25 +00:00
|
|
|
let eval_provider = use_eval(cx);
|
2022-03-19 02:11:30 +00:00
|
|
|
|
2023-07-21 22:36:25 +00:00
|
|
|
let future = use_future(cx, (), |_| {
|
|
|
|
to_owned![eval_provider];
|
|
|
|
async move {
|
|
|
|
let eval = eval_provider(
|
|
|
|
r#"
|
|
|
|
dioxus.send("Hi from JS!");
|
|
|
|
let msg = await dioxus.recv();
|
|
|
|
console.log(msg);
|
|
|
|
return "hello world";
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
eval.send("Hi from Rust!".into()).unwrap();
|
|
|
|
let res = eval.recv().await.unwrap();
|
|
|
|
println!("{:?}", eval.await);
|
|
|
|
res
|
2022-03-19 02:11:30 +00:00
|
|
|
}
|
2023-07-21 22:36:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
match future.value() {
|
|
|
|
Some(v) => cx.render(rsx!(
|
|
|
|
p { "{v}" }
|
|
|
|
)),
|
|
|
|
_ => cx.render(rsx!(
|
|
|
|
p { "hello" }
|
|
|
|
)),
|
|
|
|
}
|
2022-03-19 02:11:30 +00:00
|
|
|
}
|