From a52f13cb60acf417b85a1ab7b1847be61411e95b Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Wed, 6 Sep 2023 15:54:28 -0300 Subject: [PATCH 1/3] fix(core): use postMessage IPC for remote URLs on iOS ref #7751 --- .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 | 4 ++-- core/tauri/src/manager.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.changes/fix-ipc-remote-url-macos.md b/.changes/fix-ipc-remote-url-macos.md index 915ebee4e58..314ab2e2976 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 082a8ddd546..f52ab5e09ad 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 3d51726d277..02bf1f6a83c 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 043ea931a4d..97930287dd7 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}; diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index 57738953c6f..60686b5be1e 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())); } From f9c933f8d66806359b013c24211f5c927c776dc0 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Wed, 6 Sep 2023 15:55:40 -0300 Subject: [PATCH 2/3] fix protocol impl --- core/tauri/src/ipc/protocol.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/tauri/src/ipc/protocol.rs b/core/tauri/src/ipc/protocol.rs index 97930287dd7..d2b9e7cf4cf 100644 --- a/core/tauri/src/ipc/protocol.rs +++ b/core/tauri/src/ipc/protocol.rs @@ -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())); From 0cc6d7ab65ebba33d84ceafe935ce670b644bcab Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Wed, 6 Sep 2023 22:02:24 +0300 Subject: [PATCH 3/3] Update core/tauri/src/ipc/protocol.rs --- core/tauri/src/ipc/protocol.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/tauri/src/ipc/protocol.rs b/core/tauri/src/ipc/protocol.rs index d2b9e7cf4cf..2dd74b9ce68 100644 --- a/core/tauri/src/ipc/protocol.rs +++ b/core/tauri/src/ipc/protocol.rs @@ -254,7 +254,7 @@ fn handle_ipc_message(message: String, manager: &WindowManager, l } } InvokeResponse::Ok(InvokeBody::Raw(v)) => { - if (cfg!(target_os = "macos") || cfg!(target_os = "ios")) { + if cfg!(target_os = "macos") || cfg!(target_os = "ios") { responder_eval( &window, format_callback_result(Result::<_, ()>::Ok(v), callback, error),