Skip to content

Custom block with watch_files fires four times #2211

@jalvesaq

Description

@jalvesaq

Thanks for i3status-rust!

I have a custom block to notify me of new messages. It watches the file /var/mail/mylogin and runs a custom script. The custom script outputs the number of messages formatted for i3status-rust and plays a sound. The problem is: the sound plays four times.

To fix the issue, I made this change:

diff --git a/src/blocks/custom.rs b/src/blocks/custom.rs
index 234127091..861d8695b 100644
--- a/src/blocks/custom.rs
+++ b/src/blocks/custom.rs
@@ -173,13 +173,7 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
             for file in files {
                 let file = file.expand()?;
                 watches
-                    .add(
-                        &*file,
-                        WatchMask::MODIFY
-                            | WatchMask::CLOSE_WRITE
-                            | WatchMask::DELETE
-                            | WatchMask::MOVE,
-                    )
+                    .add(&*file, WatchMask::CLOSE_WRITE)
                     .error("Failed to add file watch")?;
             }
             Box::pin(

I didn't make a pull request because other people may want the four events or choose one different from CLOSE_WRITE.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions