fix compilation

This commit is contained in:
Evan Almloff 2024-01-04 17:04:56 -06:00
parent bcc2da4b42
commit f6acaba061
8 changed files with 113 additions and 112 deletions

View file

@ -286,7 +286,8 @@ fn default_handler<'a>(error: CapturedError) -> LazyNodes<'a, 'a> {
attr_paths: &[], attr_paths: &[],
}; };
VNode { VNode {
parent: None, parent: Default::default(),
stable_id: Default::default(),
key: None, key: None,
template: std::cell::Cell::new(TEMPLATE), template: std::cell::Cell::new(TEMPLATE),
root_ids: bumpalo::collections::Vec::with_capacity_in(1usize, __cx.bump()).into(), root_ids: bumpalo::collections::Vec::with_capacity_in(1usize, __cx.bump()).into(),
@ -471,12 +472,13 @@ pub fn ErrorBoundary<'a>(cx: Scope<'a, ErrorBoundaryProps<'a>>) -> Element {
attr_paths: &[], attr_paths: &[],
}; };
VNode { VNode {
parent: None, parent: Default::default(),
stable_id: Default::default(),
key: None, key: None,
template: std::cell::Cell::new(TEMPLATE), template: std::cell::Cell::new(TEMPLATE),
root_ids: bumpalo::collections::Vec::with_capacity_in(1usize, __cx.bump()).into(), root_ids: bumpalo::collections::Vec::with_capacity_in(1usize, __cx.bump()).into(),
dynamic_nodes: __cx.bump().alloc([{ dynamic_nodes: __cx.bump().alloc([{
let ___nodes = (&cx.props.children).into_vnode(__cx); let ___nodes = (&cx.props.children).into_dyn_node(__cx);
___nodes ___nodes
}]), }]),
dynamic_attrs: __cx.bump().alloc([]), dynamic_attrs: __cx.bump().alloc([]),

View file

@ -59,13 +59,12 @@ tokio_runtime = ["tokio"]
fullscreen = ["wry/fullscreen"] fullscreen = ["wry/fullscreen"]
transparent = ["wry/transparent"] transparent = ["wry/transparent"]
devtools = ["wry/devtools"] devtools = ["wry/devtools"]
dox = ["wry/dox"]
hot-reload = ["dioxus-hot-reload"] hot-reload = ["dioxus-hot-reload"]
gnu = [] gnu = []
[package.metadata.docs.rs] [package.metadata.docs.rs]
default-features = false default-features = false
features = [ "dox", "tokio_runtime", "hot-reload" ] features = ["tokio_runtime", "hot-reload"]
[dev-dependencies] [dev-dependencies]
dioxus-core-macro = { workspace = true } dioxus-core-macro = { workspace = true }

View file

@ -466,9 +466,8 @@ pub fn use_wry_event_handler(
cx: &ScopeState, cx: &ScopeState,
handler: impl FnMut(&Event<UserWindowEvent>, &EventLoopWindowTarget<UserWindowEvent>) + 'static, handler: impl FnMut(&Event<UserWindowEvent>, &EventLoopWindowTarget<UserWindowEvent>) + 'static,
) -> &WryEventHandler { ) -> &WryEventHandler {
let desktop = use_window(cx);
cx.use_hook(move || { cx.use_hook(move || {
let desktop = desktop.clone(); let desktop = window();
let id = desktop.create_wry_event_handler(handler); let id = desktop.create_wry_event_handler(handler);

View file

@ -22,6 +22,7 @@ use crate::query::QueryResult;
use crate::shortcut::GlobalHotKeyEvent; use crate::shortcut::GlobalHotKeyEvent;
pub use cfg::{Config, WindowCloseBehaviour}; pub use cfg::{Config, WindowCloseBehaviour};
pub use desktop_context::DesktopContext; pub use desktop_context::DesktopContext;
#[allow(deprecated)]
pub use desktop_context::{ pub use desktop_context::{
use_window, use_wry_event_handler, window, DesktopService, WryEventHandler, WryEventHandlerId, use_window, use_wry_event_handler, window, DesktopService, WryEventHandler, WryEventHandlerId,
}; };
@ -33,8 +34,8 @@ use dioxus_interpreter_js::binary_protocol::Channel;
use element::DesktopElement; use element::DesktopElement;
use eval::init_eval; use eval::init_eval;
use futures_util::{pin_mut, FutureExt}; use futures_util::{pin_mut, FutureExt};
use rustc_hash::FxHashMap;
pub use protocol::{use_asset_handler, AssetFuture, AssetHandler, AssetRequest, AssetResponse}; pub use protocol::{use_asset_handler, AssetFuture, AssetHandler, AssetRequest, AssetResponse};
use rustc_hash::FxHashMap;
use shortcut::ShortcutRegistry; use shortcut::ShortcutRegistry;
pub use shortcut::{use_global_shortcut, ShortcutHandle, ShortcutId, ShortcutRegistryError}; pub use shortcut::{use_global_shortcut, ShortcutHandle, ShortcutId, ShortcutRegistryError};
use std::cell::Cell; use std::cell::Cell;
@ -49,7 +50,7 @@ use tao::{
event::{Event, StartCause, WindowEvent}, event::{Event, StartCause, WindowEvent},
event_loop::ControlFlow, event_loop::ControlFlow,
}; };
pub use webview::build_default_menu_bar; // pub use webview::build_default_menu_bar;
pub use wry; pub use wry;
pub use wry::application as tao; pub use wry::application as tao;
use wry::application::event_loop::EventLoopBuilder; use wry::application::event_loop::EventLoopBuilder;
@ -412,8 +413,8 @@ fn create_new_window(
queue.clone(), queue.clone(),
event_handlers.clone(), event_handlers.clone(),
shortcut_manager, shortcut_manager,
asset_handlers,
edit_queue, edit_queue,
asset_handlers,
)); ));
let cx = dom.base_scope(); let cx = dom.base_scope();

View file

@ -1,5 +1,6 @@
use crate::{window, DesktopContext};
use dioxus_core::ScopeState; use dioxus_core::ScopeState;
use dioxus_interpreter_js::{COMMON_JS, INTERPRETER_JS}; use dioxus_interpreter_js::INTERPRETER_JS;
use slab::Slab; use slab::Slab;
use std::{ use std::{
borrow::Cow, borrow::Cow,
@ -16,10 +17,8 @@ use tokio::{
}; };
use wry::{ use wry::{
http::{status::StatusCode, Request, Response}, http::{status::StatusCode, Request, Response},
webview::RequestAsyncResponder,
Result, Result,
}; };
use crate::{use_window, DesktopContext};
use crate::desktop_context::EditQueue; use crate::desktop_context::EditQueue;
@ -52,7 +51,7 @@ fn module_loader(root_name: &str, headless: bool) -> String {
} }
}"#, }"#,
); );
format!( format!(
r#" r#"
<script type="module"> <script type="module">
@ -197,8 +196,8 @@ pub fn use_asset_handler<F: AssetFuture>(
cx: &ScopeState, cx: &ScopeState,
handler: impl AssetHandler<F>, handler: impl AssetHandler<F>,
) -> &AssetHandlerHandle { ) -> &AssetHandlerHandle {
let desktop = Rc::clone(use_window(cx));
cx.use_hook(|| { cx.use_hook(|| {
let desktop = window();
let handler_id = Rc::new(OnceCell::new()); let handler_id = Rc::new(OnceCell::new());
let handler_id_ref = Rc::clone(&handler_id); let handler_id_ref = Rc::clone(&handler_id);
let desktop_ref = Rc::clone(&desktop); let desktop_ref = Rc::clone(&desktop);
@ -221,7 +220,8 @@ pub(super) async fn desktop_handler(
asset_handlers: &AssetHandlerRegistry, asset_handlers: &AssetHandlerRegistry,
edit_queue: &EditQueue, edit_queue: &EditQueue,
headless: bool, headless: bool,
) -> Result<AssetResponse> { responder: wry::webview::RequestAsyncResponder,
) {
let request = AssetRequest::from(request); let request = AssetRequest::from(request);
// If the request is for the root, we'll serve the index.html file. // If the request is for the root, we'll serve the index.html file.
@ -272,7 +272,8 @@ pub(super) async fn desktop_handler(
// If the user provided a custom asset handler, then call it and return the response // If the user provided a custom asset handler, then call it and return the response
// if the request was handled. // if the request was handled.
if let Some(response) = asset_handlers.try_handlers(&request).await { if let Some(response) = asset_handlers.try_handlers(&request).await {
return Ok(response); responder.respond(response);
return;
} }
// Else, try to serve a file from the filesystem. // Else, try to serve a file from the filesystem.

View file

@ -5,7 +5,7 @@ use dioxus_html::input_data::keyboard_types::Modifiers;
use slab::Slab; use slab::Slab;
use wry::application::keyboard::ModifiersState; use wry::application::keyboard::ModifiersState;
use crate::{desktop_context::DesktopContext, use_window}; use crate::{desktop_context::DesktopContext, window};
#[cfg(any( #[cfg(any(
target_os = "windows", target_os = "windows",
@ -183,9 +183,8 @@ pub fn use_global_shortcut(
accelerator: impl IntoAccelerator, accelerator: impl IntoAccelerator,
handler: impl FnMut() + 'static, handler: impl FnMut() + 'static,
) -> &Result<ShortcutHandle, ShortcutRegistryError> { ) -> &Result<ShortcutHandle, ShortcutRegistryError> {
let desktop = use_window(cx);
cx.use_hook(move || { cx.use_hook(move || {
let desktop = desktop.clone(); let desktop = window();
let id = desktop.create_shortcut(accelerator.accelerator(), handler); let id = desktop.create_shortcut(accelerator.accelerator(), handler);

View file

@ -4,7 +4,6 @@ use crate::{desktop_context::UserWindowEvent, Config};
use tao::event_loop::{EventLoopProxy, EventLoopWindowTarget}; use tao::event_loop::{EventLoopProxy, EventLoopWindowTarget};
pub use wry; pub use wry;
pub use wry::application as tao; pub use wry::application as tao;
use wry::application::menu::{MenuBar, MenuItem};
use wry::application::window::Window; use wry::application::window::Window;
use wry::http::Response; use wry::http::Response;
use wry::webview::{WebContext, WebView, WebViewBuilder}; use wry::webview::{WebContext, WebView, WebViewBuilder};
@ -21,11 +20,10 @@ pub(crate) fn build(
let index_file = cfg.custom_index.clone(); let index_file = cfg.custom_index.clone();
let root_name = cfg.root_name.clone(); let root_name = cfg.root_name.clone();
if cfg.enable_default_menu_bar { // TODO: restore the menu bar with muda: https://github.com/tauri-apps/muda/blob/dev/examples/wry.rs
builder = builder.with_menu(build_default_menu_bar()); // if cfg.enable_default_menu_bar {
} // builder = builder.with_menu(build_default_menu_bar());
// }
let window = builder.with_visible(false).build(event_loop).unwrap();
// We assume that if the icon is None in cfg, then the user just didnt set it // We assume that if the icon is None in cfg, then the user just didnt set it
if cfg.window.window.window_icon.is_none() { if cfg.window.window.window_icon.is_none() {
@ -56,22 +54,28 @@ pub(crate) fn build(
_ = proxy.send_event(UserWindowEvent(EventData::Ipc(message), window.id())); _ = proxy.send_event(UserWindowEvent(EventData::Ipc(message), window.id()));
} }
}) })
.with_asynchronous_custom_protocol(String::from("dioxus"), move |request, responder| { .with_asynchronous_custom_protocol(String::from("dioxus"), {
let custom_head = custom_head.clone(); let edit_queue = edit_queue.clone();
let index_file = index_file.clone(); move |request, responder| {
let root_name = root_name.clone(); let custom_head = custom_head.clone();
let asset_handlers_ref = asset_handlers_ref.clone(); let index_file = index_file.clone();
tokio::spawn(async move { let root_name = root_name.clone();
let response_res = protocol::desktop_handler( let asset_handlers_ref = asset_handlers_ref.clone();
request, let edit_queue = edit_queue.clone();
custom_head.clone(), tokio::spawn(async move {
index_file.clone(), protocol::desktop_handler(
&root_name, request,
&asset_handlers_ref, custom_head.clone(),
) index_file.clone(),
.await; &root_name,
responder.respond(response); &asset_handlers_ref,
}); &edit_queue,
headless,
responder,
)
.await;
});
}
}) })
.with_file_drop_handler(move |window, evet| { .with_file_drop_handler(move |window, evet| {
file_handler file_handler
@ -97,16 +101,7 @@ pub(crate) fn build(
// .with_web_context(&mut web_context); // .with_web_context(&mut web_context);
for (name, handler) in cfg.protocols.drain(..) { for (name, handler) in cfg.protocols.drain(..) {
webview = webview.with_custom_protocol(name, move |r| match handler(&r) { webview = webview.with_custom_protocol(name, move |r| handler(r))
Ok(response) => response,
Err(err) => {
tracing::error!("Error: {}", err);
Response::builder()
.status(500)
.body(err.to_string().into_bytes().into())
.unwrap()
}
})
} }
if cfg.disable_context_menu { if cfg.disable_context_menu {
@ -129,63 +124,68 @@ pub(crate) fn build(
webview = webview.with_devtools(true); webview = webview.with_devtools(true);
} }
(webview.build().unwrap(), web_context, asset_handlers, edit_queue) (
webview.build().unwrap(),
web_context,
asset_handlers,
edit_queue,
)
} }
/// Builds a standard menu bar depending on the users platform. It may be used as a starting point // /// Builds a standard menu bar depending on the users platform. It may be used as a starting point
/// to further customize the menu bar and pass it to a [`WindowBuilder`](tao::window::WindowBuilder). // /// to further customize the menu bar and pass it to a [`WindowBuilder`](tao::window::WindowBuilder).
/// > Note: The default menu bar enables macOS shortcuts like cut/copy/paste. // /// > Note: The default menu bar enables macOS shortcuts like cut/copy/paste.
/// > The menu bar differs per platform because of constraints introduced // /// > The menu bar differs per platform because of constraints introduced
/// > by [`MenuItem`](tao::menu::MenuItem). // /// > by [`MenuItem`](tao::menu::MenuItem).
pub fn build_default_menu_bar() -> MenuBar { // pub fn build_default_menu_bar() -> MenuBar {
let mut menu_bar = MenuBar::new(); // let mut menu_bar = MenuBar::new();
// since it is uncommon on windows to have an "application menu" // // since it is uncommon on windows to have an "application menu"
// we add a "window" menu to be more consistent across platforms with the standard menu // // we add a "window" menu to be more consistent across platforms with the standard menu
let mut window_menu = MenuBar::new(); // let mut window_menu = MenuBar::new();
#[cfg(target_os = "macos")] // #[cfg(target_os = "macos")]
{ // {
window_menu.add_native_item(MenuItem::EnterFullScreen); // window_menu.add_native_item(MenuItem::EnterFullScreen);
window_menu.add_native_item(MenuItem::Zoom); // window_menu.add_native_item(MenuItem::Zoom);
window_menu.add_native_item(MenuItem::Separator); // window_menu.add_native_item(MenuItem::Separator);
} // }
window_menu.add_native_item(MenuItem::Hide); // window_menu.add_native_item(MenuItem::Hide);
#[cfg(target_os = "macos")] // #[cfg(target_os = "macos")]
{ // {
window_menu.add_native_item(MenuItem::HideOthers); // window_menu.add_native_item(MenuItem::HideOthers);
window_menu.add_native_item(MenuItem::ShowAll); // window_menu.add_native_item(MenuItem::ShowAll);
} // }
window_menu.add_native_item(MenuItem::Minimize); // window_menu.add_native_item(MenuItem::Minimize);
window_menu.add_native_item(MenuItem::CloseWindow); // window_menu.add_native_item(MenuItem::CloseWindow);
window_menu.add_native_item(MenuItem::Separator); // window_menu.add_native_item(MenuItem::Separator);
window_menu.add_native_item(MenuItem::Quit); // window_menu.add_native_item(MenuItem::Quit);
menu_bar.add_submenu("Window", true, window_menu); // menu_bar.add_submenu("Window", true, window_menu);
// since tao supports none of the below items on linux we should only add them on macos/windows // // since tao supports none of the below items on linux we should only add them on macos/windows
#[cfg(not(target_os = "linux"))] // #[cfg(not(target_os = "linux"))]
{ // {
let mut edit_menu = MenuBar::new(); // let mut edit_menu = MenuBar::new();
#[cfg(target_os = "macos")] // #[cfg(target_os = "macos")]
{ // {
edit_menu.add_native_item(MenuItem::Undo); // edit_menu.add_native_item(MenuItem::Undo);
edit_menu.add_native_item(MenuItem::Redo); // edit_menu.add_native_item(MenuItem::Redo);
edit_menu.add_native_item(MenuItem::Separator); // edit_menu.add_native_item(MenuItem::Separator);
} // }
edit_menu.add_native_item(MenuItem::Cut); // edit_menu.add_native_item(MenuItem::Cut);
edit_menu.add_native_item(MenuItem::Copy); // edit_menu.add_native_item(MenuItem::Copy);
edit_menu.add_native_item(MenuItem::Paste); // edit_menu.add_native_item(MenuItem::Paste);
#[cfg(target_os = "macos")] // #[cfg(target_os = "macos")]
{ // {
edit_menu.add_native_item(MenuItem::Separator); // edit_menu.add_native_item(MenuItem::Separator);
edit_menu.add_native_item(MenuItem::SelectAll); // edit_menu.add_native_item(MenuItem::SelectAll);
} // }
menu_bar.add_submenu("Edit", true, edit_menu); // menu_bar.add_submenu("Edit", true, edit_menu);
} // }
menu_bar // menu_bar
} // }

View file

@ -48,23 +48,23 @@ pub fn rsx_node_from_html(node: &Node) -> Option<BodyNode> {
} else { } else {
Ident::new(name, Span::call_site()) Ident::new(name, Span::call_site())
}; };
ElementAttr::AttrText { value, name: ident } ElementAttr {
value: dioxus_rsx::ElementAttrValue::AttrLiteral(value),
name: dioxus_rsx::ElementAttrName::BuiltIn(ident),
}
} else { } else {
// If we don't recognize the attribute, we assume it's a custom attribute // If we don't recognize the attribute, we assume it's a custom attribute
ElementAttr::CustomAttrText { ElementAttr {
value, value: dioxus_rsx::ElementAttrValue::AttrLiteral(value),
name: LitStr::new(name, Span::call_site()), name: dioxus_rsx::ElementAttrName::Custom(LitStr::new(
name,
Span::call_site(),
)),
} }
}; };
ElementAttrNamed { ElementAttrNamed {
el_name: el_name.clone(), el_name: el_name.clone(),
// attr: ElementAttr {
// value: dioxus_rsx::ElementAttrValue::AttrLiteral(ifmt_from_text(
// value.as_deref().unwrap_or("false"),
// )),
// name: dioxus_rsx::ElementAttrName::BuiltIn(ident),
// },
attr, attr,
} }
}) })