@@ -325,7 +325,6 @@ fn handle_ipc_message<R: Runtime>(request: Request<String>, manager: &AppManager
325325 request,
326326 Box :: new ( move |webview, cmd, response, callback, error| {
327327 use crate :: ipc:: Channel ;
328- use crate :: sealed:: ManagerBase ;
329328
330329 #[ cfg( feature = "tracing" ) ]
331330 let _respond_span = tracing:: trace_span!(
@@ -334,104 +333,101 @@ fn handle_ipc_message<R: Runtime>(request: Request<String>, manager: &AppManager
334333 )
335334 . entered ( ) ;
336335
337- // the channel data command is the only command that uses a custom protocol on Linux
338- if webview. manager ( ) . webview . invoke_responder . is_none ( ) {
339- fn responder_eval < R : Runtime > (
340- webview : & crate :: Webview < R > ,
341- js : crate :: Result < String > ,
342- error : CallbackFn ,
343- ) {
344- let eval_js = match js {
345- Ok ( js) => js,
346- Err ( e) => crate :: ipc:: format_callback:: format ( error, & e. to_string ( ) )
347- . expect ( "unable to serialize response error string to json" ) ,
348- } ;
349-
350- let _ = webview. eval ( & eval_js) ;
351- }
336+ fn responder_eval < R : Runtime > (
337+ webview : & crate :: Webview < R > ,
338+ js : crate :: Result < String > ,
339+ error : CallbackFn ,
340+ ) {
341+ let eval_js = match js {
342+ Ok ( js) => js,
343+ Err ( e) => crate :: ipc:: format_callback:: format ( error, & e. to_string ( ) )
344+ . expect ( "unable to serialize response error string to json" ) ,
345+ } ;
352346
353- let can_use_channel_for_response = cmd
354- != crate :: ipc:: channel:: FETCH_CHANNEL_DATA_COMMAND
355- && !options. custom_protocol_ipc_blocked ;
347+ let _ = webview. eval ( & eval_js) ;
348+ }
356349
357- #[ cfg( feature = "tracing" ) ]
358- let mime_type = match & response {
359- InvokeResponse :: Ok ( InvokeResponseBody :: Json ( _) ) => mime:: APPLICATION_JSON ,
360- InvokeResponse :: Ok ( InvokeResponseBody :: Raw ( _) ) => mime:: APPLICATION_OCTET_STREAM ,
361- InvokeResponse :: Err ( _) => mime:: APPLICATION_JSON ,
362- } ;
350+ let can_use_channel_for_response = cmd
351+ != crate :: ipc:: channel:: FETCH_CHANNEL_DATA_COMMAND
352+ && !options. custom_protocol_ipc_blocked ;
363353
364- #[ cfg( feature = "tracing" ) ]
365- let _response_span = match & response {
366- InvokeResponse :: Ok ( InvokeResponseBody :: Json ( v) ) => tracing:: trace_span!(
367- "ipc::request::response" ,
368- response = v,
369- mime_type = mime_type. essence_str( )
370- )
371- . entered ( ) ,
372- InvokeResponse :: Ok ( InvokeResponseBody :: Raw ( v) ) => tracing:: trace_span!(
373- "ipc::request::response" ,
374- response = format!( "{v:?}" ) ,
375- mime_type = mime_type. essence_str( )
376- )
377- . entered ( ) ,
378- InvokeResponse :: Err ( e) => tracing:: trace_span!(
379- "ipc::request::response" ,
380- response = format!( "{e:?}" ) ,
381- mime_type = mime_type. essence_str( )
382- )
383- . entered ( ) ,
384- } ;
354+ #[ cfg( feature = "tracing" ) ]
355+ let mime_type = match & response {
356+ InvokeResponse :: Ok ( InvokeResponseBody :: Json ( _) ) => mime:: APPLICATION_JSON ,
357+ InvokeResponse :: Ok ( InvokeResponseBody :: Raw ( _) ) => mime:: APPLICATION_OCTET_STREAM ,
358+ InvokeResponse :: Err ( _) => mime:: APPLICATION_JSON ,
359+ } ;
385360
386- match response {
387- InvokeResponse :: Ok ( InvokeResponseBody :: Json ( v) ) => {
388- if !( cfg ! ( target_os = "macos" ) || cfg ! ( target_os = "ios" ) )
389- && ( v. starts_with ( '{' ) || v. starts_with ( '[' ) )
390- && can_use_channel_for_response
391- {
392- let _ = Channel :: from_callback_fn ( webview, callback)
393- . send ( InvokeResponseBody :: Json ( v) ) ;
394- } else {
395- responder_eval (
396- & webview,
397- crate :: ipc:: format_callback:: format_result_raw (
398- Result :: < _ , String > :: Ok ( v) ,
399- callback,
400- error,
401- ) ,
361+ #[ cfg( feature = "tracing" ) ]
362+ let _response_span = match & response {
363+ InvokeResponse :: Ok ( InvokeResponseBody :: Json ( v) ) => tracing:: trace_span!(
364+ "ipc::request::response" ,
365+ response = v,
366+ mime_type = mime_type. essence_str( )
367+ )
368+ . entered ( ) ,
369+ InvokeResponse :: Ok ( InvokeResponseBody :: Raw ( v) ) => tracing:: trace_span!(
370+ "ipc::request::response" ,
371+ response = format!( "{v:?}" ) ,
372+ mime_type = mime_type. essence_str( )
373+ )
374+ . entered ( ) ,
375+ InvokeResponse :: Err ( e) => tracing:: trace_span!(
376+ "ipc::request::response" ,
377+ response = format!( "{e:?}" ) ,
378+ mime_type = mime_type. essence_str( )
379+ )
380+ . entered ( ) ,
381+ } ;
382+
383+ match response {
384+ InvokeResponse :: Ok ( InvokeResponseBody :: Json ( v) ) => {
385+ if !( cfg ! ( target_os = "macos" ) || cfg ! ( target_os = "ios" ) )
386+ && ( v. starts_with ( '{' ) || v. starts_with ( '[' ) )
387+ && can_use_channel_for_response
388+ {
389+ let _ =
390+ Channel :: from_callback_fn ( webview, callback) . send ( InvokeResponseBody :: Json ( v) ) ;
391+ } else {
392+ responder_eval (
393+ & webview,
394+ crate :: ipc:: format_callback:: format_result_raw (
395+ Result :: < _ , String > :: Ok ( v) ,
396+ callback,
402397 error,
403- )
404- }
398+ ) ,
399+ error,
400+ )
405401 }
406- InvokeResponse :: Ok ( InvokeResponseBody :: Raw ( v) ) => {
407- if cfg ! ( target_os = "macos" )
408- || cfg ! ( target_os = "ios" )
409- || !can_use_channel_for_response
410- {
411- responder_eval (
412- & webview,
413- crate :: ipc:: format_callback:: format_result (
414- Result :: < _ , ( ) > :: Ok ( v) ,
415- callback,
416- error,
417- ) ,
402+ }
403+ InvokeResponse :: Ok ( InvokeResponseBody :: Raw ( v) ) => {
404+ if cfg ! ( target_os = "macos" )
405+ || cfg ! ( target_os = "ios" )
406+ || !can_use_channel_for_response
407+ {
408+ responder_eval (
409+ & webview,
410+ crate :: ipc:: format_callback:: format_result (
411+ Result :: < _ , ( ) > :: Ok ( v) ,
412+ callback,
418413 error,
419- ) ;
420- } else {
421- let _ = Channel :: from_callback_fn ( webview, callback)
422- . send ( InvokeResponseBody :: Raw ( v. clone ( ) ) ) ;
423- }
424- }
425- InvokeResponse :: Err ( e) => responder_eval (
426- & webview,
427- crate :: ipc:: format_callback:: format_result (
428- Result :: < ( ) , _ > :: Err ( & e. 0 ) ,
429- callback,
414+ ) ,
430415 error,
431- ) ,
416+ ) ;
417+ } else {
418+ let _ = Channel :: from_callback_fn ( webview, callback)
419+ . send ( InvokeResponseBody :: Raw ( v. clone ( ) ) ) ;
420+ }
421+ }
422+ InvokeResponse :: Err ( e) => responder_eval (
423+ & webview,
424+ crate :: ipc:: format_callback:: format_result (
425+ Result :: < ( ) , _ > :: Err ( & e. 0 ) ,
426+ callback,
432427 error,
433428 ) ,
434- }
429+ error,
430+ ) ,
435431 }
436432 } ) ,
437433 ) ;
@@ -593,7 +589,7 @@ mod tests {
593589 Default :: default ( ) ,
594590 Default :: default ( ) ,
595591 Default :: default ( ) ,
596- ( None , "" . into ( ) ) ,
592+ "" . into ( ) ,
597593 crate :: generate_invoke_key ( ) . unwrap ( ) ,
598594 ) ;
599595
@@ -706,7 +702,7 @@ mod tests {
706702 Default :: default ( ) ,
707703 Default :: default ( ) ,
708704 Default :: default ( ) ,
709- ( None , "" . into ( ) ) ,
705+ "" . into ( ) ,
710706 crate :: generate_invoke_key ( ) . unwrap ( ) ,
711707 ) ;
712708
0 commit comments