2022-03-19 02:11:30 +00:00
|
|
|
use dioxus::prelude::*;
|
2022-12-08 16:44:56 +00:00
|
|
|
use dioxus_desktop::EvalResult;
|
2022-03-19 02:11:30 +00:00
|
|
|
|
|
|
|
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 {
|
2022-12-07 21:11:40 +00:00
|
|
|
let script = use_state(cx, String::new);
|
|
|
|
let eval = dioxus_desktop::use_eval(cx);
|
2022-12-08 17:25:15 +00:00
|
|
|
let future: &UseRef<Option<EvalResult>> = use_ref(cx, || None);
|
2022-12-08 16:44:56 +00:00
|
|
|
if future.read().is_some() {
|
|
|
|
let future_clone = future.clone();
|
|
|
|
cx.spawn(async move {
|
|
|
|
if let Some(fut) = future_clone.with_mut(|o| o.take()) {
|
|
|
|
println!("{:?}", fut.await)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2022-03-19 02:11:30 +00:00
|
|
|
|
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
|
|
|
input {
|
|
|
|
placeholder: "Enter an expression",
|
|
|
|
value: "{script}",
|
|
|
|
oninput: move |e| script.set(e.value.clone()),
|
|
|
|
}
|
|
|
|
button {
|
2022-12-08 16:44:56 +00:00
|
|
|
onclick: move |_| {
|
|
|
|
let fut = eval(script);
|
|
|
|
future.set(Some(fut));
|
|
|
|
},
|
2022-03-19 02:11:30 +00:00
|
|
|
"Execute"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|