fix compilation
This commit is contained in:
1 parent
bcc2da4b42
commit
f6acaba061
8 files changed
+113
-112
No files matched your search
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -52,7 +51,7 @@ fn module_loader(root_name: &str, headless: bool) -> String {
|
||||
}
|
||||
}"#,
|
||||
);
|
||||
|
||||
|
||||
format!(
|
||||
r#"
|
||||
<script type="module">
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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| {
|
||||
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();
|
||||
tokio::spawn(async move {
|
||||
let response_res = protocol::desktop_handler(
|
||||
request,
|
||||
custom_head.clone(),
|
||||
index_file.clone(),
|
||||
&root_name,
|
||||
&asset_handlers_ref,
|
||||
)
|
||||
.await;
|
||||
responder.respond(response);
|
||||
});
|
||||
.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 {
|
||||
protocol::desktop_handler(
|
||||
request,
|
||||
custom_head.clone(),
|
||||
index_file.clone(),
|
||||
&root_name,
|
||||
&asset_handlers_ref,
|
||||
&edit_queue,
|
||||
headless,
|
||||
responder,
|
||||
)
|
||||
.await;
|
||||
});
|
||||
}
|
||||
})
|
||||
.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
|
||||
// }
|
||||
Reference in new issue
Block a user