Update wry to 0.22.0 (#604)
This commit is contained in:
1 parent
f89cd20455
commit
5c996f21fb
3 files changed
+26
-18
No files matched your search
@@ -20,7 +20,7 @@ serde = "1.0.136"
|
|||||||
serde_json = "1.0.79"
|
serde_json = "1.0.79"
|
||||||
thiserror = "1.0.30"
|
thiserror = "1.0.30"
|
||||||
log = "0.4.14"
|
log = "0.4.14"
|
||||||
wry = { version = "0.20.2" }
|
wry = { version = "0.22.0", git = "https://github.com/tauri-apps/wry", branch = "release" }
|
||||||
futures-channel = "0.3.21"
|
futures-channel = "0.3.21"
|
||||||
tokio = { version = "1.16.1", features = [
|
tokio = { version = "1.16.1", features = [
|
||||||
"sync",
|
"sync",
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ type DropHandler = Box<dyn Fn(&Window, FileDropEvent) -> bool>;
|
|||||||
|
|
||||||
pub(crate) type WryProtocol = (
|
pub(crate) type WryProtocol = (
|
||||||
String,
|
String,
|
||||||
Box<dyn Fn(&HttpRequest) -> WryResult<HttpResponse> + 'static>,
|
Box<dyn Fn(&HttpRequest<Vec<u8>>) -> WryResult<HttpResponse<Vec<u8>>> + 'static>,
|
||||||
);
|
);
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@@ -96,7 +96,7 @@ impl Config {
|
|||||||
/// Set a custom protocol
|
/// Set a custom protocol
|
||||||
pub fn with_custom_protocol<F>(mut self, name: String, handler: F) -> Self
|
pub fn with_custom_protocol<F>(mut self, name: String, handler: F) -> Self
|
||||||
where
|
where
|
||||||
F: Fn(&HttpRequest) -> WryResult<HttpResponse> + 'static,
|
F: Fn(&HttpRequest<Vec<u8>>) -> WryResult<HttpResponse<Vec<u8>>> + 'static,
|
||||||
{
|
{
|
||||||
self.protocols.push((name, Box::new(handler)));
|
self.protocols.push((name, Box::new(handler)));
|
||||||
self
|
self
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use wry::{
|
use wry::{
|
||||||
http::{status::StatusCode, Request, Response, ResponseBuilder},
|
http::{status::StatusCode, Request, Response},
|
||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -13,14 +13,14 @@ const MODULE_LOADER: &str = r#"
|
|||||||
"#;
|
"#;
|
||||||
|
|
||||||
pub(super) fn desktop_handler(
|
pub(super) fn desktop_handler(
|
||||||
request: &Request,
|
request: &Request<Vec<u8>>,
|
||||||
asset_root: Option<PathBuf>,
|
asset_root: Option<PathBuf>,
|
||||||
custom_head: Option<String>,
|
custom_head: Option<String>,
|
||||||
custom_index: Option<String>,
|
custom_index: Option<String>,
|
||||||
) -> Result<Response> {
|
) -> Result<Response<Vec<u8>>> {
|
||||||
// Any content that uses the `dioxus://` scheme will be shuttled through this handler as a "special case".
|
// Any content that uses the `dioxus://` scheme will be shuttled through this handler as a "special case".
|
||||||
// For now, we only serve two pieces of content which get included as bytes into the final binary.
|
// For now, we only serve two pieces of content which get included as bytes into the final binary.
|
||||||
let path = request.uri().replace("dioxus://", "");
|
let path = request.uri().to_string().replace("dioxus://", "");
|
||||||
|
|
||||||
// all assets should be called from index.html
|
// all assets should be called from index.html
|
||||||
let trimmed = path.trim_start_matches("index.html/");
|
let trimmed = path.trim_start_matches("index.html/");
|
||||||
@@ -32,7 +32,10 @@ pub(super) fn desktop_handler(
|
|||||||
let rendered = custom_index
|
let rendered = custom_index
|
||||||
.replace("</body>", &format!("{}</body>", MODULE_LOADER))
|
.replace("</body>", &format!("{}</body>", MODULE_LOADER))
|
||||||
.into_bytes();
|
.into_bytes();
|
||||||
ResponseBuilder::new().mimetype("text/html").body(rendered)
|
Response::builder()
|
||||||
|
.header("Content-Type", "text/html")
|
||||||
|
.body(rendered)
|
||||||
|
.map_err(From::from)
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, we'll serve the default index.html and apply a custom head if that's specified.
|
// Otherwise, we'll serve the default index.html and apply a custom head if that's specified.
|
||||||
let mut template = include_str!("./index.html").to_string();
|
let mut template = include_str!("./index.html").to_string();
|
||||||
@@ -41,14 +44,16 @@ pub(super) fn desktop_handler(
|
|||||||
}
|
}
|
||||||
template = template.replace("<!-- MODULE LOADER -->", MODULE_LOADER);
|
template = template.replace("<!-- MODULE LOADER -->", MODULE_LOADER);
|
||||||
|
|
||||||
ResponseBuilder::new()
|
Response::builder()
|
||||||
.mimetype("text/html")
|
.header("Content-Type", "text/html")
|
||||||
.body(template.into_bytes())
|
.body(template.into_bytes())
|
||||||
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
} else if trimmed == "index.js" {
|
} else if trimmed == "index.js" {
|
||||||
ResponseBuilder::new()
|
Response::builder()
|
||||||
.mimetype("text/javascript")
|
.header("Content-Type", "text/javascript")
|
||||||
.body(dioxus_interpreter_js::INTERPRETER_JS.as_bytes().to_vec())
|
.body(dioxus_interpreter_js::INTERPRETER_JS.as_bytes().to_vec())
|
||||||
|
.map_err(From::from)
|
||||||
} else {
|
} else {
|
||||||
let asset_root = asset_root
|
let asset_root = asset_root
|
||||||
.unwrap_or_else(|| get_asset_root().unwrap_or_else(|| Path::new(".").to_path_buf()))
|
.unwrap_or_else(|| get_asset_root().unwrap_or_else(|| Path::new(".").to_path_buf()))
|
||||||
@@ -57,20 +62,23 @@ pub(super) fn desktop_handler(
|
|||||||
let asset = asset_root.join(trimmed).canonicalize()?;
|
let asset = asset_root.join(trimmed).canonicalize()?;
|
||||||
|
|
||||||
if !asset.starts_with(asset_root) {
|
if !asset.starts_with(asset_root) {
|
||||||
return ResponseBuilder::new()
|
return Response::builder()
|
||||||
.status(StatusCode::FORBIDDEN)
|
.status(StatusCode::FORBIDDEN)
|
||||||
.body(String::from("Forbidden").into_bytes());
|
.body(String::from("Forbidden").into_bytes())
|
||||||
|
.map_err(From::from);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !asset.exists() {
|
if !asset.exists() {
|
||||||
return ResponseBuilder::new()
|
return Response::builder()
|
||||||
.status(StatusCode::NOT_FOUND)
|
.status(StatusCode::NOT_FOUND)
|
||||||
.body(String::from("Not Found").into_bytes());
|
.body(String::from("Not Found").into_bytes())
|
||||||
|
.map_err(From::from);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseBuilder::new()
|
Response::builder()
|
||||||
.mimetype(get_mime_from_path(trimmed)?)
|
.header("Content-Type", get_mime_from_path(trimmed)?)
|
||||||
.body(std::fs::read(asset)?)
|
.body(std::fs::read(asset)?)
|
||||||
|
.map_err(From::from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user