Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): allow custom protocol handler to resolve async #7754

Merged
merged 30 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f12862e
refactor(core): allow custom protocol handler to resolve async
lucasfernog Sep 5, 2023
c938971
sync channel
lucasfernog Sep 5, 2023
b6e5f8e
lint
lucasfernog Sep 5, 2023
e01901d
remove own http types
lucasfernog Sep 5, 2023
c878713
fix mut [skip ci]
lucasfernog Sep 6, 2023
9145da2
remove console.log [skip ci]
lucasfernog Sep 6, 2023
54657e8
Merge remote-tracking branch 'origin/refactor/custom-protocol-respons…
lucasfernog Sep 6, 2023
ac360c6
fix asset protocol usage
lucasfernog Sep 6, 2023
35912fb
fix channel usage
lucasfernog Sep 6, 2023
0c13903
update wry [skip ci]
lucasfernog Sep 6, 2023
0f936ba
add struct api instead of closure
lucasfernog Sep 6, 2023
bc004b0
custom protocol no longer return result
lucasfernog Sep 6, 2023
d934906
remove sync trait
lucasfernog Sep 6, 2023
7359295
lint
lucasfernog Sep 6, 2023
d446f59
fix linux
lucasfernog Sep 6, 2023
4e44125
fix ipc error [skip ci]
lucasfernog Sep 6, 2023
5fae60f
update wry
lucasfernog Sep 6, 2023
9abe4a1
Merge remote-tracking branch 'origin/refactor/custom-protocol-respons…
lucasfernog Sep 6, 2023
fd2f58c
wry 0.32
lucasfernog Sep 6, 2023
e32d521
rename responder
lucasfernog Sep 6, 2023
630fb45
lint
lucasfernog Sep 6, 2023
0a98f59
add separate api
lucasfernog Sep 6, 2023
8b56e7f
add missing change file
lucasfernog Sep 6, 2023
fc6a8ca
re-export http
lucasfernog Sep 6, 2023
c98eb84
change asset protocol signature to match others
lucasfernog Sep 6, 2023
6d9c53f
move isolation protocol
lucasfernog Sep 6, 2023
5ab7458
revert lint change
lucasfernog Sep 6, 2023
7c89f5d
add on_message change file
lucasfernog Sep 6, 2023
dbaf98d
license header
lucasfernog Sep 6, 2023
eaf0af9
Merge remote-tracking branch 'origin/dev' into refactor/custom-protoc…
lucasfernog Sep 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/custom-protocol-response-refactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:breaking
---

Changed `Builder::register_uri_scheme_protocol` to return a `http::Response` instead of `Result<http::Response>`. To return an error response, manually create a response with status code >= 400.
5 changes: 5 additions & 0 deletions .changes/fix-channel-data-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:bug
---

Fixes invalid header value type when requesting IPC body through a channel.
7 changes: 7 additions & 0 deletions .changes/http-types-refactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri": patch:breaking
"tauri-runtime": patch:breaking
"tauri-runtime-wry": patch:breaking
---

`tauri-runtime` no longer implements its own HTTP types and relies on the `http` crate instead.
5 changes: 5 additions & 0 deletions .changes/invoke-system-args.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:breaking
---

Changed `Builder::invoke_system` to take references instead of owned values.
5 changes: 5 additions & 0 deletions .changes/register_asynchronous_uri_scheme_protocol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:enhance
---

Added `Builder::register_asynchronous_uri_scheme_protocol` to allow resolving a custom URI scheme protocol request asynchronously to prevent blocking the main thread.
5 changes: 5 additions & 0 deletions .changes/runtime-custom-protocol-async.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-runtime": patch:enhance
---

Changed custom protocol closure type to enable asynchronous usage.
5 changes: 5 additions & 0 deletions .changes/window-on-message-refactor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch:breaking
---

Changed `Window::on_message` signature to take a responder closure instead of returning the response object in order to asynchronously process the request.
5 changes: 5 additions & 0 deletions .changes/wry-0.32.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-runtime-wry": patch:enhance
---

Update wry to 0.32 to include asynchronous custom protocol support.
3 changes: 2 additions & 1 deletion core/tauri-runtime-wry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ rust-version = { workspace = true }
features = [ "dox" ]

