mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-12-24 03:04:36 +03:00
This commit is contained in:
parent
822ba2b121
commit
d5074af562
8
.changes/custom-protocol-http-android.md
Normal file
8
.changes/custom-protocol-http-android.md
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
"tauri": patch:breaking
|
||||
"@tauri-apps/api": patch:breaking
|
||||
"@tauri-apps/cli": patch:breaking
|
||||
"tauri-cli": patch:breaking
|
||||
---
|
||||
|
||||
The custom protocol on Android now uses the `http` scheme instead of `https`.
|
6
.changes/fix-windows-custom-protocol.md
Normal file
6
.changes/fix-windows-custom-protocol.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"tauri": patch:bug
|
||||
"tauri-runtime-wry": patch:bug
|
||||
---
|
||||
|
||||
Fixes custom protocol not working on Windows.
|
@ -16,7 +16,7 @@ rust-version = { workspace = true }
|
||||
features = [ "dox" ]
|
||||
|
||||
[dependencies]
|
||||
wry = { version = "0.32", default-features = false, features = [ "tao", "file-drop", "protocol" ] }
|
||||
wry = { version = "0.33", default-features = false, features = [ "tao", "file-drop", "protocol" ] }
|
||||
tauri-runtime = { version = "1.0.0-alpha.1", path = "../tauri-runtime" }
|
||||
tauri-utils = { version = "2.0.0-alpha.7", path = "../tauri-utils" }
|
||||
uuid = { version = "1", features = [ "v4" ] }
|
||||
|
@ -17,13 +17,9 @@
|
||||
|
||||
window.__TAURI__.convertFileSrc = function convertFileSrc(filePath, protocol = 'asset') {
|
||||
const path = encodeURIComponent(filePath)
|
||||
return osName === 'windows'
|
||||
return osName === 'windows' || osName === 'android'
|
||||
? `http://${protocol}.localhost/${path}`
|
||||
: (
|
||||
osName === 'android'
|
||||
? `https://${protocol}.localhost/${path}`
|
||||
: `${protocol}://localhost/${path}`
|
||||
)
|
||||
: `${protocol}://localhost/${path}`
|
||||
}
|
||||
|
||||
window.__TAURI__.transformCallback = function transformCallback(
|
||||
|
@ -244,7 +244,7 @@ fn handle_ipc_message<R: Runtime>(message: String, manager: &WindowManager<R>, l
|
||||
if !(cfg!(target_os = "macos") || cfg!(target_os = "ios"))
|
||||
&& matches!(v, JsonValue::Object(_) | JsonValue::Array(_))
|
||||
{
|
||||
let _ = Channel::from_ipc(window.clone(), callback).send(v);
|
||||
let _ = Channel::from_ipc(window, callback).send(v);
|
||||
} else {
|
||||
responder_eval(
|
||||
&window,
|
||||
@ -261,8 +261,7 @@ fn handle_ipc_message<R: Runtime>(message: String, manager: &WindowManager<R>, l
|
||||
error,
|
||||
);
|
||||
} else {
|
||||
let _ =
|
||||
Channel::from_ipc(window.clone(), callback).send(InvokeBody::Raw(v.clone()));
|
||||
let _ = Channel::from_ipc(window, callback).send(InvokeBody::Raw(v.clone()));
|
||||
}
|
||||
}
|
||||
InvokeResponse::Err(e) => responder_eval(
|
||||
|
@ -506,10 +506,8 @@ impl<R: Runtime> WindowManager<R> {
|
||||
}
|
||||
|
||||
pub(crate) fn protocol_url(&self) -> Cow<'_, Url> {
|
||||
if cfg!(windows) {
|
||||
if cfg!(windows) || cfg!(target_os = "android") {
|
||||
Cow::Owned(Url::parse("http://tauri.localhost").unwrap())
|
||||
} else if cfg!(target_os = "android") {
|
||||
Cow::Owned(Url::parse("https://tauri.localhost").unwrap())
|
||||
} else {
|
||||
Cow::Owned(Url::parse("tauri://localhost").unwrap())
|
||||
}
|
||||
@ -614,13 +612,11 @@ impl<R: Runtime> WindowManager<R> {
|
||||
let window_url = Url::parse(&pending.url).unwrap();
|
||||
let window_origin = if window_url.scheme() == "data" {
|
||||
"null".into()
|
||||
} else if cfg!(windows) && window_url.scheme() != "http" && window_url.scheme() != "https" {
|
||||
format!("http://{}.localhost", window_url.scheme())
|
||||
} else if cfg!(target_os = "android")
|
||||
} else if (cfg!(windows) || cfg!(target_os = "android"))
|
||||
&& window_url.scheme() != "http"
|
||||
&& window_url.scheme() != "https"
|
||||
{
|
||||
format!("https://{}.localhost", window_url.scheme())
|
||||
format!("http://{}.localhost", window_url.scheme())
|
||||
} else {
|
||||
format!(
|
||||
"{}://{}{}",
|
||||
@ -883,10 +879,8 @@ mod test {
|
||||
{
|
||||
assert_eq!(
|
||||
manager.get_url().to_string(),
|
||||
if cfg!(windows) {
|
||||
if cfg!(windows) || cfg!(target_os = "android") {
|
||||
"http://tauri.localhost/"
|
||||
} else if cfg!(target_os = "android") {
|
||||
"https://tauri.localhost/"
|
||||
} else {
|
||||
"tauri://localhost"
|
||||
}
|
||||
|
@ -109,10 +109,8 @@ pub(crate) struct PatternJavascript {
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn format_real_schema(schema: &str) -> String {
|
||||
if cfg!(windows) {
|
||||
if cfg!(windows) || cfg!(target_os = "android") {
|
||||
format!("http://{schema}.{ISOLATION_IFRAME_SRC_DOMAIN}")
|
||||
} else if cfg!(target_os = "android") {
|
||||
format!("https://{schema}.{ISOLATION_IFRAME_SRC_DOMAIN}")
|
||||
} else {
|
||||
format!("{schema}://{ISOLATION_IFRAME_SRC_DOMAIN}")
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'; connect-src ipc: http://ipc.localhost https://ipc.localhost"
|
||||
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'; connect-src ipc: http://ipc.localhost"
|
||||
}
|
||||
}
|
||||
}
|
6
examples/api/src-tauri/Cargo.lock
generated
6
examples/api/src-tauri/Cargo.lock
generated
@ -3399,7 +3399,7 @@ checksum = "9d0e916b1148c8e263850e1ebcbd046f333e0683c724876bb0da63ea4373dc8a"
|
||||
|
||||
[[package]]
|
||||
name = "tauri"
|
||||
version = "2.0.0-alpha.12"
|
||||
version = "2.0.0-alpha.13"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
@ -4530,9 +4530,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wry"
|
||||
version = "0.32.0"
|
||||
version = "0.33.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41fc00d1511c9ff5b600a6c6bde254eb39b9fcc5c0369b71a8efd5ff807bf937"
|
||||
checksum = "bf906b43b8042615c85a978dceb4d4b72214d27b850b54abc3edeb7c5a67abab"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"block",
|
||||
|
@ -92,11 +92,11 @@
|
||||
"security": {
|
||||
"csp": {
|
||||
"default-src": "'self' customprotocol: asset:",
|
||||
"connect-src": "ipc: http://ipc.localhost https://ipc.localhost",
|
||||
"connect-src": "ipc: http://ipc.localhost",
|
||||
"font-src": [
|
||||
"https://fonts.gstatic.com"
|
||||
],
|
||||
"img-src": "'self' asset: http://asset.localhost https://asset.localhost blob: data:",
|
||||
"img-src": "'self' asset: http://asset.localhost blob: data:",
|
||||
"style-src": "'unsafe-inline' 'self' https://fonts.googleapis.com"
|
||||
},
|
||||
"freezePrototype": true,
|
||||
|
@ -51,7 +51,7 @@
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost https://ipc.localhost"
|
||||
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost"
|
||||
}
|
||||
}
|
||||
}
|
@ -50,7 +50,7 @@
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost https://ipc.localhost"
|
||||
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost"
|
||||
}
|
||||
}
|
||||
}
|
@ -60,7 +60,7 @@
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'; connect-src ipc: http://ipc.localhost https://ipc.localhost"
|
||||
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'; connect-src ipc: http://ipc.localhost"
|
||||
}
|
||||
}
|
||||
}
|
@ -47,7 +47,7 @@
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost https://ipc.localhost"
|
||||
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost"
|
||||
}
|
||||
}
|
||||
}
|
@ -47,7 +47,7 @@
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost https://ipc.localhost"
|
||||
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost"
|
||||
}
|
||||
}
|
||||
}
|
@ -31,7 +31,7 @@
|
||||
"category": "DeveloperTool"
|
||||
},
|
||||
"security": {
|
||||
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost https://ipc.localhost"
|
||||
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost"
|
||||
}
|
||||
}
|
||||
}
|
@ -53,7 +53,7 @@
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost https://ipc.localhost"
|
||||
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost"
|
||||
}
|
||||
}
|
||||
}
|
@ -44,7 +44,7 @@
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost https://ipc.localhost"
|
||||
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost"
|
||||
}
|
||||
}
|
||||
}
|
@ -51,7 +51,7 @@
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost https://ipc.localhost"
|
||||
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost"
|
||||
}
|
||||
}
|
||||
}
|
@ -51,7 +51,7 @@
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src 'self' ipc:; media-src stream: http://stream.localhost https://stream.localhost asset: http://asset.localhost https://asset.localhost",
|
||||
"csp": "default-src 'self' ipc:; media-src stream: http://stream.localhost asset: http://asset.localhost",
|
||||
"assetProtocol": {
|
||||
"scope": [
|
||||
"**/test_video.mp4"
|
||||
|
@ -50,7 +50,7 @@
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'; connect-src ipc: http://ipc.localhost https://ipc.localhost"
|
||||
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'; connect-src ipc: http://ipc.localhost"
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -181,8 +181,8 @@ async function invoke<T>(
|
||||
|
||||
/**
|
||||
* Convert a device file path to an URL that can be loaded by the webview.
|
||||
* Note that `asset:`, `http://asset.localhost` and `https://asset.localhost` must be added to [`tauri.security.csp`](https://tauri.app/v1/api/config/#securityconfig.csp) in `tauri.conf.json`.
|
||||
* Example CSP value: `"csp": "default-src 'self' ipc: http://ipc.localhost https://ipc.localhost; img-src 'self' asset: http://asset.localhost https://asset.localhost"` to use the asset protocol on image sources.
|
||||
* Note that `asset:` and `http://asset.localhost` must be added to [`tauri.security.csp`](https://tauri.app/v1/api/config/#securityconfig.csp) in `tauri.conf.json`.
|
||||
* Example CSP value: `"csp": "default-src 'self' ipc: http://ipc.localhost; img-src 'self' asset: http://asset.localhost"` to use the asset protocol on image sources.
|
||||
*
|
||||
* Additionally, `asset` must be added to [`tauri.allowlist.protocol`](https://tauri.app/v1/api/config/#allowlistconfig.protocol)
|
||||
* in `tauri.conf.json` and its access scope must be defined on the `assetScope` array on the same `protocol` object.
|
||||
|
@ -43,7 +43,7 @@
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'; connect-src ipc: http://ipc.localhost https://ipc.localhost"
|
||||
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'; connect-src ipc: http://ipc.localhost"
|
||||
}
|
||||
}
|
||||
}
|
@ -43,7 +43,7 @@
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'; connect-src ipc: http://ipc.localhost https://ipc.localhost"
|
||||
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'; connect-src ipc: http://ipc.localhost"
|
||||
}
|
||||
}
|
||||
}
|
@ -43,7 +43,7 @@
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'; connect-src ipc: http://ipc.localhost https://ipc.localhost"
|
||||
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'; connect-src ipc: http://ipc.localhost"
|
||||
}
|
||||
}
|
||||
}
|
@ -85,24 +85,21 @@ fn process_security(security: &mut Map<String, Value>) -> Result<()> {
|
||||
match &mut csp {
|
||||
tauri_utils_v1::config::Csp::Policy(csp) => {
|
||||
if csp.contains("connect-src") {
|
||||
*csp = csp.replace(
|
||||
"connect-src",
|
||||
"connect-src ipc: http://ipc.localhost https://ipc.localhost",
|
||||
);
|
||||
*csp = csp.replace("connect-src", "connect-src ipc: http://ipc.localhost");
|
||||
} else {
|
||||
*csp = format!("{csp}; connect-src ipc: http://ipc.localhost https://ipc.localhost");
|
||||
*csp = format!("{csp}; connect-src ipc: http://ipc.localhost");
|
||||
}
|
||||
}
|
||||
tauri_utils_v1::config::Csp::DirectiveMap(csp) => {
|
||||
if let Some(connect_src) = csp.get_mut("connect-src") {
|
||||
if !connect_src.contains("ipc: http://ipc.localhost https://ipc.localhost") {
|
||||
connect_src.push("ipc: http://ipc.localhost https://ipc.localhost");
|
||||
if !connect_src.contains("ipc: http://ipc.localhost") {
|
||||
connect_src.push("ipc: http://ipc.localhost");
|
||||
}
|
||||
} else {
|
||||
csp.insert(
|
||||
"connect-src".into(),
|
||||
tauri_utils_v1::config::CspDirectiveSources::List(vec![
|
||||
"ipc: http://ipc.localhost https://ipc.localhost".to_string(),
|
||||
"ipc: http://ipc.localhost".to_string()
|
||||
]),
|
||||
);
|
||||
}
|
||||
@ -334,7 +331,7 @@ mod test {
|
||||
assert_eq!(
|
||||
migrated["tauri"]["security"]["csp"],
|
||||
format!(
|
||||
"{}; connect-src ipc: http://ipc.localhost https://ipc.localhost",
|
||||
"{}; connect-src ipc: http://ipc.localhost",
|
||||
original["tauri"]["security"]["csp"].as_str().unwrap()
|
||||
)
|
||||
);
|
||||
@ -361,7 +358,7 @@ mod test {
|
||||
assert!(migrated["tauri"]["security"]["csp"]["connect-src"]
|
||||
.as_array()
|
||||
.expect("connect-src isn't an array")
|
||||
.contains(&"ipc: http://ipc.localhost https://ipc.localhost".into()));
|
||||
.contains(&"ipc: http://ipc.localhost".into()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -388,7 +385,7 @@ mod test {
|
||||
.as_str()
|
||||
.expect("connect-src isn't a string"),
|
||||
format!(
|
||||
"{} ipc: http://ipc.localhost https://ipc.localhost",
|
||||
"{} ipc: http://ipc.localhost",
|
||||
original["tauri"]["security"]["csp"]["connect-src"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
|
@ -50,7 +50,7 @@
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'; connect-src ipc: http://ipc.localhost https://ipc.localhost"
|
||||
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'; connect-src ipc: http://ipc.localhost"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user