lib.rs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. use dioxus_core::prelude::*;
  2. use web_view::WebViewBuilder;
  3. pub fn new<T>(root: FC<T>) -> WebviewRenderer<T> {
  4. WebviewRenderer::new(root)
  5. }
  6. /// The `WebviewRenderer` provides a way of rendering a Dioxus Virtual DOM through a bridge to a Webview instance.
  7. /// Components used in WebviewRenderer instances can directly use system libraries, access the filesystem, and multithread with ease.
  8. pub struct WebviewRenderer<T> {
  9. /// The root component used to render the Webview
  10. root: FC<T>,
  11. }
  12. impl<T> WebviewRenderer<T> {
  13. /// Create a new text-renderer instance from a functional component root.
  14. /// Automatically progresses the creation of the VNode tree to completion.
  15. ///
  16. /// A VDom is automatically created. If you want more granular control of the VDom, use `from_vdom`
  17. pub fn new(root: FC<T>) -> Self {
  18. Self { root }
  19. }
  20. /// Create a new text renderer from an existing Virtual DOM.
  21. /// This will progress the existing VDom's events to completion.
  22. pub fn from_vdom() -> Self {
  23. todo!()
  24. }
  25. /// Pass new args to the root function
  26. pub fn update(&mut self, new_val: T) {
  27. todo!()
  28. }
  29. /// Modify the root function in place, forcing a re-render regardless if the props changed
  30. pub fn update_mut(&mut self, modifier: impl Fn(&mut T)) {
  31. todo!()
  32. }
  33. pub fn launch(self, props: T) {
  34. todo!()
  35. // let mut ctx = Context { props: &props };
  36. // let WebviewRenderer { root } = self;
  37. // let content = root(&mut ctx);
  38. // let html_content = content.to_string();
  39. // /*
  40. // TODO: @Jon
  41. // Launch the webview with a premade VDom app
  42. // */
  43. // web_view::builder()
  44. // .title("My Project")
  45. // .content(web_view::Content::Html(html_content))
  46. // .size(320, 480)
  47. // .resizable(true)
  48. // .debug(true)
  49. // .user_data(())
  50. // .invoke_handler(|_webview, _arg| Ok(()))
  51. // .run()
  52. // .unwrap();
  53. }
  54. }
  55. // mod receiver {
  56. // use dioxus_core::prelude::*;
  57. // /// The receiver app is a container that builds a connection to the host process that shuttles events and patches.
  58. // pub(crate) static ReceiverApp: FC<()> = |ctx| {
  59. // //
  60. // html! {
  61. // <div>
  62. // {}
  63. // </div>
  64. // }
  65. // };
  66. // }