remove some generics from LaunchBuilder
This commit is contained in:
1 parent
16e2c3f2f2
commit
25ad3da659
14 files changed
+142
-304
No files matched your search
@@ -10,8 +10,8 @@ use crate::{
|
||||
webview::WebviewInstance,
|
||||
};
|
||||
use crossbeam_channel::Receiver;
|
||||
use dioxus_core::AnyProps;
|
||||
use dioxus_core::{CrossPlatformConfig, ElementId};
|
||||
use dioxus_core::ElementId;
|
||||
use dioxus_core::VirtualDom;
|
||||
use dioxus_html::{
|
||||
native_bind::NativeFileEngine, FileEngine, HasFileData, HasFormData, HtmlEvent,
|
||||
PlatformEventData,
|
||||
@@ -29,10 +29,10 @@ use tao::{
|
||||
};
|
||||
|
||||
/// The single top-level object that manages all the running windows, assets, shortcuts, etc
|
||||
pub(crate) struct App<P: AnyProps> {
|
||||
pub(crate) struct App {
|
||||
// move the props into a cell so we can pop it out later to create the first window
|
||||
// iOS panics if we create a window before the event loop is started, so we toss them into a cell
|
||||
pub(crate) dioxus_config: Cell<Option<CrossPlatformConfig<P>>>,
|
||||
pub(crate) unmounted_dom: Cell<Option<VirtualDom>>,
|
||||
pub(crate) cfg: Cell<Option<Config>>,
|
||||
|
||||
// Stuff we need mutable access to
|
||||
@@ -59,11 +59,8 @@ pub struct SharedContext {
|
||||
pub(crate) target: EventLoopWindowTarget<UserWindowEvent>,
|
||||
}
|
||||
|
||||
impl<P: AnyProps> App<P> {
|
||||
pub fn new(
|
||||
cfg: Config,
|
||||
dioxus_config: CrossPlatformConfig<P>,
|
||||
) -> (EventLoop<UserWindowEvent>, Self) {
|
||||
impl App {
|
||||
pub fn new(cfg: Config, virtual_dom: VirtualDom) -> (EventLoop<UserWindowEvent>, Self) {
|
||||
let event_loop = EventLoopBuilder::<UserWindowEvent>::with_user_event().build();
|
||||
|
||||
let app = Self {
|
||||
@@ -71,7 +68,7 @@ impl<P: AnyProps> App<P> {
|
||||
is_visible_before_start: true,
|
||||
webviews: HashMap::new(),
|
||||
control_flow: ControlFlow::Wait,
|
||||
dioxus_config: Cell::new(Some(dioxus_config)),
|
||||
unmounted_dom: Cell::new(Some(virtual_dom)),
|
||||
cfg: Cell::new(Some(cfg)),
|
||||
shared: Rc::new(SharedContext {
|
||||
event_handlers: WindowEventHandlers::default(),
|
||||
@@ -166,12 +163,12 @@ impl<P: AnyProps> App<P> {
|
||||
}
|
||||
|
||||
pub fn handle_start_cause_init(&mut self) {
|
||||
let dioxus_config = self.dioxus_config.take().unwrap();
|
||||
let virtual_dom = self.unmounted_dom.take().unwrap();
|
||||
let cfg = self.cfg.take().unwrap();
|
||||
|
||||
self.is_visible_before_start = cfg.window.window.visible;
|
||||
|
||||
let webview = WebviewInstance::new(cfg, dioxus_config.build_vdom(), self.shared.clone());
|
||||
let webview = WebviewInstance::new(cfg, virtual_dom, self.shared.clone());
|
||||
|
||||
let id = webview.desktop_context.window.id();
|
||||
self.webviews.insert(id, webview);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use std::borrow::Cow;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use dioxus_core::prelude::{Component, Element};
|
||||
use tao::window::{Icon, WindowBuilder, WindowId};
|
||||
use wry::{
|
||||
http::{Request as HttpRequest, Response as HttpResponse},
|
||||
|
||||
@@ -12,11 +12,9 @@ use dioxus_core::{
|
||||
prelude::{current_scope_id, ScopeId},
|
||||
use_hook, VirtualDom,
|
||||
};
|
||||
use dioxus_interpreter_js::binary_protocol::Channel;
|
||||
use dioxus_interpreter_js::MutationState;
|
||||
use rustc_hash::FxHashMap;
|
||||
use slab::Slab;
|
||||
use std::{cell::RefCell, fmt::Debug, rc::Rc, rc::Weak, sync::atomic::AtomicU16};
|
||||
use std::{cell::RefCell, fmt::Debug, rc::Rc, rc::Weak};
|
||||
use tao::{
|
||||
event::Event,
|
||||
event_loop::EventLoopWindowTarget,
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
use dioxus_core::{AttributeValue, Template, TemplateAttribute, TemplateNode};
|
||||
use dioxus_html::event_bubbles;
|
||||
use dioxus_interpreter_js::binary_protocol::Channel;
|
||||
use rustc_hash::FxHashMap;
|
||||
use std::{
|
||||
sync::atomic::AtomicU16,
|
||||
sync::Arc,
|
||||
sync::{atomic::Ordering, Mutex},
|
||||
};
|
||||
use std::{sync::Arc, sync::Mutex};
|
||||
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use wry::RequestAsyncResponder;
|
||||
|
||||
/// This handles communication between the requests that the webview makes and the interpreter. The interpreter constantly makes long running requests to the webview to get any edits that should be made to the DOM almost like server side events.
|
||||
/// It will hold onto the requests until the interpreter is ready to handle them and hold onto any pending edits until a new request is made.
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
pub use crate::Config;
|
||||
use crate::{
|
||||
app::App,
|
||||
ipc::{EventData, IpcMethod, UserWindowEvent},
|
||||
Config,
|
||||
};
|
||||
use dioxus_core::*;
|
||||
use std::any::Any;
|
||||
use tao::event::{Event, StartCause, WindowEvent};
|
||||
|
||||
/// Launch the WebView and run the event loop, with configuration and root props.
|
||||
///
|
||||
/// This will block the main thread, and *must* be spawned on the main thread. This function does not assume any runtime
|
||||
/// and is equivalent to calling launch_with_props with the tokio feature disabled.
|
||||
pub fn launch_with_props_blocking<P: AnyProps>(
|
||||
dioxus_cfg: CrossPlatformConfig<P>,
|
||||
desktop_config: Config,
|
||||
) {
|
||||
let (event_loop, mut app) = App::new(desktop_config, dioxus_cfg);
|
||||
pub fn launch_with_props_blocking(virtual_dom: VirtualDom, desktop_config: Config) {
|
||||
let (event_loop, mut app) = App::new(desktop_config, virtual_dom);
|
||||
|
||||
event_loop.run(move |window_event, _, control_flow| {
|
||||
app.tick(&window_event);
|
||||
@@ -50,23 +48,27 @@ pub fn launch_with_props_blocking<P: AnyProps>(
|
||||
})
|
||||
}
|
||||
|
||||
/// The desktop renderer platform
|
||||
pub struct DesktopPlatform;
|
||||
/// Launches the WebView and runs the event loop, with configuration and root props.
|
||||
pub fn launch(
|
||||
root: fn() -> Element,
|
||||
contexts: Vec<Box<dyn Fn() -> Box<dyn Any> + Send>>,
|
||||
platform_config: Config,
|
||||
) {
|
||||
let mut virtual_dom = VirtualDom::new(root);
|
||||
|
||||
impl<P: AnyProps> PlatformBuilder<P> for DesktopPlatform {
|
||||
type Config = Config;
|
||||
|
||||
fn launch(config: dioxus_core::CrossPlatformConfig<P>, platform_config: Self::Config) {
|
||||
#[cfg(feature = "tokio")]
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(tokio::task::unconstrained(async move {
|
||||
launch_with_props_blocking(config, platform_config)
|
||||
}));
|
||||
|
||||
#[cfg(not(feature = "tokio"))]
|
||||
launch_with_props_blocking(config, platform_config)
|
||||
for context in contexts {
|
||||
virtual_dom.insert_any_root_context(context());
|
||||
}
|
||||
|
||||
#[cfg(feature = "tokio")]
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(tokio::task::unconstrained(async move {
|
||||
launch_with_props_blocking(virtual_dom, platform_config)
|
||||
}));
|
||||
|
||||
#[cfg(not(feature = "tokio"))]
|
||||
launch_with_props_blocking(config, platform_config)
|
||||
}
|
||||
@@ -26,9 +26,8 @@ mod webview;
|
||||
#[cfg(any(target_os = "ios", target_os = "android"))]
|
||||
mod mobile_shortcut;
|
||||
|
||||
// The main entrypoint for this crate
|
||||
pub use launch::*;
|
||||
mod launch;
|
||||
/// The main entrypoint for this crate
|
||||
pub mod launch;
|
||||
|
||||
// Reexport tao and wry, might want to re-export other important things
|
||||
pub use tao;
|
||||
|
||||
Reference in new issue
Block a user