|
@@ -25,10 +25,9 @@ use tauri_utils::{
|
|
|
html::{SCRIPT_NONCE_TOKEN, STYLE_NONCE_TOKEN},
|
|
|
};
|
|
|
|
|
|
-use crate::hooks::IpcJavascript;
|
|
|
#[cfg(feature = "isolation")]
|
|
|
use crate::hooks::IsolationJavascript;
|
|
|
-use crate::pattern::{format_real_schema, PatternJavascript};
|
|
|
+use crate::pattern::PatternJavascript;
|
|
|
use crate::{
|
|
|
app::{AppHandle, GlobalWindowEvent, GlobalWindowEventListener},
|
|
|
event::{assert_event_name_is_valid, Event, EventHandler, Listeners},
|
|
@@ -54,6 +53,7 @@ use crate::{
|
|
|
app::{GlobalMenuEventListener, WindowMenuEvent},
|
|
|
window::WebResourceRequestHandler,
|
|
|
};
|
|
|
+use crate::{hooks::IpcJavascript, pattern::format_real_schema};
|
|
|
|
|
|
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
|
|
use crate::api::path::{resolve_path, BaseDirectory};
|
|
@@ -136,7 +136,7 @@ fn set_csp<R: Runtime>(
|
|
|
let default_src = csp
|
|
|
.entry("default-src".into())
|
|
|
.or_insert_with(Default::default);
|
|
|
- default_src.push(format_real_schema(schema));
|
|
|
+ default_src.push(crate::pattern::format_real_schema(schema));
|
|
|
}
|
|
|
|
|
|
Csp::DirectiveMap(csp).to_string()
|
|
@@ -225,7 +225,7 @@ pub struct InnerWindowManager<R: Runtime> {
|
|
|
/// The script that initializes the invoke system.
|
|
|
invoke_initialization_script: String,
|
|
|
/// Application pattern.
|
|
|
- pattern: Pattern,
|
|
|
+ pub(crate) pattern: Pattern,
|
|
|
}
|
|
|
|
|
|
impl<R: Runtime> fmt::Debug for InnerWindowManager<R> {
|
|
@@ -357,9 +357,12 @@ impl<R: Runtime> WindowManager<R> {
|
|
|
/// Get the base URL to use for webview requests.
|
|
|
///
|
|
|
/// In dev mode, this will be based on the `devPath` configuration value.
|
|
|
- fn get_url(&self) -> Cow<'_, Url> {
|
|
|
+ pub(crate) fn get_url(&self) -> Cow<'_, Url> {
|
|
|
match self.base_path() {
|
|
|
AppUrl::Url(WindowUrl::External(url)) => Cow::Borrowed(url),
|
|
|
+ #[cfg(windows)]
|
|
|
+ _ => Cow::Owned(Url::parse("https://tauri.localhost").unwrap()),
|
|
|
+ #[cfg(not(windows))]
|
|
|
_ => Cow::Owned(Url::parse("tauri://localhost").unwrap()),
|
|
|
}
|
|
|
}
|
|
@@ -467,7 +470,7 @@ impl<R: Runtime> WindowManager<R> {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- let window_url = Url::parse(&pending.url).unwrap();
|
|
|
+ let window_url = pending.current_url.lock().unwrap().clone();
|
|
|
let window_origin =
|
|
|
if cfg!(windows) && window_url.scheme() != "http" && window_url.scheme() != "https" {
|
|
|
format!("https://{}.localhost", window_url.scheme())
|
|
@@ -1001,7 +1004,16 @@ mod test {
|
|
|
);
|
|
|
|
|
|
#[cfg(custom_protocol)]
|
|
|
- assert_eq!(manager.get_url().to_string(), "tauri://localhost");
|
|
|
+ {
|
|
|
+ assert_eq!(
|
|
|
+ manager.get_url().to_string(),
|
|
|
+ if cfg!(windows) {
|
|
|
+ "https://tauri.localhost/"
|
|
|
+ } else {
|
|
|
+ "tauri://localhost"
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
#[cfg(dev)]
|
|
|
assert_eq!(manager.get_url().to_string(), "http://localhost:4000/");
|
|
@@ -1052,27 +1064,21 @@ impl<R: Runtime> WindowManager<R> {
|
|
|
return Err(crate::Error::WindowLabelAlreadyExists(pending.label));
|
|
|
}
|
|
|
#[allow(unused_mut)] // mut url only for the data-url parsing
|
|
|
- let (is_local, mut url) = match &pending.webview_attributes.url {
|
|
|
+ let mut url = match &pending.webview_attributes.url {
|
|
|
WindowUrl::App(path) => {
|
|
|
let url = self.get_url();
|
|
|
- (
|
|
|
- true,
|
|
|
- // ignore "index.html" just to simplify the url
|
|
|
- if path.to_str() != Some("index.html") {
|
|
|
- url
|
|
|
- .join(&*path.to_string_lossy())
|
|
|
- .map_err(crate::Error::InvalidUrl)
|
|
|
- // this will never fail
|
|
|
- .unwrap()
|
|
|
- } else {
|
|
|
- url.into_owned()
|
|
|
- },
|
|
|
- )
|
|
|
- }
|
|
|
- WindowUrl::External(url) => {
|
|
|
- let config_url = self.get_url();
|
|
|
- (config_url.make_relative(url).is_some(), url.clone())
|
|
|
+ // ignore "index.html" just to simplify the url
|
|
|
+ if path.to_str() != Some("index.html") {
|
|
|
+ url
|
|
|
+ .join(&*path.to_string_lossy())
|
|
|
+ .map_err(crate::Error::InvalidUrl)
|
|
|
+ // this will never fail
|
|
|
+ .unwrap()
|
|
|
+ } else {
|
|
|
+ url.into_owned()
|
|
|
+ }
|
|
|
}
|
|
|
+ WindowUrl::External(url) => url.clone(),
|
|
|
_ => unimplemented!(),
|
|
|
};
|
|
|
|
|
@@ -1099,7 +1105,7 @@ impl<R: Runtime> WindowManager<R> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- pending.url = url.to_string();
|
|
|
+ *pending.current_url.lock().unwrap() = url;
|
|
|
|
|
|
if !pending.window_builder.has_icon() {
|
|
|
if let Some(default_window_icon) = self.inner.default_window_icon.clone() {
|
|
@@ -1115,17 +1121,15 @@ impl<R: Runtime> WindowManager<R> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if is_local {
|
|
|
- let label = pending.label.clone();
|
|
|
- pending = self.prepare_pending_window(
|
|
|
- pending,
|
|
|
- &label,
|
|
|
- window_labels,
|
|
|
- app_handle.clone(),
|
|
|
- web_resource_request_handler,
|
|
|
- )?;
|
|
|
- pending.ipc_handler = Some(self.prepare_ipc_handler(app_handle));
|
|
|
- }
|
|
|
+ let label = pending.label.clone();
|
|
|
+ pending = self.prepare_pending_window(
|
|
|
+ pending,
|
|
|
+ &label,
|
|
|
+ window_labels,
|
|
|
+ app_handle.clone(),
|
|
|
+ web_resource_request_handler,
|
|
|
+ )?;
|
|
|
+ pending.ipc_handler = Some(self.prepare_ipc_handler(app_handle));
|
|
|
|
|
|
// in `Windows`, we need to force a data_directory
|
|
|
// but we do respect user-specification
|
|
@@ -1150,6 +1154,17 @@ impl<R: Runtime> WindowManager<R> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ let current_url_ = pending.current_url.clone();
|
|
|
+ let navigation_handler = pending.navigation_handler.take();
|
|
|
+ pending.navigation_handler = Some(Box::new(move |url| {
|
|
|
+ *current_url_.lock().unwrap() = url.clone();
|
|
|
+ if let Some(handler) = &navigation_handler {
|
|
|
+ handler(url)
|
|
|
+ } else {
|
|
|
+ true
|
|
|
+ }
|
|
|
+ }));
|
|
|
+
|
|
|
Ok(pending)
|
|
|
}
|
|
|
|