[dependencies]
wry = { version = "0.31", default-features = false, features = [ "file-drop", "protocol" ] }
wry = { version = "0.32", default-features = false, features = [ "tao", "file-drop", "protocol" ] }
tauri-runtime = { version = "1.0.0-alpha.0", path = "../tauri-runtime" }
tauri-utils = { version = "2.0.0-alpha.7", path = "../tauri-utils" }
uuid = { version = "1", features = [ "v4" ] }
rand = "0.8"
raw-window-handle = "0.5"
http = "0.2"

[target."cfg(windows)".dependencies]
webview2-com = "0.25"
Expand Down
48 changes: 7 additions & 41 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle};
use tauri_runtime::{
http::{header::CONTENT_TYPE, Request as HttpRequest, RequestParts, Response as HttpResponse},
monitor::Monitor,
webview::{WebviewIpcHandler, WindowBuilder, WindowBuilderBase},
window::{
Expand Down Expand Up @@ -61,7 +60,6 @@ use wry::{
UserAttentionType as WryUserAttentionType,
},
},
http::{Request as WryRequest, Response as WryResponse},
webview::{FileDropEvent as WryFileDropEvent, Url, WebContext, WebView, WebViewBuilder},
};

Expand All @@ -85,7 +83,6 @@ pub use wry::application::platform::macos::{
};

use std::{
borrow::Cow,
cell::RefCell,
collections::{
hash_map::Entry::{Occupied, Vacant},
Expand Down Expand Up @@ -259,39 +256,6 @@ impl<T: UserEvent> fmt::Debug for Context<T> {
}
}

struct HttpRequestWrapper(HttpRequest);

impl From<&WryRequest<Vec<u8>>> for HttpRequestWrapper {
fn from(req: &WryRequest<Vec<u8>>) -> Self {
let parts = RequestParts {
uri: req.uri().to_string(),
method: req.method().clone(),
headers: req.headers().clone(),
};
Self(HttpRequest::new_internal(parts, req.body().clone()))
}
}

// response
struct HttpResponseWrapper(WryResponse<Cow<'static, [u8]>>);
impl From<HttpResponse> for HttpResponseWrapper {
fn from(response: HttpResponse) -> Self {
let (parts, body) = response.into_parts();
let mut res_builder = WryResponse::builder()
.status(parts.status)
.version(parts.version);
if let Some(mime) = parts.mimetype {
res_builder = res_builder.header(CONTENT_TYPE, mime);
}
for (name, val) in parts.headers.iter() {
res_builder = res_builder.header(name, val);
}

let res = res_builder.body(body).unwrap();
Self(res)
}
}

pub struct DeviceEventFilterWrapper(pub WryDeviceEventFilter);

impl From<DeviceEventFilter> for DeviceEventFilterWrapper {
Expand Down Expand Up @@ -2701,11 +2665,13 @@ fn create_webview<T: UserEvent, F: Fn(RawWindow) + Send + 'static>(
}

for (scheme, protocol) in uri_scheme_protocols {
webview_builder = webview_builder.with_custom_protocol(scheme, move |wry_request| {
protocol(&HttpRequestWrapper::from(wry_request).0)
.map(|tauri_response| HttpResponseWrapper::from(tauri_response).0)
.map_err(|_| wry::Error::InitScriptError)
});
webview_builder =
webview_builder.with_asynchronous_custom_protocol(scheme, move |request, responder| {
protocol(
request,
Box::new(move |response| responder.respond(response)),
)
});
}

for script in webview_attributes.initialization_scripts {
Expand Down
1 change: 0 additions & 1 deletion core/tauri-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ thiserror = "1.0"
tauri-utils = { version = "2.0.0-alpha.7", path = "../tauri-utils" }
uuid = { version = "1", features = [ "v4" ] }
http = "0.2.4"
http-range = "0.1.4"
raw-window-handle = "0.5"
rand = "0.8"
url = { version = "2" }
Expand Down
20 changes: 0 additions & 20 deletions core/tauri-runtime/src/http/mod.rs

This file was deleted.

132 changes: 0 additions & 132 deletions core/tauri-runtime/src/http/request.rs

This file was deleted.

Loading
Loading