Watch trash folders for changes
This commit is contained in:
parent
503bce2c37
commit
f606a26482
1 changed files with 39 additions and 0 deletions
39
src/app.rs
39
src/app.rs
|
|
@ -1567,6 +1567,7 @@ impl Application for App {
|
||||||
struct ConfigSubscription;
|
struct ConfigSubscription;
|
||||||
struct ThemeSubscription;
|
struct ThemeSubscription;
|
||||||
struct WatcherSubscription;
|
struct WatcherSubscription;
|
||||||
|
struct TrashWatcherSubscription;
|
||||||
|
|
||||||
let mut subscriptions = vec![
|
let mut subscriptions = vec![
|
||||||
event::listen_with(|event, status| match event {
|
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() {
|
for (id, (pending_operation, _)) in self.pending_operations.iter() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue