@@ -333,8 +333,8 @@ mod error;
333333pub use self :: error:: Error ;
334334
335335use crate :: {
336- api:: dialog:: blocking:: ask, runtime:: EventLoopProxy , utils:: config:: UpdaterConfig , Env ,
337- EventLoopMessage , Manager , Runtime , UpdaterEvent , Window ,
336+ api:: dialog:: blocking:: ask, runtime:: EventLoopProxy , utils:: config:: UpdaterConfig , AppHandle ,
337+ Env , EventLoopMessage , Manager , Runtime , UpdaterEvent ,
338338} ;
339339
340340/// Check for new updates
@@ -374,14 +374,14 @@ struct UpdateManifest {
374374pub ( crate ) async fn check_update_with_dialog < R : Runtime > (
375375 updater_config : UpdaterConfig ,
376376 package_info : crate :: PackageInfo ,
377- window : Window < R > ,
377+ handle : AppHandle < R > ,
378378) {
379379 if let Some ( endpoints) = updater_config. endpoints . clone ( ) {
380380 let endpoints = endpoints
381381 . iter ( )
382382 . map ( |e| e. to_string ( ) )
383383 . collect :: < Vec < String > > ( ) ;
384- let env = window . state :: < Env > ( ) . inner ( ) . clone ( ) ;
384+ let env = handle . state :: < Env > ( ) . inner ( ) . clone ( ) ;
385385 // check updates
386386 match self :: core:: builder ( env)
387387 . urls ( & endpoints[ ..] )
@@ -395,9 +395,9 @@ pub(crate) async fn check_update_with_dialog<R: Runtime>(
395395 // if dialog enabled only
396396 if updater. should_update && updater_config. dialog {
397397 let body = updater. body . clone ( ) . unwrap_or_else ( || String :: from ( "" ) ) ;
398- let window_ = window . clone ( ) ;
398+ let handle_ = handle . clone ( ) ;
399399 let dialog = prompt_for_install (
400- window_ ,
400+ handle_ ,
401401 & updater. clone ( ) ,
402402 & package_info. name ,
403403 & body. clone ( ) ,
@@ -406,12 +406,12 @@ pub(crate) async fn check_update_with_dialog<R: Runtime>(
406406 . await ;
407407
408408 if let Err ( e) = dialog {
409- send_status_update ( window . clone ( ) , UpdaterEvent :: Error ( e. to_string ( ) ) ) ;
409+ send_status_update ( & handle , UpdaterEvent :: Error ( e. to_string ( ) ) ) ;
410410 }
411411 }
412412 }
413413 Err ( e) => {
414- send_status_update ( window . clone ( ) , UpdaterEvent :: Error ( e. to_string ( ) ) ) ;
414+ send_status_update ( & handle , UpdaterEvent :: Error ( e. to_string ( ) ) ) ;
415415 }
416416 }
417417 }
@@ -422,13 +422,13 @@ pub(crate) async fn check_update_with_dialog<R: Runtime>(
422422pub ( crate ) fn listener < R : Runtime > (
423423 updater_config : UpdaterConfig ,
424424 package_info : crate :: PackageInfo ,
425- window : & Window < R > ,
425+ handle : & AppHandle < R > ,
426426) {
427- let isolated_window = window . clone ( ) ;
427+ let handle_ = handle . clone ( ) ;
428428
429429 // Wait to receive the event `"tauri://update"`
430- window . listen ( EVENT_CHECK_UPDATE , move |_msg| {
431- let window = isolated_window . clone ( ) ;
430+ handle . listen_global ( EVENT_CHECK_UPDATE , move |_msg| {
431+ let handle = handle_ . clone ( ) ;
432432 let package_info = package_info. clone ( ) ;
433433
434434 // prepare our endpoints
@@ -444,10 +444,10 @@ pub(crate) fn listener<R: Runtime>(
444444
445445 // check updates
446446 crate :: async_runtime:: spawn ( async move {
447- let window = window . clone ( ) ;
448- let window_isolation = window . clone ( ) ;
447+ let handle = handle . clone ( ) ;
448+ let handle_ = handle . clone ( ) ;
449449 let pubkey = pubkey. clone ( ) ;
450- let env = window . state :: < Env > ( ) . inner ( ) . clone ( ) ;
450+ let env = handle . state :: < Env > ( ) . inner ( ) . clone ( ) ;
451451
452452 match self :: core:: builder ( env)
453453 . urls ( & endpoints[ ..] )
@@ -461,28 +461,27 @@ pub(crate) fn listener<R: Runtime>(
461461 let body = updater. body . clone ( ) . unwrap_or_else ( || String :: from ( "" ) ) ;
462462
463463 // Emit `tauri://update-available`
464- let _ = window . emit (
464+ let _ = handle . emit_all (
465465 EVENT_UPDATE_AVAILABLE ,
466466 UpdateManifest {
467467 body,
468468 date : updater. date . clone ( ) ,
469469 version : updater. version . clone ( ) ,
470470 } ,
471471 ) ;
472- let _ = window
473- . app_handle
472+ let _ = handle
474473 . create_proxy ( )
475474 . send_event ( EventLoopMessage :: Updater ( UpdaterEvent :: UpdateAvailable ) ) ;
476475
477476 // Listen for `tauri://update-install`
478- window . once ( EVENT_INSTALL_UPDATE , move |_msg| {
479- let window = window_isolation . clone ( ) ;
477+ handle . once_global ( EVENT_INSTALL_UPDATE , move |_msg| {
478+ let handle = handle_ . clone ( ) ;
480479 let updater = updater. clone ( ) ;
481480
482481 // Start installation
483482 crate :: async_runtime:: spawn ( async move {
484483 // emit {"status": "PENDING"}
485- send_status_update ( window . clone ( ) , UpdaterEvent :: Pending ) ;
484+ send_status_update ( & handle , UpdaterEvent :: Pending ) ;
486485
487486 // Launch updater download process
488487 // macOS we display the `Ready to restart dialog` asking to restart
@@ -492,28 +491,28 @@ pub(crate) fn listener<R: Runtime>(
492491
493492 if let Err ( err) = update_result {
494493 // emit {"status": "ERROR", "error": "The error message"}
495- send_status_update ( window . clone ( ) , UpdaterEvent :: Error ( err. to_string ( ) ) ) ;
494+ send_status_update ( & handle , UpdaterEvent :: Error ( err. to_string ( ) ) ) ;
496495 } else {
497496 // emit {"status": "DONE"}
498- send_status_update ( window . clone ( ) , UpdaterEvent :: Updated ) ;
497+ send_status_update ( & handle , UpdaterEvent :: Updated ) ;
499498 }
500499 } ) ;
501500 } ) ;
502501 } else {
503- send_status_update ( window . clone ( ) , UpdaterEvent :: AlreadyUpToDate ) ;
502+ send_status_update ( & handle , UpdaterEvent :: AlreadyUpToDate ) ;
504503 }
505504 }
506505 Err ( e) => {
507- send_status_update ( window . clone ( ) , UpdaterEvent :: Error ( e. to_string ( ) ) ) ;
506+ send_status_update ( & handle , UpdaterEvent :: Error ( e. to_string ( ) ) ) ;
508507 }
509508 }
510509 } ) ;
511510 } ) ;
512511}
513512
514513// Send a status update via `tauri://update-status` event.
515- fn send_status_update < R : Runtime > ( window : Window < R > , message : UpdaterEvent ) {
516- let _ = window . emit (
514+ fn send_status_update < R : Runtime > ( handle : & AppHandle < R > , message : UpdaterEvent ) {
515+ let _ = handle . emit_all (
517516 EVENT_STATUS_UPDATE ,
518517 if let UpdaterEvent :: Error ( error) = & message {
519518 StatusEvent {
@@ -527,28 +526,29 @@ fn send_status_update<R: Runtime>(window: Window<R>, message: UpdaterEvent) {
527526 }
528527 } ,
529528 ) ;
530- let _ = window
531- . app_handle
529+ let _ = handle
532530 . create_proxy ( )
533531 . send_event ( EventLoopMessage :: Updater ( message) ) ;
534532}
535533
536534// Prompt a dialog asking if the user want to install the new version
537535// Maybe we should add an option to customize it in future versions.
538536async fn prompt_for_install < R : Runtime > (
539- window : Window < R > ,
537+ handle : AppHandle < R > ,
540538 updater : & self :: core:: Update ,
541539 app_name : & str ,
542540 body : & str ,
543541 pubkey : String ,
544542) -> crate :: Result < ( ) > {
545543 // remove single & double quote
546544 let escaped_body = body. replace ( & [ '\"' , '\'' ] [ ..] , "" ) ;
545+ let windows = handle. windows ( ) ;
546+ let parent_window = windows. values ( ) . next ( ) ;
547547
548548 // todo(lemarier): We should review this and make sure we have
549549 // something more conventional.
550550 let should_install = ask (
551- Some ( & window ) ,
551+ parent_window ,
552552 format ! ( r#"A new version of {} is available! "# , app_name) ,
553553 format ! (
554554 r#"{} {} is now available -- you have {}.
@@ -570,12 +570,12 @@ Release Notes:
570570
571571 // Ask user if we need to restart the application
572572 let should_exit = ask (
573- Some ( & window ) ,
573+ parent_window ,
574574 "Ready to Restart" ,
575575 "The installation was successful, do you want to restart the application now?" ,
576576 ) ;
577577 if should_exit {
578- window . app_handle ( ) . restart ( ) ;
578+ handle . restart ( ) ;
579579 }
580580 }
581581
0 commit comments