@@ -21,7 +21,8 @@ use crate::{
21
21
} ;
22
22
23
23
use super :: {
24
- format_callback, CallbackFn , InvokeError , InvokeResponseBody , IpcResponse , Request , Response ,
24
+ format_callback:: format_raw_js, CallbackFn , InvokeError , InvokeResponseBody , IpcResponse ,
25
+ Request , Response ,
25
26
} ;
26
27
27
28
pub const IPC_PAYLOAD_PREFIX : & str = "__CHANNEL__:" ;
@@ -150,15 +151,17 @@ impl JavaScriptChannelId {
150
151
151
152
match body {
152
153
// Don't go through the fetch process if the payload is small
153
- InvokeResponseBody :: Json ( string) if string. len ( ) < MAX_JSON_DIRECT_EXECUTE_THRESHOLD => {
154
- webview. eval ( format_callback:: format_raw_js (
154
+ InvokeResponseBody :: Json ( json_string)
155
+ if json_string. len ( ) < MAX_JSON_DIRECT_EXECUTE_THRESHOLD =>
156
+ {
157
+ webview. eval ( format_raw_js (
155
158
callback_id,
156
- & format ! ( "{{ message: {string }, index: {current_index} }}" ) ,
159
+ format ! ( "{{ message: {json_string }, index: {current_index} }}" ) ,
157
160
) ) ?;
158
161
}
159
162
InvokeResponseBody :: Raw ( bytes) if bytes. len ( ) < MAX_RAW_DIRECT_EXECUTE_THRESHOLD => {
160
163
let bytes_as_json_array = serde_json:: to_string ( & bytes) ?;
161
- webview. eval ( format_callback :: format_raw_js ( callback_id, & format ! ( "{{ message: new Uint8Array({bytes_as_json_array}).buffer, index: {current_index} }}" ) ) ) ?;
164
+ webview. eval ( format_raw_js ( callback_id, format ! ( "{{ message: new Uint8Array({bytes_as_json_array}).buffer, index: {current_index} }}" ) ) ) ?;
162
165
}
163
166
// use the fetch API to speed up larger response payloads
164
167
_ => {
@@ -172,7 +175,7 @@ impl JavaScriptChannelId {
172
175
. insert ( data_id, body) ;
173
176
174
177
webview. eval ( format ! (
175
- "window.__TAURI_INTERNALS__.invoke('{FETCH_CHANNEL_DATA_COMMAND}', null, {{ headers: {{ '{CHANNEL_ID_HEADER_NAME}': '{data_id}' }} }}).then((response) => window['_ {callback_id}']( {{ message: response, index: {current_index} }})).catch(console.error)" ,
178
+ "window.__TAURI_INTERNALS__.invoke('{FETCH_CHANNEL_DATA_COMMAND}', null, {{ headers: {{ '{CHANNEL_ID_HEADER_NAME}': '{data_id}' }} }}).then((response) => window.__TAURI_INTERNALS__.runCallback( {callback_id}, {{ message: response, index: {current_index} }})).catch(console.error)" ,
176
179
) ) ?;
177
180
}
178
181
}
@@ -181,9 +184,9 @@ impl JavaScriptChannelId {
181
184
} ) ,
182
185
Some ( Box :: new ( move || {
183
186
let current_index = counter_clone. load ( Ordering :: Relaxed ) ;
184
- let _ = webview_clone. eval ( format_callback :: format_raw_js (
187
+ let _ = webview_clone. eval ( format_raw_js (
185
188
callback_id,
186
- & format ! ( "{{ end: true, index: {current_index} }}" ) ,
189
+ format ! ( "{{ end: true, index: {current_index} }}" ) ,
187
190
) ) ;
188
191
} ) ) ,
189
192
)
@@ -244,14 +247,16 @@ impl<TSend> Channel<TSend> {
244
247
Box :: new ( move |body| {
245
248
match body {
246
249
// Don't go through the fetch process if the payload is small
247
- InvokeResponseBody :: Json ( string) if string. len ( ) < MAX_JSON_DIRECT_EXECUTE_THRESHOLD => {
248
- webview. eval ( format_callback:: format_raw_js ( callback_id, & string) ) ?;
250
+ InvokeResponseBody :: Json ( json_string)
251
+ if json_string. len ( ) < MAX_JSON_DIRECT_EXECUTE_THRESHOLD =>
252
+ {
253
+ webview. eval ( format_raw_js ( callback_id, json_string) ) ?;
249
254
}
250
255
InvokeResponseBody :: Raw ( bytes) if bytes. len ( ) < MAX_RAW_DIRECT_EXECUTE_THRESHOLD => {
251
256
let bytes_as_json_array = serde_json:: to_string ( & bytes) ?;
252
- webview. eval ( format_callback :: format_raw_js (
257
+ webview. eval ( format_raw_js (
253
258
callback_id,
254
- & format ! ( "new Uint8Array({bytes_as_json_array}).buffer" ) ,
259
+ format ! ( "new Uint8Array({bytes_as_json_array}).buffer" ) ,
255
260
) ) ?;
256
261
}
257
262
// use the fetch API to speed up larger response payloads
@@ -266,7 +271,7 @@ impl<TSend> Channel<TSend> {
266
271
. insert ( data_id, body) ;
267
272
268
273
webview. eval ( format ! (
269
- "window.__TAURI_INTERNALS__.invoke('{FETCH_CHANNEL_DATA_COMMAND}', null, {{ headers: {{ '{CHANNEL_ID_HEADER_NAME}': '{data_id}' }} }}).then((response) => window['_ {callback_id}']( response)).catch(console.error)" ,
274
+ "window.__TAURI_INTERNALS__.invoke('{FETCH_CHANNEL_DATA_COMMAND}', null, {{ headers: {{ '{CHANNEL_ID_HEADER_NAME}': '{data_id}' }} }}).then((response) => window.__TAURI_INTERNALS__.runCallback( {callback_id}, response)).catch(console.error)" ,
270
275
) ) ?;
271
276
}
272
277
}
0 commit comments