Skip to content

Commit d5074af

Browse files
authored
fix: custom protocol on Windows, change scheme on Android, closes #7801 (#7808)
1 parent 822ba2b commit d5074af

File tree

28 files changed

+56
-58
lines changed

28 files changed

+56
-58
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"tauri": patch:breaking
3+
"@tauri-apps/api": patch:breaking
4+
"@tauri-apps/cli": patch:breaking
5+
"tauri-cli": patch:breaking
6+
---
7+
8+
The custom protocol on Android now uses the `http` scheme instead of `https`.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": patch:bug
3+
"tauri-runtime-wry": patch:bug
4+
---
5+
6+
Fixes custom protocol not working on Windows.

core/tauri-runtime-wry/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ rust-version = { workspace = true }
1616
features = [ "dox" ]
1717

1818
[dependencies]
19-
wry = { version = "0.32", default-features = false, features = [ "tao", "file-drop", "protocol" ] }
19+
wry = { version = "0.33", default-features = false, features = [ "tao", "file-drop", "protocol" ] }
2020
tauri-runtime = { version = "1.0.0-alpha.1", path = "../tauri-runtime" }
2121
tauri-utils = { version = "2.0.0-alpha.7", path = "../tauri-utils" }
2222
uuid = { version = "1", features = [ "v4" ] }

core/tauri/scripts/core.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@
1717

1818
window.__TAURI__.convertFileSrc = function convertFileSrc(filePath, protocol = 'asset') {
1919
const path = encodeURIComponent(filePath)
20-
return osName === 'windows'
20+
return osName === 'windows' || osName === 'android'
2121
? `http://${protocol}.localhost/${path}`
22-
: (
23-
osName === 'android'
24-
? `https://${protocol}.localhost/${path}`
25-
: `${protocol}://localhost/${path}`
26-
)
22+
: `${protocol}://localhost/${path}`
2723
}
2824

2925
window.__TAURI__.transformCallback = function transformCallback(

core/tauri/src/ipc/protocol.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ fn handle_ipc_message<R: Runtime>(message: String, manager: &WindowManager<R>, l
244244
if !(cfg!(target_os = "macos") || cfg!(target_os = "ios"))
245245
&& matches!(v, JsonValue::Object(_) | JsonValue::Array(_))
246246
{
247-
let _ = Channel::from_ipc(window.clone(), callback).send(v);
247+
let _ = Channel::from_ipc(window, callback).send(v);
248248
} else {
249249
responder_eval(
250250
&window,
@@ -261,8 +261,7 @@ fn handle_ipc_message<R: Runtime>(message: String, manager: &WindowManager<R>, l
261261
error,
262262
);
263263
} else {
264-
let _ =
265-
Channel::from_ipc(window.clone(), callback).send(InvokeBody::Raw(v.clone()));
264+
let _ = Channel::from_ipc(window, callback).send(InvokeBody::Raw(v.clone()));
266265
}
267266
}
268267
InvokeResponse::Err(e) => responder_eval(

core/tauri/src/manager.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,8 @@ impl<R: Runtime> WindowManager<R> {
506506
}
507507

508508
pub(crate) fn protocol_url(&self) -> Cow<'_, Url> {
509-
if cfg!(windows) {
509+
if cfg!(windows) || cfg!(target_os = "android") {
510510
Cow::Owned(Url::parse("http://tauri.localhost").unwrap())
511-
} else if cfg!(target_os = "android") {
512-
Cow::Owned(Url::parse("https://tauri.localhost").unwrap())
513511
} else {
514512
Cow::Owned(Url::parse("tauri://localhost").unwrap())
515513
}
@@ -614,13 +612,11 @@ impl<R: Runtime> WindowManager<R> {
614612
let window_url = Url::parse(&pending.url).unwrap();
615613
let window_origin = if window_url.scheme() == "data" {
616614
"null".into()
617-
} else if cfg!(windows) && window_url.scheme() != "http" && window_url.scheme() != "https" {
618-
format!("http://{}.localhost", window_url.scheme())
619-
} else if cfg!(target_os = "android")
615+
} else if (cfg!(windows) || cfg!(target_os = "android"))
620616
&& window_url.scheme() != "http"
621617
&& window_url.scheme() != "https"
622618
{
623-
format!("https://{}.localhost", window_url.scheme())
619+
format!("http://{}.localhost", window_url.scheme())
624620
} else {
625621
format!(
626622
"{}://{}{}",
@@ -883,10 +879,8 @@ mod test {
883879
{
884880
assert_eq!(
885881
manager.get_url().to_string(),
886-
if cfg!(windows) {
882+
if cfg!(windows) || cfg!(target_os = "android") {
887883
"http://tauri.localhost/"
888-
} else if cfg!(target_os = "android") {
889-
"https://tauri.localhost/"
890884
} else {
891885
"tauri://localhost"
892886
}

core/tauri/src/pattern.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,8 @@ pub(crate) struct PatternJavascript {
109109

110110
#[allow(dead_code)]
111111
pub(crate) fn format_real_schema(schema: &str) -> String {
112-
if cfg!(windows) {
112+
if cfg!(windows) || cfg!(target_os = "android") {
113113
format!("http://{schema}.{ISOLATION_IFRAME_SRC_DOMAIN}")
114-
} else if cfg!(target_os = "android") {
115-
format!("https://{schema}.{ISOLATION_IFRAME_SRC_DOMAIN}")
116114
} else {
117115
format!("{schema}://{ISOLATION_IFRAME_SRC_DOMAIN}")
118116
}

core/tauri/test/fixture/src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
],
1717
"security": {
18-
"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"
18+
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self'; connect-src ipc: http://ipc.localhost"
1919
}
2020
}
2121
}

examples/api/src-tauri/Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/api/src-tauri/tauri.conf.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@
9292
"security": {
9393
"csp": {
9494
"default-src": "'self' customprotocol: asset:",
95-
"connect-src": "ipc: http://ipc.localhost https://ipc.localhost",
95+
"connect-src": "ipc: http://ipc.localhost",
9696
"font-src": [
9797
"https://fonts.gstatic.com"
9898
],
99-
"img-src": "'self' asset: http://asset.localhost https://asset.localhost blob: data:",
99+
"img-src": "'self' asset: http://asset.localhost blob: data:",
100100
"style-src": "'unsafe-inline' 'self' https://fonts.googleapis.com"
101101
},
102102
"freezePrototype": true,

0 commit comments

Comments
 (0)