Skip to content

Commit

Permalink
Add pipewire privacy driver
Browse files Browse the repository at this point in the history
  • Loading branch information
bim9262 committed Jan 13, 2024
1 parent 85b0411 commit 369c028
Show file tree
Hide file tree
Showing 6 changed files with 412 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Version information
run: rustc --version; cargo --version
- name: Get required packages
run: sudo apt-get update && sudo apt-get install libsensors-dev libssl-dev libpulse-dev libnotmuch-dev
run: sudo apt-get update && sudo apt-get install libsensors-dev libssl-dev libpulse-dev libnotmuch-dev libpipewire-0.3
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
]
steps:
- name: Get required packages
run: sudo apt-get update && sudo apt-get install libsensors-dev libssl-dev libpulse-dev libnotmuch-dev
run: sudo apt-get update && sudo apt-get install libsensors-dev libssl-dev libpulse-dev libnotmuch-dev libpipewire-0.3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
Expand Down
182 changes: 182 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [".", "xtask"]
[features]
default = ["pulseaudio"]
pulseaudio = ["libpulse-binding"]
pipewire = ["dep:pipewire"]
maildir = ["dep:maildir", "glob"]
icu_calendar = ["dep:icu_datetime", "dep:icu_calendar", "dep:icu_locid"]
debug_borders = [] # Make widgets' borders visible
Expand Down Expand Up @@ -53,6 +54,7 @@ nix = { version = "0.27", features = ["fs", "process"] }
nom = "7.1.2"
notmuch = { version = "0.8", optional = true }
once_cell = "1"
pipewire = { version = "0.7.2", default-features = false, optional = true }
regex = "1.5"
reqwest = { version = "0.11", features = ["json"] }
sensors = "0.2.2"
Expand Down
30 changes: 30 additions & 0 deletions src/blocks/privacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
//! `format` | Format string. | <code>"{ $icon_audio \|}{ $icon_audio_sink \|}{ $icon_video \|}{ $icon_webcam \|}{ $icon_unknown \|}"</code> |
//! `format_alt` | Format string. | <code>"{ $icon_audio $info_audio \|}{ $icon_audio_sink $info_audio_sink \|}{ $icon_video $info_video \|}{ $icon_webcam $info_webcam \|}{ $icon_unknown $info_unknown \|}"</code> |
//!
//! # pipewire Options (requires the pipewire feature to be enabled)
//!
//! Key | Values | Required | Default
//! ----|--------|----------|--------
//! `name` | `vl4` | Yes | None
//! `exclude_device` | A device to ignore, example: `["/dev/video5"]` | No | `[]`
//! `exclude_consumer` | Processes to ignore | No | `["pipewire", "wireplumber"]`
//!
//! # vl4 Options
//!
//! Key | Values | Required | Default
Expand Down Expand Up @@ -44,8 +52,15 @@
//! ```toml
//! [[block]]
//! block = "privacy"
//! merge_with_next = true
//! [block.driver]
//! name = "v4l"
//!
//! [[block]]
//! block = "privacy"
//! [block.driver]
//! name = "pipewire"
//! exclude_input = ["openrgb"]
//! ```
//!
//! # Icons Used
Expand All @@ -61,6 +76,8 @@ use super::prelude::*;

make_log_macro!(debug, "privacy");

#[cfg(feature = "pipewire")]
mod pipewire;
mod v4l;

#[derive(Deserialize, Debug)]
Expand All @@ -73,6 +90,15 @@ pub struct Config {
pub driver: PrivacyDriver,
}

#[cfg(feature = "pipewire")]
#[derive(Deserialize, Debug)]
#[serde(tag = "name", rename_all = "snake_case")]
pub enum PrivacyDriver {
Pipewire(pipewire::Config),
V4l(v4l::Config),
}

#[cfg(not(feature = "pipewire"))]
#[derive(Deserialize, Debug)]
#[serde(tag = "name", rename_all = "snake_case")]
pub enum PrivacyDriver {
Expand Down Expand Up @@ -107,6 +133,10 @@ pub async fn run(config: &Config, api: &CommonApi) -> Result<()> {
let mut format_alt = config.format_alt.with_default("{ $icon_audio $info_audio |}{ $icon_audio_sink $info_audio_sink |}{ $icon_video $info_video |}{ $icon_webcam $info_webcam |}{ $icon_unknown $info_unknown |}")?;

let mut device: Box<dyn PrivacyMonitor + Send + Sync> = match &config.driver {
#[cfg(feature = "pipewire")]
PrivacyDriver::Pipewire(driver_config) => {
Box::new(pipewire::Monitor::new(driver_config).await?)
}
PrivacyDriver::V4l(driver_config) => {
Box::new(v4l::Monitor::new(driver_config, api.error_interval).await?)
}
Expand Down
Loading

0 comments on commit 369c028

Please sign in to comment.