@@ -121,7 +121,7 @@ impl Interface for Rust {
121121 watcher
122122 . watcher ( )
123123 . watch ( & tauri_dir ( ) . join ( "Cargo.toml" ) , RecursiveMode :: Recursive ) ?;
124- let manifest = rewrite_manifest ( config) ?;
124+ let ( manifest, _modified ) = rewrite_manifest ( config) ?;
125125 let now = Instant :: now ( ) ;
126126 let timeout = Duration :: from_secs ( 2 ) ;
127127 loop {
@@ -535,38 +535,34 @@ impl Rust {
535535
536536 if !ignore_matcher. is_ignore ( & event_path, event_path. is_dir ( ) ) {
537537 if is_configuration_file ( self . app_settings . target , & event_path) {
538- match reload_config ( config. as_ref ( ) ) {
539- Ok ( config) => {
540- info ! ( "Tauri configuration changed. Rewriting manifest..." ) ;
541- * self . app_settings . manifest . lock ( ) . unwrap ( ) =
542- rewrite_manifest ( config. lock ( ) . unwrap ( ) . as_ref ( ) . unwrap ( ) ) ?
543- }
544- Err ( err) => {
545- let p = process. lock ( ) . unwrap ( ) ;
546- if p. is_building_app ( ) {
547- p. kill ( ) . with_context ( || "failed to kill app process" ) ?;
548- }
549- error ! ( "{}" , err) ;
538+ if let Ok ( config) = reload_config ( config. as_ref ( ) ) {
539+ let ( manifest, modified) =
540+ rewrite_manifest ( config. lock ( ) . unwrap ( ) . as_ref ( ) . unwrap ( ) ) ?;
541+ if modified {
542+ * self . app_settings . manifest . lock ( ) . unwrap ( ) = manifest;
543+ // no need to run the watcher logic, the manifest was modified
544+ // and it will trigger the watcher again
545+ continue ;
550546 }
551547 }
552- } else {
553- info ! (
554- "File {} changed. Rebuilding application..." ,
555- display_path ( event_path . strip_prefix ( app_path ) . unwrap_or ( & event_path ) )
556- ) ;
557- // When tauri.conf.json is changed, rewrite_manifest will be called
558- // which will trigger the watcher again
559- // So the app should only be started when a file other than tauri.conf.json is changed
560- let mut p = process. lock ( ) . unwrap ( ) ;
561- p . kill ( ) . with_context ( || "failed to kill app process" ) ? ;
562- // wait for the process to exit
563- loop {
564- if let Ok ( Some ( _ ) ) = p . try_wait ( ) {
565- break ;
566- }
548+ }
549+
550+ log :: info! (
551+ "File {} changed. Rebuilding application..." ,
552+ display_path ( event_path . strip_prefix ( app_path ) . unwrap_or ( & event_path ) )
553+ ) ;
554+
555+ let mut p = process . lock ( ) . unwrap ( ) ;
556+ p . kill ( ) . with_context ( || "failed to kill app process" ) ? ;
557+
558+ // wait for the process to exit
559+ // note that on mobile, kill() already waits for the process to exit (duct implementation)
560+ loop {
561+ if ! matches ! ( p . try_wait ( ) , Ok ( None ) ) {
562+ break ;
567563 }
568- * p = run ( self ) ?;
569564 }
565+ * p = run ( self ) ?;
570566 }
571567 }
572568 }
0 commit comments