Watch trash folders for changes

This commit is contained in:
Josh Megnauth 2024-03-20 01:50:43 -04:00
parent 503bce2c37
commit f606a26482
No known key found for this signature in database
GPG key ID: 70813183462EFAD3

View file

@ -1567,6 +1567,7 @@ impl Application for App {
struct ConfigSubscription;
struct ThemeSubscription;
struct WatcherSubscription;
struct TrashWatcherSubscription;
let mut subscriptions = vec![
event::listen_with(|event, status| match event {
@ -1687,6 +1688,44 @@ impl Application for App {
}
},
),
subscription::channel(
TypeId::of::<TrashWatcherSubscription>(),
25,
|mut output| async move {
let watcher_res = notify::recommended_watcher(|event_res| match event_res {
Ok(event) => {
log::info!("Trash event: {event:?}");
}
Err(e) => log::warn!("failed watching trash bin for changes: {e:?}"),
});
match (watcher_res, trash::os_limited::trash_folders()) {
(Ok(mut watcher), Ok(trash_bins)) => {
for path in trash_bins {
if let Err(e) =
watcher.watch(&path, notify::RecursiveMode::Recursive)
{
log::warn!(
"failed to add trash bin `{}` to watcher: {e:?}",
path.display()
);
}
}
// Don't drop the watcher
std::future::pending().await
}
(Err(e), _) => {
log::warn!("failed to create new watcher for trash bin: {e:?}")
}
(_, Err(e)) => {
log::warn!("could not find any valid trash bins to watch: {e:?}")
}
}
std::future::pending().await
},
),
];
for (id, (pending_operation, _)) in self.pending_operations.iter() {