image: Reload image on FileMonitor Renamed events

The Rename event is also fired if the file got replaced
via a file move.

Closes #227

Part-of: <https://gitlab.gnome.org/GNOME/loupe/-/merge_requests/271>
This commit is contained in:
Sophie Herold 2023-08-08 18:23:26 +02:00
parent 13f1a753d9
commit 270853ea57

View file

@ -965,9 +965,19 @@ impl LpImage {
) { ) {
match event { match event {
gio::FileMonitorEvent::Renamed => { gio::FileMonitorEvent::Renamed => {
if let Some(file) = file_b { if let Some(file) = file_b.cloned() {
log::debug!("Moved to {}", file.uri()); log::debug!("Moved to {}", file.uri());
self.set_file(file); // current file got replaced with a new one
let file_replace = self.file().map_or(false, |x| x.equal(&file));
self.set_file(&file);
if file_replace {
log::debug!("Image got replaced");
let obj = self.clone();
// TODO: error handling is missing
spawn(async move {
obj.load(&file).await;
});
}
} }
} }
gio::FileMonitorEvent::ChangesDoneHint => { gio::FileMonitorEvent::ChangesDoneHint => {