From b3578ee923a8e458a565e8501fed34fdc953effb Mon Sep 17 00:00:00 2001 From: Nathan Collins Date: Thu, 18 Apr 2024 13:08:55 +0100 Subject: [PATCH] slint-viewer: handle path being renamed and replaced Some editors may backup a file by renaming it to append ~, then saving the new file contents to a new file. notify-rs/notify#166 explains that a non-recursive watcher on the parent directory is the recommended way to deal with this situation. Closes: #3641 --- tools/viewer/main.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/viewer/main.rs b/tools/viewer/main.rs index 5f8a234a1f7..356e47dad88 100644 --- a/tools/viewer/main.rs +++ b/tools/viewer/main.rs @@ -190,6 +190,16 @@ fn init_compiler( .unwrap_or_else(|err| { eprintln!("Warning: error while watching {}: {:?}", args.path.display(), err) }); + // Watch the parent directory incase args.path is renamed or removed + let parent = args.path.parent().unwrap(); + notify::Watcher::watch( + &mut *watcher.lock().unwrap(), + &parent, + notify::RecursiveMode::NonRecursive, + ) + .unwrap_or_else(|err| { + eprintln!("Warning: error while watching {}: {:?}", parent.display(), err) + }); if let Some(data_path) = &args.load_data { notify::Watcher::watch( &mut *watcher.lock().unwrap(),