Skip to content

Commit

Permalink
Remove debounced dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
bim9262 committed Feb 17, 2025
1 parent 2fac1a0 commit f99d34d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
17 changes: 0 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ calibright = { version = "0.1.9", features = ["watch"] }
chrono = { version = "0.4", default-features = false, features = ["clock", "unstable-locales"] }
chrono-tz = { version = "0.10", features = ["serde"] }
clap = { version = "4.0", default-features = false, features = ["std", "derive", "help", "usage"] }
debounced = "0.2.0"
dirs = "5.0"
env_logger = "0.11"
futures = { version = "0.3.31", default-features = false }
Expand Down
22 changes: 12 additions & 10 deletions src/blocks/privacy/v4l.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use debounced::{debounced, Debounced};
use inotify::{EventStream, Inotify, WatchDescriptor, WatchMask, Watches};
use tokio::fs::{read_dir, File};
use tokio::time::{interval, Interval};
Expand All @@ -20,27 +19,24 @@ pub(super) struct Monitor<'a> {
devices: HashMap<PathBuf, WatchDescriptor>,
interval: Interval,
watches: Watches,
updates: Debounced<EventStream<[u8; 1024]>>,
stream: EventStream<[u8; 1024]>,
}

impl<'a> Monitor<'a> {
pub(super) async fn new(config: &'a Config, duration: Duration) -> Result<Self> {
let notify = Inotify::init().error("Failed to start inotify")?;
let watches = notify.watches();

let updates = debounced(
notify
.into_event_stream([0; 1024])
.error("Failed to create event stream")?,
Duration::from_millis(100),
);
let stream = notify
.into_event_stream([0; 1024])
.error("Failed to create event stream")?;

let mut s = Self {
config,
devices: HashMap::new(),
interval: interval(duration),
watches,
updates,
stream,
};
s.update_devices().await?;

Expand Down Expand Up @@ -149,7 +145,13 @@ impl PrivacyMonitor for Monitor<'_> {
break;
}
},
_ = self.updates.next() => break,
_ = self.stream.next() => {
// avoid too frequent updates
let _ = tokio::time::timeout(Duration::from_millis(100), async {
loop { let _ = self.stream.next().await; }
}).await;
break;
}
}
}
Ok(())
Expand Down

0 comments on commit f99d34d

Please sign in to comment.