Skip to content

Commit

Permalink
slint-viewer: handle path being renamed and replaced
Browse files Browse the repository at this point in the history
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
  • Loading branch information
0x6e committed Apr 18, 2024
1 parent 97940ee commit b3578ee
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tools/viewer/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit b3578ee

Please sign in to comment.