Convert trash watcher to use debounced events
This commit is contained in:
parent
2e5911e6cc
commit
2f5bbc5e7f
1 changed files with 23 additions and 16 deletions
39
src/app.rs
39
src/app.rs
|
|
@ -1694,23 +1694,29 @@ impl Application for App {
|
||||||
TypeId::of::<TrashWatcherSubscription>(),
|
TypeId::of::<TrashWatcherSubscription>(),
|
||||||
25,
|
25,
|
||||||
|mut output| async move {
|
|mut output| async move {
|
||||||
let watcher_res = notify::recommended_watcher(
|
let watcher_res = new_debouncer(
|
||||||
move |event_res: Result<notify::Event, _>| match event_res {
|
time::Duration::from_millis(250),
|
||||||
Ok(event)
|
Some(time::Duration::from_millis(250)),
|
||||||
if matches!(
|
move |event_res: notify_debouncer_full::DebounceEventResult| match event_res
|
||||||
event.kind,
|
{
|
||||||
notify::EventKind::Create(_) | notify::EventKind::Remove(_)
|
Ok(mut events) => {
|
||||||
) =>
|
events.retain(|event| {
|
||||||
{
|
matches!(
|
||||||
if let Err(e) = futures::executor::block_on(async {
|
event.kind,
|
||||||
output.send(Message::RescanTrash).await
|
notify::EventKind::Create(_) | notify::EventKind::Remove(_)
|
||||||
}) {
|
)
|
||||||
log::warn!("trash needs to be rescanned but sending message failed: {e:?}");
|
});
|
||||||
|
|
||||||
|
if !events.is_empty() {
|
||||||
|
if let Err(e) = futures::executor::block_on(async {
|
||||||
|
output.send(Message::RescanTrash).await
|
||||||
|
}) {
|
||||||
|
log::warn!("trash needs to be rescanned but sending message failed: {e:?}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(_) => {}
|
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::warn!("failed watching trash bin for changes: {e:?}")
|
log::warn!("failed to watch trash bin for changes: {e:?}")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -1725,8 +1731,9 @@ impl Application for App {
|
||||||
match (watcher_res, trash::os_limited::trash_folders()) {
|
match (watcher_res, trash::os_limited::trash_folders()) {
|
||||||
(Ok(mut watcher), Ok(trash_bins)) => {
|
(Ok(mut watcher), Ok(trash_bins)) => {
|
||||||
for path in trash_bins {
|
for path in trash_bins {
|
||||||
if let Err(e) =
|
if let Err(e) = watcher
|
||||||
watcher.watch(&path, notify::RecursiveMode::Recursive)
|
.watcher()
|
||||||
|
.watch(&path, notify::RecursiveMode::Recursive)
|
||||||
{
|
{
|
||||||
log::warn!(
|
log::warn!(
|
||||||
"failed to add trash bin `{}` to watcher: {e:?}",
|
"failed to add trash bin `{}` to watcher: {e:?}",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue