@@ -30,7 +30,7 @@ pub(crate) fn run(application: &mut App) -> crate::Result<()> {
3030 } ;
3131
3232 // build the webview
33- let webview = build_webview (
33+ let mut webview = build_webview (
3434 application,
3535 main_content,
3636 if application. splashscreen_html ( ) . is_some ( ) {
@@ -45,6 +45,8 @@ pub(crate) fn run(application: &mut App) -> crate::Result<()> {
4545 } ,
4646 ) ?;
4747
48+ crate :: plugin:: created ( & mut webview) ;
49+
4850 // spawn the embedded server on our server url
4951 #[ cfg( embedded_server) ]
5052 spawn_server ( server_url) ?;
@@ -217,33 +219,59 @@ fn build_webview(
217219 "window-1"
218220 } ;
219221 application. run_setup ( webview, source. to_string ( ) ) ;
222+ if source == "window-1" {
223+ let handle = webview. handle ( ) ;
224+ handle
225+ . dispatch ( |webview| {
226+ crate :: plugin:: ready ( webview) ;
227+ Ok ( ( ) )
228+ } )
229+ . expect ( "failed to invoke ready hook" ) ;
230+ }
220231 } else if arg == r#"{"cmd":"closeSplashscreen"}"# {
221232 let content_href = match content_clone {
222233 Content :: Html ( ref html) => html,
223234 Content :: Url ( ref url) => url,
224235 } ;
225236 webview. eval ( & format ! ( r#"window.location.href = "{}""# , content_href) ) ?;
226237 } else {
227- let handler_error;
228- if let Err ( tauri_handle_error) = crate :: endpoints:: handle ( webview, arg) {
229- let tauri_handle_error_str = tauri_handle_error. to_string ( ) ;
230- if tauri_handle_error_str. contains ( "unknown variant" ) {
231- let handled_by_app = application. run_invoke_handler ( webview, arg) ;
232- handler_error = if let Err ( e) = handled_by_app {
233- Some ( e. replace ( "'" , "\\ '" ) )
238+ let endpoint_handle = crate :: endpoints:: handle ( webview, arg)
239+ . map_err ( |tauri_handle_error| {
240+ let tauri_handle_error_str = tauri_handle_error. to_string ( ) ;
241+ if tauri_handle_error_str. contains ( "unknown variant" ) {
242+ match application. run_invoke_handler ( webview, arg) {
243+ Ok ( handled) => {
244+ if handled {
245+ String :: from ( "" )
246+ } else {
247+ tauri_handle_error_str
248+ }
249+ }
250+ Err ( e) => e,
251+ }
234252 } else {
235- let handled = handled_by_app. expect ( "failed to check if the invoke was handled" ) ;
236- if handled {
237- None
238- } else {
239- Some ( tauri_handle_error_str)
253+ tauri_handle_error_str
254+ }
255+ } )
256+ . map_err ( |app_handle_error| {
257+ if app_handle_error. contains ( "unknown variant" ) {
258+ match crate :: plugin:: extend_api ( webview, arg) {
259+ Ok ( handled) => {
260+ if handled {
261+ String :: from ( "" )
262+ } else {
263+ app_handle_error
264+ }
265+ }
266+ Err ( e) => e,
240267 }
241- } ;
242- } else {
243- handler_error = Some ( tauri_handle_error_str) ;
244- }
245-
246- if let Some ( handler_error_message) = handler_error {
268+ } else {
269+ app_handle_error
270+ }
271+ } )
272+ . map_err ( |e| e. replace ( "'" , "\\ '" ) ) ;
273+ if let Err ( handler_error_message) = endpoint_handle {
274+ if handler_error_message != "" {
247275 webview. eval ( & get_api_error_message ( arg, handler_error_message) ) ?;
248276 }
249277 }
0 commit comments