use dioxus_core::DomEdit; use wry::{ application::{event_loop::EventLoop, window::WindowBuilder}, webview::WebView, }; pub(crate) type DynEventHandlerFn = dyn Fn(&mut EventLoop<()>, &mut WebView); pub struct DesktopConfig<'a> { pub window: WindowBuilder, pub(crate) manual_edits: Option>>, pub(crate) pre_rendered: Option, pub(crate) event_handler: Option>, } impl<'a> DesktopConfig<'a> { /// Initializes a new `WindowBuilder` with default values. #[inline] pub fn new() -> Self { let window = WindowBuilder::new().with_title("Dioxus app"); Self { event_handler: None, window, pre_rendered: None, manual_edits: None, } } pub fn with_edits(&mut self, edits: Vec>) -> &mut Self { self.manual_edits = Some(edits); self } pub fn with_prerendered(&mut self, content: String) -> &mut Self { self.pre_rendered = Some(content); self } pub fn with_window( &mut self, configure: impl FnOnce(WindowBuilder) -> WindowBuilder, ) -> &mut Self { // gots to do a swap because the window builder only takes itself as muy self // I wish more people knew about returning &mut Self let mut builder = WindowBuilder::default().with_title("Dioxus App"); std::mem::swap(&mut self.window, &mut builder); builder = configure(builder); std::mem::swap(&mut self.window, &mut builder); self } pub fn with_event_handler( &mut self, handler: impl Fn(&mut EventLoop<()>, &mut WebView) + 'static, ) -> &mut Self { self.event_handler = Some(Box::new(handler)); self } } impl<'a> Default for DesktopConfig<'a> { fn default() -> Self { Self::new() } }