@@ -21,7 +21,8 @@ use crate::{
2121} ;
2222
2323use super :: {
24- format_callback, CallbackFn , InvokeError , InvokeResponseBody , IpcResponse , Request , Response ,
24+ format_callback:: format_raw_js, CallbackFn , InvokeError , InvokeResponseBody , IpcResponse ,
25+ Request , Response ,
2526} ;
2627
2728pub const IPC_PAYLOAD_PREFIX : & str = "__CHANNEL__:" ;
@@ -150,15 +151,17 @@ impl JavaScriptChannelId {
150151
151152 match body {
152153 // 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 (
155158 callback_id,
156- & format ! ( "{{ message: {string }, index: {current_index} }}" ) ,
159+ format ! ( "{{ message: {json_string }, index: {current_index} }}" ) ,
157160 ) ) ?;
158161 }
159162 InvokeResponseBody :: Raw ( bytes) if bytes. len ( ) < MAX_RAW_DIRECT_EXECUTE_THRESHOLD => {
160163 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} }}" ) ) ) ?;
162165 }
163166 // use the fetch API to speed up larger response payloads
164167 _ => {
@@ -172,7 +175,7 @@ impl JavaScriptChannelId {
172175 . insert ( data_id, body) ;
173176
174177 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)" ,
176179 ) ) ?;
177180 }
178181 }
@@ -181,9 +184,9 @@ impl JavaScriptChannelId {
181184 } ) ,
182185 Some ( Box :: new ( move || {
183186 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 (
185188 callback_id,
186- & format ! ( "{{ end: true, index: {current_index} }}" ) ,
189+ format ! ( "{{ end: true, index: {current_index} }}" ) ,
187190 ) ) ;
188191 } ) ) ,
189192 )
@@ -244,14 +247,16 @@ impl<TSend> Channel<TSend> {
244247 Box :: new ( move |body| {
245248 match body {
246249 // 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) ) ?;
249254 }
250255 InvokeResponseBody :: Raw ( bytes) if bytes. len ( ) < MAX_RAW_DIRECT_EXECUTE_THRESHOLD => {
251256 let bytes_as_json_array = serde_json:: to_string ( & bytes) ?;
252- webview. eval ( format_callback :: format_raw_js (
257+ webview. eval ( format_raw_js (
253258 callback_id,
254- & format ! ( "new Uint8Array({bytes_as_json_array}).buffer" ) ,
259+ format ! ( "new Uint8Array({bytes_as_json_array}).buffer" ) ,
255260 ) ) ?;
256261 }
257262 // use the fetch API to speed up larger response payloads
@@ -266,7 +271,7 @@ impl<TSend> Channel<TSend> {
266271 . insert ( data_id, body) ;
267272
268273 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)" ,
270275 ) ) ?;
271276 }
272277 }
0 commit comments