mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-28 12:27:16 +03:00
fix(core): prevent iOS crash on invalid plugin response JSON (#8049)
This commit is contained in:
parent
d16206a086
commit
22f26882cf
5
.changes/prevent-ios-crash.md
Normal file
5
.changes/prevent-ios-crash.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": patch:bug
|
||||
---
|
||||
|
||||
Prevent crash on iOS when the Swift plugin data is not a valid JSON string.
|
@ -344,13 +344,20 @@ pub(crate) fn run_command<R: Runtime, C: AsRef<str>, F: FnOnce(PluginResponse) +
|
||||
.unwrap()
|
||||
.remove(&id)
|
||||
{
|
||||
let payload = serde_json::from_str(payload.to_str().unwrap()).unwrap();
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn send_channel_data_handler(id: c_ulonglong, payload: *const c_char) {
|
||||
|
@ -69,7 +69,7 @@ pub fn get<R: Runtime>(
|
||||
|
||||
fn get_response<R: Runtime>(
|
||||
request: Request<Vec<u8>>,
|
||||
manager: &WindowManager<R>,
|
||||
#[allow(unused_variables)] manager: &WindowManager<R>,
|
||||
window_origin: &str,
|
||||
web_resource_request_handler: Option<&WebResourceRequestHandler>,
|
||||
#[cfg(all(dev, mobile))] (url, response_cache): (
|
||||
|
@ -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<R: Runtime> Window<R> {
|
||||
/// - **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
|
||||
|
@ -314,13 +314,12 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
#[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()
|
||||
|
Loading…
Reference in New Issue
Block a user