diff --git a/.changes/prevent-ios-crash.md b/.changes/prevent-ios-crash.md new file mode 100644 index 000000000..8d3295d4b --- /dev/null +++ b/.changes/prevent-ios-crash.md @@ -0,0 +1,5 @@ +--- +"tauri": patch:bug +--- + +Prevent crash on iOS when the Swift plugin data is not a valid JSON string. diff --git a/core/tauri/src/plugin/mobile.rs b/core/tauri/src/plugin/mobile.rs index 4e7317db5..a708f509a 100644 --- a/core/tauri/src/plugin/mobile.rs +++ b/core/tauri/src/plugin/mobile.rs @@ -344,12 +344,19 @@ pub(crate) fn run_command, F: FnOnce(PluginResponse) + .unwrap() .remove(&id) { - let payload = serde_json::from_str(payload.to_str().unwrap()).unwrap(); - handler(if success == 1 { - Ok(payload) - } else { - Err(payload) - }); + let json = payload.to_str().unwrap(); + match serde_json::from_str(json) { + Ok(payload) => { + handler(if success == 1 { + Ok(payload) + } else { + Err(payload) + }); + } + Err(err) => { + handler(Err(format!("{err}, data: {}", json).into())); + } + } } } diff --git a/core/tauri/src/protocol/tauri.rs b/core/tauri/src/protocol/tauri.rs index 109d8a77d..bd2ba5d11 100644 --- a/core/tauri/src/protocol/tauri.rs +++ b/core/tauri/src/protocol/tauri.rs @@ -69,7 +69,7 @@ pub fn get( fn get_response( request: Request>, - manager: &WindowManager, + #[allow(unused_variables)] manager: &WindowManager, window_origin: &str, web_resource_request_handler: Option<&WebResourceRequestHandler>, #[cfg(all(dev, mobile))] (url, response_cache): ( diff --git a/core/tauri/src/window/mod.rs b/core/tauri/src/window/mod.rs index a2e8bb4cc..74ac435ee 100644 --- a/core/tauri/src/window/mod.rs +++ b/core/tauri/src/window/mod.rs @@ -32,10 +32,7 @@ use crate::{ }, sealed::ManagerBase, sealed::RuntimeOrDispatch, - utils::{ - config::{WindowConfig, WindowEffectsConfig, WindowUrl}, - ProgressBarState, - }, + utils::config::{WindowConfig, WindowEffectsConfig, WindowUrl}, EventLoopMessage, Manager, Runtime, Theme, WindowEvent, }; #[cfg(desktop)] @@ -2071,7 +2068,10 @@ impl Window { /// - **Linux / macOS**: Progress bar is app-wide and not specific to this window. /// - **Linux**: Only supported desktop environments with `libunity` (e.g. GNOME). /// - **iOS / Android:** Unsupported. - pub fn set_progress_bar(&self, progress_state: ProgressBarState) -> crate::Result<()> { + pub fn set_progress_bar( + &self, + progress_state: crate::utils::ProgressBarState, + ) -> crate::Result<()> { self .window .dispatcher diff --git a/core/tauri/src/window/plugin.rs b/core/tauri/src/window/plugin.rs index 705f083e5..1d295addd 100644 --- a/core/tauri/src/window/plugin.rs +++ b/core/tauri/src/window/plugin.rs @@ -314,13 +314,12 @@ pub fn init() -> TauriPlugin { #[cfg(any(debug_assertions, feature = "devtools"))] desktop_commands::internal_toggle_devtools, ]); - #[allow(clippy::needless_return)] - return handler(invoke); + handler(invoke) } #[cfg(mobile)] { invoke.resolver.reject("Window API not available on mobile"); - return true; + true } }) .build()