From b7f53d66e8f9506ff4de8775aae9884d74abda44 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Wed, 6 Sep 2023 16:09:01 -0300 Subject: [PATCH] fix(core): use postMessage IPC for remote URLs on iOS ref #7751 (#7764) --- .changes/fix-ipc-remote-url-macos.md | 2 +- core/tauri/scripts/ipc-protocol.js | 2 +- core/tauri/src/ipc/mod.rs | 2 +- core/tauri/src/ipc/protocol.rs | 18 +++++++++--------- core/tauri/src/manager.rs | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.changes/fix-ipc-remote-url-macos.md b/.changes/fix-ipc-remote-url-macos.md index 915ebee4e..314ab2e29 100644 --- a/.changes/fix-ipc-remote-url-macos.md +++ b/.changes/fix-ipc-remote-url-macos.md @@ -2,4 +2,4 @@ "tauri": patch:bug --- -Fixes IPC failing to communicate for remote URLs on macOS. +Fixes IPC failing to communicate for remote URLs on macOS and iOS. diff --git a/core/tauri/scripts/ipc-protocol.js b/core/tauri/scripts/ipc-protocol.js index 082a8ddd5..f52ab5e09 100644 --- a/core/tauri/scripts/ipc-protocol.js +++ b/core/tauri/scripts/ipc-protocol.js @@ -30,7 +30,7 @@ cmd === fetchChannelDataCommand || !(osName === 'linux' || osName === 'android') ) && - !(osName === 'macos' && location.protocol === 'https:') + !((osName === 'macos' || osName === 'ios') && location.protocol === 'https:') ) { const { contentType, diff --git a/core/tauri/src/ipc/mod.rs b/core/tauri/src/ipc/mod.rs index 3d51726d2..02bf1f6a8 100644 --- a/core/tauri/src/ipc/mod.rs +++ b/core/tauri/src/ipc/mod.rs @@ -21,7 +21,7 @@ use crate::{ }; pub(crate) mod channel; -#[cfg(any(target_os = "macos", not(ipc_custom_protocol)))] +#[cfg(any(target_os = "macos", target_os = "ios", not(ipc_custom_protocol)))] pub(crate) mod format_callback; pub(crate) mod protocol; diff --git a/core/tauri/src/ipc/protocol.rs b/core/tauri/src/ipc/protocol.rs index 043ea931a..2dd74b9ce 100644 --- a/core/tauri/src/ipc/protocol.rs +++ b/core/tauri/src/ipc/protocol.rs @@ -20,7 +20,7 @@ use super::{CallbackFn, InvokeBody, InvokeResponse}; const TAURI_CALLBACK_HEADER_NAME: &str = "Tauri-Callback"; const TAURI_ERROR_HEADER_NAME: &str = "Tauri-Error"; -#[cfg(any(target_os = "macos", not(ipc_custom_protocol)))] +#[cfg(any(target_os = "macos", target_os = "ios", not(ipc_custom_protocol)))] pub fn message_handler( manager: WindowManager, ) -> crate::runtime::webview::WebviewIpcHandler { @@ -125,7 +125,7 @@ pub fn get(manager: WindowManager, label: String) -> UriSchemePro }) } -#[cfg(any(target_os = "macos", not(ipc_custom_protocol)))] +#[cfg(any(target_os = "macos", target_os = "ios", not(ipc_custom_protocol)))] fn handle_ipc_message(message: String, manager: &WindowManager, label: &str) { if let Some(window) = manager.get_window(label) { use serde::{Deserialize, Deserializer}; @@ -241,7 +241,7 @@ fn handle_ipc_message(message: String, manager: &WindowManager, l match &response { InvokeResponse::Ok(InvokeBody::Json(v)) => { - if !cfg!(target_os = "macos") + if !(cfg!(target_os = "macos") || cfg!(target_os = "ios")) && matches!(v, JsonValue::Object(_) | JsonValue::Array(_)) { let _ = Channel::from_ipc(window.clone(), callback).send(v); @@ -254,12 +254,12 @@ fn handle_ipc_message(message: String, manager: &WindowManager, l } } InvokeResponse::Ok(InvokeBody::Raw(v)) => { - responder_eval( - &window, - format_callback_result(Result::<_, ()>::Ok(v), callback, error), - error, - ); - if cfg!(target_os = "macos") { + if cfg!(target_os = "macos") || cfg!(target_os = "ios") { + responder_eval( + &window, + format_callback_result(Result::<_, ()>::Ok(v), callback, error), + error, + ); } else { let _ = Channel::from_ipc(window.clone(), callback).send(InvokeBody::Raw(v.clone())); diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index 57738953c..60686b5be 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -1029,7 +1029,7 @@ impl WindowManager { app_handle.clone(), )?; - #[cfg(any(target_os = "macos", not(ipc_custom_protocol)))] + #[cfg(any(target_os = "macos", target_os = "ios", not(ipc_custom_protocol)))] { pending.ipc_handler = Some(crate::ipc::protocol::message_handler(self.clone())); }