mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-03 10:11:15 +02:00
* fix(core): Fix `WindowBuilder::on_navigation` handler never registerd, closes #6865 * clippy
This commit is contained in:
5
.changes/core-navigation-handler.md
Normal file
5
.changes/core-navigation-handler.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'tauri': 'patch'
|
||||
---
|
||||
|
||||
Fix `WindowBuilder::on_navigation` handler not registered properly.
|
||||
@@ -24,6 +24,8 @@ use std::{
|
||||
type UriSchemeProtocol =
|
||||
dyn Fn(&HttpRequest) -> Result<HttpResponse, Box<dyn std::error::Error>> + Send + Sync + 'static;
|
||||
|
||||
type WebResourceRequestHandler = dyn Fn(&HttpRequest, &mut HttpResponse) + Send + Sync;
|
||||
|
||||
/// UI scaling utilities.
|
||||
pub mod dpi;
|
||||
|
||||
@@ -234,6 +236,8 @@ pub struct PendingWindow<T: UserEvent, R: Runtime<T>> {
|
||||
/// A handler to decide if incoming url is allowed to navigate.
|
||||
pub navigation_handler: Option<Box<dyn Fn(Url) -> bool + Send>>,
|
||||
|
||||
pub web_resource_request_handler: Option<Box<WebResourceRequestHandler>>,
|
||||
|
||||
/// The current webview URL.
|
||||
pub current_url: Arc<Mutex<Url>>,
|
||||
}
|
||||
@@ -275,6 +279,7 @@ impl<T: UserEvent, R: Runtime<T>> PendingWindow<T, R> {
|
||||
menu_ids: Arc::new(Mutex::new(menu_ids)),
|
||||
js_event_listeners: Default::default(),
|
||||
navigation_handler: Default::default(),
|
||||
web_resource_request_handler: Default::default(),
|
||||
current_url: Arc::new(Mutex::new("tauri://localhost".parse().unwrap())),
|
||||
})
|
||||
}
|
||||
@@ -305,6 +310,7 @@ impl<T: UserEvent, R: Runtime<T>> PendingWindow<T, R> {
|
||||
menu_ids: Arc::new(Mutex::new(menu_ids)),
|
||||
js_event_listeners: Default::default(),
|
||||
navigation_handler: Default::default(),
|
||||
web_resource_request_handler: Default::default(),
|
||||
current_url: Arc::new(Mutex::new("tauri://localhost".parse().unwrap())),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1705,10 +1705,9 @@ impl<R: Runtime> Builder<R> {
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for pending in self.pending_windows {
|
||||
let pending =
|
||||
app
|
||||
.manager
|
||||
.prepare_window(app.handle.clone(), pending, &window_labels, None)?;
|
||||
let pending = app
|
||||
.manager
|
||||
.prepare_window(app.handle.clone(), pending, &window_labels)?;
|
||||
let detached = app.runtime.as_ref().unwrap().create_window(pending)?;
|
||||
let _window = app.manager.attach_window(app.handle(), detached);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ use tauri_utils::{
|
||||
html::{SCRIPT_NONCE_TOKEN, STYLE_NONCE_TOKEN},
|
||||
};
|
||||
|
||||
use crate::app::{GlobalMenuEventListener, WindowMenuEvent};
|
||||
use crate::hooks::IpcJavascript;
|
||||
#[cfg(feature = "isolation")]
|
||||
use crate::hooks::IsolationJavascript;
|
||||
@@ -50,10 +51,6 @@ use crate::{
|
||||
Context, EventLoopMessage, Icon, Invoke, Manager, Pattern, Runtime, Scopes, StateManager, Window,
|
||||
WindowEvent,
|
||||
};
|
||||
use crate::{
|
||||
app::{GlobalMenuEventListener, WindowMenuEvent},
|
||||
window::WebResourceRequestHandler,
|
||||
};
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||
use crate::api::path::{resolve_path, BaseDirectory};
|
||||
@@ -401,7 +398,6 @@ impl<R: Runtime> WindowManager<R> {
|
||||
label: &str,
|
||||
window_labels: &[String],
|
||||
app_handle: AppHandle<R>,
|
||||
web_resource_request_handler: Option<Box<WebResourceRequestHandler>>,
|
||||
) -> crate::Result<PendingWindow<EventLoopMessage, R>> {
|
||||
let is_init_global = self.inner.config.build.with_global_tauri;
|
||||
let plugin_init = self
|
||||
@@ -492,6 +488,7 @@ impl<R: Runtime> WindowManager<R> {
|
||||
};
|
||||
|
||||
if !registered_scheme_protocols.contains(&"tauri".into()) {
|
||||
let web_resource_request_handler = pending.web_resource_request_handler.take();
|
||||
pending.register_uri_scheme_protocol(
|
||||
"tauri",
|
||||
self.prepare_uri_scheme_protocol(&window_origin, web_resource_request_handler),
|
||||
@@ -1122,7 +1119,6 @@ impl<R: Runtime> WindowManager<R> {
|
||||
app_handle: AppHandle<R>,
|
||||
mut pending: PendingWindow<EventLoopMessage, R>,
|
||||
window_labels: &[String],
|
||||
web_resource_request_handler: Option<Box<WebResourceRequestHandler>>,
|
||||
) -> crate::Result<PendingWindow<EventLoopMessage, R>> {
|
||||
if self.windows_lock().contains_key(&pending.label) {
|
||||
return Err(crate::Error::WindowLabelAlreadyExists(pending.label));
|
||||
@@ -1186,13 +1182,7 @@ impl<R: Runtime> WindowManager<R> {
|
||||
}
|
||||
|
||||
let label = pending.label.clone();
|
||||
pending = self.prepare_pending_window(
|
||||
pending,
|
||||
&label,
|
||||
window_labels,
|
||||
app_handle.clone(),
|
||||
web_resource_request_handler,
|
||||
)?;
|
||||
pending = self.prepare_pending_window(pending, &label, window_labels, app_handle.clone())?;
|
||||
pending.ipc_handler = Some(self.prepare_ipc_handler(app_handle));
|
||||
|
||||
// in `Windows`, we need to force a data_directory
|
||||
|
||||
@@ -310,19 +310,18 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
|
||||
|
||||
/// Creates a new webview window.
|
||||
pub fn build(mut self) -> crate::Result<Window<R>> {
|
||||
let web_resource_request_handler = self.web_resource_request_handler.take();
|
||||
let pending = PendingWindow::new(
|
||||
let mut pending = PendingWindow::new(
|
||||
self.window_builder.clone(),
|
||||
self.webview_attributes.clone(),
|
||||
self.label.clone(),
|
||||
)?;
|
||||
pending.navigation_handler = self.navigation_handler.take();
|
||||
pending.web_resource_request_handler = self.web_resource_request_handler.take();
|
||||
|
||||
let labels = self.manager.labels().into_iter().collect::<Vec<_>>();
|
||||
let pending = self.manager.prepare_window(
|
||||
self.app_handle.clone(),
|
||||
pending,
|
||||
&labels,
|
||||
web_resource_request_handler,
|
||||
)?;
|
||||
let pending = self
|
||||
.manager
|
||||
.prepare_window(self.app_handle.clone(), pending, &labels)?;
|
||||
|
||||
let window = match &mut self.runtime {
|
||||
RuntimeOrDispatch::Runtime(runtime) => runtime.create_window(pending),
|
||||
|
||||
Reference in New Issue
Block a user