Browse Source

Make sure custom protocol is handled as secure context on macOS (#1551)

david 4 years ago
parent
commit
5909c1e014
2 changed files with 10 additions and 6 deletions
  1. 5 0
      .changes/macos-custom-protocol-https.md
  2. 5 6
      core/tauri/src/runtime/manager.rs

+ 5 - 0
.changes/macos-custom-protocol-https.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch
+---
+
+Make sure custom protocol is treated as secure content on macOS.

+ 5 - 6
core/tauri/src/runtime/manager.rs

@@ -133,13 +133,13 @@ impl<P: Params> WindowManager<P> {
     if self.inner.config.build.dev_path.starts_with("http") {
       self.inner.config.build.dev_path.clone()
     } else {
-      format!("tauri://{}", self.inner.config.tauri.bundle.identifier)
+      "tauri://localhost".into()
     }
   }
 
   #[cfg(custom_protocol)]
   fn get_url(&self) -> String {
-    format!("tauri://{}", self.inner.config.tauri.bundle.identifier)
+    "tauri://localhost".into()
   }
 
   fn prepare_attributes(
@@ -240,7 +240,6 @@ impl<P: Params> WindowManager<P> {
 
   fn prepare_custom_protocol(&self) -> CustomProtocol {
     let assets = self.inner.assets.clone();
-    let bundle_identifier = self.inner.config.tauri.bundle.identifier.clone();
     CustomProtocol {
       handler: Box::new(move |path| {
         let mut path = path
@@ -249,12 +248,12 @@ impl<P: Params> WindowManager<P> {
           .next()
           .unwrap()
           .to_string()
-          .replace(&format!("tauri://{}", bundle_identifier), "");
+          .replace("tauri://localhost", "");
         if path.ends_with('/') {
           path.pop();
         }
         let path = if path.is_empty() {
-          // if the url is `tauri://${appId}`, we should load `index.html`
+          // if the url is `tauri://localhost`, we should load `index.html`
           "index.html".to_string()
         } else {
           // skip leading `/`
@@ -385,7 +384,7 @@ mod test {
     );
 
     #[cfg(custom_protocol)]
-    assert_eq!(manager.get_url(), "tauri://studio.tauri.example");
+    assert_eq!(manager.get_url(), "tauri://localhost");
 
     #[cfg(dev)]
     assert_eq!(manager.get_url(), manager.config().build.dev_path);