Просмотр исходного кода

fix: check if url local with platform custom protocol, closes #7176 (#7202)

* fix: check if url local with platform custom protocol, closes #7176

* Update core/tauri/src/window.rs
Amr Bashir 2 лет назад
Родитель
Сommit
0fa0fa4ccf
2 измененных файлов с 16 добавлено и 7 удалено
  1. 8 4
      core/tauri/src/manager.rs
  2. 8 3
      core/tauri/src/window.rs

+ 8 - 4
core/tauri/src/manager.rs

@@ -377,13 +377,17 @@ impl<R: Runtime> WindowManager<R> {
   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()),
+      _ => self.protocol_url(),
     }
   }
 
+  pub(crate) fn protocol_url(&self) -> Cow<'_, Url> {
+    #[cfg(any(window, target_os = "android"))]
+    return Cow::Owned(Url::parse("https://tauri.localhost").unwrap());
+    #[cfg(not(any(window, target_os = "android")))]
+    Cow::Owned(Url::parse("tauri://localhost").unwrap())
+  }
+
   fn csp(&self) -> Option<Csp> {
     if cfg!(feature = "custom-protocol") {
       self.inner.config.tauri.security.csp.clone()

+ 8 - 3
core/tauri/src/window.rs

@@ -1653,13 +1653,18 @@ impl<R: Runtime> Window<R> {
     self.current_url = url;
   }
 
+  fn is_local_url(&self, current_url: &Url) -> bool {
+    self.manager.get_url().make_relative(current_url).is_some() || {
+      let protocol_url = self.manager.protocol_url();
+      current_url.scheme() == protocol_url.scheme() && current_url.domain() == protocol_url.domain()
+    }
+  }
+
   /// Handles this window receiving an [`InvokeMessage`].
   pub fn on_message(self, payload: InvokePayload) -> crate::Result<()> {
     let manager = self.manager.clone();
     let current_url = self.url();
-    let config_url = manager.get_url();
-    let is_local =
-      config_url.make_relative(&current_url).is_some() || current_url.scheme() == "tauri";
+    let is_local = self.is_local_url(&current_url);
 
     let mut scope_not_found_error_message =
       ipc_scope_not_found_error_message(&self.window.label, current_url.as_str());