fix compilation
This commit is contained in:
1 parent
bcc2da4b42
commit
f6acaba061
8 files changed
+113
-112
No files matched your search
@@ -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