From f606a2648295aebcf6899278e86d19b9053b0552 Mon Sep 17 00:00:00 2001 From: Josh Megnauth Date: Wed, 20 Mar 2024 01:50:43 -0400 Subject: [PATCH] Watch trash folders for changes --- src/app.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/app.rs b/src/app.rs index e186ffa..4423d47 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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::(), + 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() {