//! An example where the dioxus vdom is running in a native thread, interacting with webview use std::{ borrow::BorrowMut, rc::Rc, sync::{mpsc::channel, Arc}, }; // use async_std::{channel, task::block_on}; use dioxus_core::{dodriodiff::DiffMachine, prelude::bumpalo::Bump, prelude::*, scope}; use scope::Scope; use web_view::Handle; static HTML_CONTENT: &'static str = include_str!("./index.html"); enum InnerEvent { Initiate(Handle<()>), } // async_std::task::spawn(async { // #[async_std::main] fn main() -> anyhow::Result<()> { let (sender, receiver) = channel::(); // let (sender, receiver) = channel::unbounded::(); // let task = async_std::task::spawn(async move { let mut view = web_view::builder() .title("My Project") .content(web_view::Content::Html(HTML_CONTENT)) .size(320, 480) .resizable(true) .debug(true) .user_data(()) .invoke_handler(|view, arg| { // todo: handle events here println!("handling invoker"); let handle = view.handle(); sender.send(InnerEvent::Initiate(handle)); Ok(()) }) .build() .unwrap(); println!("building the diff"); let bump = Bump::new(); let mut diff_machine = DiffMachine::new(&bump); let old = html! {
}(&bump); // let mut scope = Scope::new(TEST, (), None); // scope.run::<()>(); let new = html! {
// Title
"Jon's awesome site!!11"
// Subtext / description
"He worked so hard on it :)"
// Main number
"1337"
// Try another
}(&bump); diff_machine.diff_node(&old, &new); let edits = diff_machine.consume(); let ready_edits = serde_json::to_string(&edits)?; let ref_edits = Arc::new(ready_edits); loop { view.step().expect("should not fail"); // if let Some(evt) = receiver.try_recv() {} if let Ok(event) = receiver.try_recv() { match event { InnerEvent::Initiate(handle) => { // println!("awesome, things worked"); let ediits = ref_edits.clone(); // println!("{}", ediits); handle .dispatch(move |view| { view.eval(format!("EditListReceived(`{}`);", ediits).as_str())?; Ok(()) }) .expect("Dispatch failed"); // let g = handle.(); } } } // let event = receiver.try_recv(); // view.eval("alert('omg');")?; // view.step().expect("webview should not fail")?; } } // static TEST: FC<()> = |ctx, props| { // ctx.view(html! { //
//
//
//
// // Title //
// "Jon's awesome site!!11" //
// // Subtext / description //
// "He worked so hard on it :)" //
//
// // Main number //
// "1337" //
//
// // Try another // //
//
//
//
// }) // };