Clean up a number of examples

This commit is contained in:
Jonathan Kelley committed 2024-01-15 13:06:05 -08:00
1 parent f2caa3a3ad
commit 6134a2ce24
30 files changed
+284 -413

No files matched your search

+3 -3
View File
@@ -1,7 +1,7 @@
use std::borrow::Cow;
use std::path::PathBuf;
use dioxus_core::prelude::Component;
use dioxus_core::prelude::{Component, Element};
use tao::window::{Icon, WindowBuilder, WindowId};
use wry::{
http::{Request as HttpRequest, Response as HttpResponse},
@@ -74,8 +74,8 @@ impl Config {
/// Launch a Dioxus app using the given component and config
///
/// See the [`crate::launch::launch`] function for more details.
pub fn launch(self, root: Component<()>) {
crate::launch::launch_cfg(root, self)
pub fn launch(self, app: fn() -> Element) {
self.launch_with_props(|props| props(), app)
}
/// Launch a Dioxus app using the given component, config, and props
+14 -14
View File
@@ -2,6 +2,7 @@ use crate::{
assets::*, ipc::UserWindowEvent, shortcut::IntoAccelerator, window, DesktopContext,
ShortcutHandle, ShortcutRegistryError, WryEventHandler,
};
use dioxus_core::use_hook;
use tao::{event::Event, event_loop::EventLoopWindowTarget};
use wry::RequestAsyncResponder;
@@ -12,22 +13,21 @@ use wry::RequestAsyncResponder;
// .unwrap()
// }
// /// Get a closure that executes any JavaScript in the WebView context.
// pub fn use_wry_event_handler(
// ,
// handler: impl FnMut(&Event<UserWindowEvent>, &EventLoopWindowTarget<UserWindowEvent>) + 'static,
// ) -> &WryEventHandler {
// cx.use_hook(move || {
// let desktop = window();
/// Get a closure that executes any JavaScript in the WebView context.
pub fn use_wry_event_handler(
handler: impl FnMut(&Event<UserWindowEvent>, &EventLoopWindowTarget<UserWindowEvent>) + 'static,
) -> WryEventHandler {
use_hook(move || {
let desktop = window();
// let id = desktop.create_wry_event_handler(handler);
let id = desktop.create_wry_event_handler(handler);
// WryEventHandler {
// handlers: desktop.shared.event_handlers.clone(),
// id,
// }
// })
// }
WryEventHandler {
handlers: desktop.shared.event_handlers.clone(),
id,
}
})
}
// /// Provide a callback to handle asset loading yourself.
// ///
+4 -4
View File
@@ -23,8 +23,8 @@ use tao::event::{Event, StartCause, WindowEvent};
/// })
/// }
/// ```
pub fn launch(root: fn() -> Element) {
launch_with_props(|root| root(), root, Config::default())
pub fn launch(app: fn() -> Element) {
launch_with_props(|root| root(), app, Config::default())
}
/// Launch the WebView and run the event loop, with configuration.
@@ -47,8 +47,8 @@ pub fn launch(root: fn() -> Element) {
/// })
/// }
/// ```
pub fn launch_cfg(root: Component, config_builder: Config) {
launch_with_props(root, (), config_builder)
pub fn launch_cfg(app: fn() -> Element, config_builder: Config) {
launch_with_props(|props| props(), app, config_builder)
}
/// Launch the WebView and run the event loop, with configuration and root props.
+2
View File
@@ -46,3 +46,5 @@ pub use desktop_context::{
// pub use hooks::{use_asset_handler, use_global_shortcut, use_window, use_wry_event_handler};
pub use shortcut::{ShortcutHandle, ShortcutId, ShortcutRegistryError};
pub use wry::RequestAsyncResponder;
pub use hooks::*;