Merge branch 'upstream' into query-system

This commit is contained in:
Evan Almloff committed 2023-04-18 10:33:40 -05:00
commit 223c7efce2
27 files changed
+480 -87

No files matched your search

Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 75 KiB

After

Width:  |  Height:  |  Size: 15 KiB

+3 -2
View File
@@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::path::PathBuf;
use wry::application::window::Icon;
@@ -28,7 +29,7 @@ type DropHandler = Box<dyn Fn(&Window, FileDropEvent) -> bool>;
pub(crate) type WryProtocol = (
String,
Box<dyn Fn(&HttpRequest<Vec<u8>>) -> WryResult<HttpResponse<Vec<u8>>> + 'static>,
Box<dyn Fn(&HttpRequest<Vec<u8>>) -> WryResult<HttpResponse<Cow<'static, [u8]>>> + 'static>,
);
impl Config {
@@ -98,7 +99,7 @@ impl Config {
/// Set a custom protocol
pub fn with_custom_protocol<F>(mut self, name: String, handler: F) -> Self
where
F: Fn(&HttpRequest<Vec<u8>>) -> WryResult<HttpResponse<Vec<u8>>> + 'static,
F: Fn(&HttpRequest<Vec<u8>>) -> WryResult<HttpResponse<Cow<'static, [u8]>>> + 'static,
{
self.protocols.push((name, Box::new(handler)));
self
+6 -2
View File
@@ -40,8 +40,8 @@ use tao::{
};
pub use wry;
pub use wry::application as tao;
use wry::application::window::WindowId;
use wry::webview::WebView;
use wry::{application::window::WindowId, webview::WebContext};
/// Launch the WebView and run the event loop.
///
@@ -311,7 +311,7 @@ fn create_new_window(
event_handlers: &WindowEventHandlers,
shortcut_manager: ShortcutRegistry,
) -> WebviewHandler {
let webview = webview::build(&mut cfg, event_loop, proxy.clone());
let (webview, web_context) = webview::build(&mut cfg, event_loop, proxy.clone());
dom.base_scope().provide_context(DesktopContext::new(
webview.clone(),
@@ -329,6 +329,7 @@ fn create_new_window(
webview,
dom,
waker: waker::tao_waker(proxy, id),
web_context,
}
}
@@ -336,6 +337,9 @@ struct WebviewHandler {
dom: VirtualDom,
webview: Rc<wry::webview::WebView>,
waker: Waker,
// This is nessisary because of a bug in wry. Wry assumes the webcontext is alive for the lifetime of the webview. We need to keep the webcontext alive, otherwise the webview will crash
#[allow(dead_code)]
web_context: WebContext,
}
/// Poll the virtualdom until it's pending
+8 -5
View File
@@ -1,5 +1,8 @@
use dioxus_interpreter_js::INTERPRETER_JS;
use std::path::{Path, PathBuf};
use std::{
borrow::Cow,
path::{Path, PathBuf},
};
use wry::{
http::{status::StatusCode, Request, Response},
Result,
@@ -27,7 +30,7 @@ pub(super) fn desktop_handler(
custom_head: Option<String>,
custom_index: Option<String>,
root_name: &str,
) -> Result<Response<Vec<u8>>> {
) -> Result<Response<Cow<'static, [u8]>>> {
// If the request is for the root, we'll serve the index.html file.
if request.uri().path() == "/" {
// If a custom index is provided, just defer to that, expecting the user to know what they're doing.
@@ -53,7 +56,7 @@ pub(super) fn desktop_handler(
return Response::builder()
.header("Content-Type", "text/html")
.body(body)
.body(Cow::from(body))
.map_err(From::from);
}
@@ -72,13 +75,13 @@ pub(super) fn desktop_handler(
if asset.exists() {
return Response::builder()
.header("Content-Type", get_mime_from_path(&asset)?)
.body(std::fs::read(asset)?)
.body(Cow::from(std::fs::read(asset)?))
.map_err(From::from);
}
Response::builder()
.status(StatusCode::NOT_FOUND)
.body(String::from("Not Found").into_bytes())
.body(Cow::from(String::from("Not Found").into_bytes()))
.map_err(From::from)
}
+13 -2
View File
@@ -13,7 +13,7 @@ pub fn build(
cfg: &mut Config,
event_loop: &EventLoopWindowTarget<UserWindowEvent>,
proxy: EventLoopProxy<UserWindowEvent>,
) -> Rc<WebView> {
) -> (Rc<WebView>, WebContext) {
let builder = cfg.window.clone();
let window = builder.build(event_loop).unwrap();
let file_handler = cfg.file_drop_handler.take();
@@ -57,6 +57,17 @@ pub fn build(
})
.with_web_context(&mut web_context);
#[cfg(windows)]
{
// Windows has a platform specific settings to disable the browser shortcut keys
use wry::webview::WebViewBuilderExtWindows;
webview = webview.with_browser_accelerator_keys(false);
}
// These are commented out because wry is currently broken in wry
// let mut web_context = WebContext::new(cfg.data_dir.clone());
// .with_web_context(&mut web_context);
for (name, handler) in cfg.protocols.drain(..) {
webview = webview.with_custom_protocol(name, handler)
}
@@ -81,5 +92,5 @@ pub fn build(
webview = webview.with_devtools(true);
}
Rc::new(webview.build().unwrap())
(Rc::new(webview.build().unwrap()), web_context)
}