You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: tauri-api/src/rpc.rs
+103-12
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,72 @@
1
1
use serde::Serialize;
2
2
use serde_json::ValueasJsonValue;
3
3
4
+
/// The information about this is quite limited. On Chrome/Edge and Firefox, [the maximum string size is approximately 1 GB](https://stackoverflow.com/a/34958490).
let escape_single_quoted_json_test = escape_json_parse(dangerous_json);
58
+
59
+
let result = r#"JSON.parse('{"test":"don\\\\🚀🐱👤\\\\\'t forget to escape me!🚀🐱👤","te🚀🐱👤st2":"don\'t forget to escape me!","test3":"\\\\🚀🐱👤\\\\\\\\\'\'\'\\\\\\\\🚀🐱👤\\\\\\\\🚀🐱👤\\\\\'\'\'\'\'"}')"#;
console.warn("[TAURI] Couldn't find callback id {fn} in window. This happens when the app is reloaded while Rust is running an asynchronous operation.")
34
-
}}
35
-
"#,
36
-
fn = function_name.as_ref(),
37
-
arg = arg.into().to_string()
38
-
)
92
+
macro_rules! format_callback {
93
+
( $arg:expr ) => {
94
+
format!(
95
+
r#"
96
+
if (window["{fn}"]) {{
97
+
window["{fn}"]({arg})
98
+
}} else {{
99
+
console.warn("[TAURI] Couldn't find callback id {fn} in window. This happens when the app is reloaded while Rust is running an asynchronous operation.")
100
+
}}
101
+
"#,
102
+
fn = function_name.as_ref(),
103
+
arg = $arg
104
+
)
105
+
}
106
+
}
107
+
108
+
let json_value = arg.into();
109
+
110
+
// We should only use JSON.parse('{arg}') if it's an array or object.
111
+
// We likely won't get any performance benefit from other data types.
// Explicitly drop json_value to avoid storing both the Rust "JSON" and serialized String JSON in memory twice, as <T: Display>.tostring() takes a reference.
0 commit comments