Skip to content

Commit b3578ee

Browse files
committed
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: slint-ui#3641
1 parent 97940ee commit b3578ee

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

tools/viewer/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ fn init_compiler(
190190
.unwrap_or_else(|err| {
191191
eprintln!("Warning: error while watching {}: {:?}", args.path.display(), err)
192192
});
193+
// Watch the parent directory incase args.path is renamed or removed
194+
let parent = args.path.parent().unwrap();
195+
notify::Watcher::watch(
196+
&mut *watcher.lock().unwrap(),
197+
&parent,
198+
notify::RecursiveMode::NonRecursive,
199+
)
200+
.unwrap_or_else(|err| {
201+
eprintln!("Warning: error while watching {}: {:?}", parent.display(), err)
202+
});
193203
if let Some(data_path) = &args.load_data {
194204
notify::Watcher::watch(
195205
&mut *watcher.lock().unwrap(),

0 commit comments

Comments
 (0)