Skip to content

Commit 4cb51a2

Browse files
authored
refactor(core): custom protocol on Windows now uses the http scheme (#7779)
1 parent 974e38b commit 4cb51a2

File tree

25 files changed

+78
-45
lines changed

25 files changed

+78
-45
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 Windows now uses the `http` scheme instead of `https`.

core/tauri/scripts/core.js

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

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

2529
window.__TAURI__.transformCallback = function transformCallback(

core/tauri/src/manager.rs

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

508508
pub(crate) fn protocol_url(&self) -> Cow<'_, Url> {
509-
#[cfg(any(windows, target_os = "android"))]
510-
return Cow::Owned(Url::parse("https://tauri.localhost").unwrap());
511-
#[cfg(not(any(windows, target_os = "android")))]
512-
Cow::Owned(Url::parse("tauri://localhost").unwrap())
509+
if cfg!(windows) {
510+
Cow::Owned(Url::parse("http://tauri.localhost").unwrap())
511+
} else if cfg!(target_os = "android") {
512+
Cow::Owned(Url::parse("https://tauri.localhost").unwrap())
513+
} else {
514+
Cow::Owned(Url::parse("tauri://localhost").unwrap())
515+
}
513516
}
514517

515518
fn csp(&self) -> Option<Csp> {
@@ -612,6 +615,11 @@ impl<R: Runtime> WindowManager<R> {
612615
let window_origin = if window_url.scheme() == "data" {
613616
"null".into()
614617
} 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")
620+
&& window_url.scheme() != "http"
621+
&& window_url.scheme() != "https"
622+
{
615623
format!("https://{}.localhost", window_url.scheme())
616624
} else {
617625
format!(
@@ -876,6 +884,8 @@ mod test {
876884
assert_eq!(
877885
manager.get_url().to_string(),
878886
if cfg!(windows) {
887+
"http://tauri.localhost/"
888+
} else if cfg!(target_os = "android") {
879889
"https://tauri.localhost/"
880890
} else {
881891
"tauri://localhost"

core/tauri/src/pattern.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ pub(crate) struct PatternJavascript {
109109

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

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: 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 https://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: 3 additions & 3 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: https://ipc.localhost",
95+
"connect-src": "ipc: http://ipc.localhost https://ipc.localhost",
9696
"font-src": [
9797
"https://fonts.gstatic.com"
9898
],
99-
"img-src": "'self' asset: https://asset.localhost blob: data:",
99+
"img-src": "'self' asset: http://asset.localhost https://asset.localhost blob: data:",
100100
"style-src": "'unsafe-inline' 'self' https://fonts.googleapis.com"
101101
},
102102
"freezePrototype": true,
@@ -114,4 +114,4 @@
114114
}
115115
}
116116
}
117-
}
117+
}

examples/commands/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
}
5252
],
5353
"security": {
54-
"csp": "default-src 'self'; connect-src ipc: https://ipc.localhost"
54+
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost https://ipc.localhost"
5555
}
5656
}
5757
}

examples/helloworld/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
}
5151
],
5252
"security": {
53-
"csp": "default-src 'self'; connect-src ipc: https://ipc.localhost"
53+
"csp": "default-src 'self'; connect-src ipc: http://ipc.localhost https://ipc.localhost"
5454
}
5555
}
5656
}

examples/isolation/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
}
6161
],
6262
"security": {
63-
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'; connect-src ipc: https://ipc.localhost"
63+
"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"
6464
}
6565
}
6666
}

0 commit comments

Comments
 (0)