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: &[],
};
VNode {
parent: None,
parent: Default::default(),
stable_id: Default::default(),
key: None,
template: std::cell::Cell::new(TEMPLATE),
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: &[],
};
VNode {
parent: None,
parent: Default::default(),
stable_id: Default::default(),
key: None,
template: std::cell::Cell::new(TEMPLATE),
root_ids: bumpalo::collections::Vec::with_capacity_in(1usize, __cx.bump()).into(),
dynamic_nodes: __cx.bump().alloc([{
let ___nodes = (&cx.props.children).into_vnode(__cx);
let ___nodes = (&cx.props.children).into_dyn_node(__cx);
___nodes
}]),
dynamic_attrs: __cx.bump().alloc([]),

View file

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

View file

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

View file

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

View file

@ -1,5 +1,6 @@
use crate::{window, DesktopContext};
use dioxus_core::ScopeState;
use dioxus_interpreter_js::{COMMON_JS, INTERPRETER_JS};
use dioxus_interpreter_js::INTERPRETER_JS;
use slab::Slab;
use std::{
borrow::Cow,
@ -16,10 +17,8 @@ use tokio::{
};
use wry::{
http::{status::StatusCode, Request, Response},
webview::RequestAsyncResponder,
Result,
};
use crate::{use_window, DesktopContext};
use crate::desktop_context::EditQueue;
@ -197,8 +196,8 @@ pub fn use_asset_handler<F: AssetFuture>(
cx: &ScopeState,
handler: impl AssetHandler<F>,
) -> &AssetHandlerHandle {
let desktop = Rc::clone(use_window(cx));
cx.use_hook(|| {
let desktop = window();
let handler_id = Rc::new(OnceCell::new());
let handler_id_ref = Rc::clone(&handler_id);
let desktop_ref = Rc::clone(&desktop);
@ -221,7 +220,8 @@ pub(super) async fn desktop_handler(
asset_handlers: &AssetHandlerRegistry,
edit_queue: &EditQueue,
headless: bool,
) -> Result<AssetResponse> {
responder: wry::webview::RequestAsyncResponder,
) {
let request = AssetRequest::from(request);
// 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 request was handled.
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.

View file

@ -5,7 +5,7 @@ use dioxus_html::input_data::keyboard_types::Modifiers;
use slab::Slab;
use wry::application::keyboard::ModifiersState;
use crate::{desktop_context::DesktopContext, use_window};
use crate::{desktop_context::DesktopContext, window};
#[cfg(any(
target_os = "windows",
@ -183,9 +183,8 @@ pub fn use_global_shortcut(
accelerator: impl IntoAccelerator,
handler: impl FnMut() + 'static,
) -> &Result<ShortcutHandle, ShortcutRegistryError> {
let desktop = use_window(cx);
cx.use_hook(move || {
let desktop = desktop.clone();
let desktop = window();
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};
pub use wry;
pub use wry::application as tao;
use wry::application::menu::{MenuBar, MenuItem};
use wry::application::window::Window;
use wry::http::Response;
use wry::webview::{WebContext, WebView, WebViewBuilder};
@ -21,11 +20,10 @@ pub(crate) fn build(
let index_file = cfg.custom_index.clone();
let root_name = cfg.root_name.clone();
if cfg.enable_default_menu_bar {
builder = builder.with_menu(build_default_menu_bar());
}
let window = builder.with_visible(false).build(event_loop).unwrap();
// TODO: restore the menu bar with muda: https://github.com/tauri-apps/muda/blob/dev/examples/wry.rs
// if cfg.enable_default_menu_bar {
// builder = builder.with_menu(build_default_menu_bar());
// }
// 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() {
@ -56,22 +54,28 @@ pub(crate) fn build(
_ = 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 edit_queue = edit_queue.clone();
move |request, responder| {
let custom_head = custom_head.clone();
let index_file = index_file.clone();
let root_name = root_name.clone();
let asset_handlers_ref = asset_handlers_ref.clone();
let edit_queue = edit_queue.clone();
tokio::spawn(async move {
let response_res = protocol::desktop_handler(
protocol::desktop_handler(
request,
custom_head.clone(),
index_file.clone(),
&root_name,
&asset_handlers_ref,
&edit_queue,
headless,
responder,
)
.await;
responder.respond(response);
});
}
})
.with_file_drop_handler(move |window, evet| {
file_handler
@ -97,16 +101,7 @@ pub(crate) fn build(
// .with_web_context(&mut web_context);
for (name, handler) in cfg.protocols.drain(..) {
webview = webview.with_custom_protocol(name, move |r| match handler(&r) {
Ok(response) => response,
Err(err) => {
tracing::error!("Error: {}", err);
Response::builder()
.status(500)
.body(err.to_string().into_bytes().into())
.unwrap()
}
})
webview = webview.with_custom_protocol(name, move |r| handler(r))
}
if cfg.disable_context_menu {
@ -129,63 +124,68 @@ pub(crate) fn build(
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
/// 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.
/// > The menu bar differs per platform because of constraints introduced
/// > by [`MenuItem`](tao::menu::MenuItem).
pub fn build_default_menu_bar() -> MenuBar {
let mut menu_bar = MenuBar::new();
// /// 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).
// /// > Note: The default menu bar enables macOS shortcuts like cut/copy/paste.
// /// > The menu bar differs per platform because of constraints introduced
// /// > by [`MenuItem`](tao::menu::MenuItem).
// pub fn build_default_menu_bar() -> MenuBar {
// let mut menu_bar = MenuBar::new();
// 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
let mut window_menu = MenuBar::new();
#[cfg(target_os = "macos")]
{
window_menu.add_native_item(MenuItem::EnterFullScreen);
window_menu.add_native_item(MenuItem::Zoom);
window_menu.add_native_item(MenuItem::Separator);
}
// // 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
// let mut window_menu = MenuBar::new();
// #[cfg(target_os = "macos")]
// {
// window_menu.add_native_item(MenuItem::EnterFullScreen);
// window_menu.add_native_item(MenuItem::Zoom);
// 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")]
{
window_menu.add_native_item(MenuItem::HideOthers);
window_menu.add_native_item(MenuItem::ShowAll);
}
// #[cfg(target_os = "macos")]
// {
// window_menu.add_native_item(MenuItem::HideOthers);
// window_menu.add_native_item(MenuItem::ShowAll);
// }
window_menu.add_native_item(MenuItem::Minimize);
window_menu.add_native_item(MenuItem::CloseWindow);
window_menu.add_native_item(MenuItem::Separator);
window_menu.add_native_item(MenuItem::Quit);
menu_bar.add_submenu("Window", true, window_menu);
// window_menu.add_native_item(MenuItem::Minimize);
// window_menu.add_native_item(MenuItem::CloseWindow);
// window_menu.add_native_item(MenuItem::Separator);
// window_menu.add_native_item(MenuItem::Quit);
// 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
#[cfg(not(target_os = "linux"))]
{
let mut edit_menu = MenuBar::new();
#[cfg(target_os = "macos")]
{
edit_menu.add_native_item(MenuItem::Undo);
edit_menu.add_native_item(MenuItem::Redo);
edit_menu.add_native_item(MenuItem::Separator);
}
// // since tao supports none of the below items on linux we should only add them on macos/windows
// #[cfg(not(target_os = "linux"))]
// {
// let mut edit_menu = MenuBar::new();
// #[cfg(target_os = "macos")]
// {
// edit_menu.add_native_item(MenuItem::Undo);
// edit_menu.add_native_item(MenuItem::Redo);
// edit_menu.add_native_item(MenuItem::Separator);
// }
edit_menu.add_native_item(MenuItem::Cut);
edit_menu.add_native_item(MenuItem::Copy);
edit_menu.add_native_item(MenuItem::Paste);
// edit_menu.add_native_item(MenuItem::Cut);
// edit_menu.add_native_item(MenuItem::Copy);
// edit_menu.add_native_item(MenuItem::Paste);
#[cfg(target_os = "macos")]
{
edit_menu.add_native_item(MenuItem::Separator);
edit_menu.add_native_item(MenuItem::SelectAll);
}
menu_bar.add_submenu("Edit", true, edit_menu);
}
// #[cfg(target_os = "macos")]
// {
// edit_menu.add_native_item(MenuItem::Separator);
// edit_menu.add_native_item(MenuItem::SelectAll);
// }
// 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 {
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 {
// If we don't recognize the attribute, we assume it's a custom attribute
ElementAttr::CustomAttrText {
value,
name: LitStr::new(name, Span::call_site()),
ElementAttr {
value: dioxus_rsx::ElementAttrValue::AttrLiteral(value),
name: dioxus_rsx::ElementAttrName::Custom(LitStr::new(
name,
Span::call_site(),
)),
}
};
ElementAttrNamed {
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,
}
})